~saiko/game

deec8e173376e274ff01db617758cc484795f3ee — 2xsaiko 6 months ago c08ba37 master
extract color parsing code for UI color commands to function
3 files changed, 19 insertions(+), 51 deletions(-)

M Cargo.lock
M Cargo.toml
M src/main.rs
M Cargo.lock => Cargo.lock +3 -2
@@ 535,8 535,9 @@ dependencies = [

[[package]]
name = "glium"
version = "0.26.0-alpha5"
source = "git+https://github.com/2xsaiko/glium#4cfa3b69c6935e5c8cecc299ff9b9c00362fc69c"
version = "0.26.0-alpha6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "649d3b056f605d6b202d737685115ecc614d293d834b940277d18bb1b442f3b2"
dependencies = [
 "backtrace",
 "fnv",

M Cargo.toml => Cargo.toml +1 -1
@@ 8,7 8,7 @@ edition = "2018"
lto = true

[dependencies]
glium = { git = "https://github.com/2xsaiko/glium" }
glium = "0.26.0-alpha6"
ncollide3d = "0.21"
nalgebra = "0.19"
bit-set = "0.5.1"

M src/main.rs => src/main.rs +15 -48
@@ 147,6 147,13 @@ fn start_game(env: Environment) -> ! {
  let ui_settings = Rc::new(Cell::new(UiSettings::default()));

  let mut ce = {
    fn parse_color(args: &[&str]) -> Color {
      let r = args.get(0).unwrap_or(&"").parse().unwrap_or(0);
      let g = args.get(1).unwrap_or(&"").parse().unwrap_or(0);
      let b = args.get(2).unwrap_or(&"").parse().unwrap_or(0);
      Color::from_rgb8(r, g, b)
    }

    let env = env.clone();
    let running = running.clone();
    EngineBuilder::new(LogPipe::info())


@@ 161,75 168,35 @@ fn start_game(env: Environment) -> ! {
      .with_help_text("debug_info", "whether to show debug info like fps and player position")
      .with_command("ui_col_border", {
        let ui_settings = ui_settings.clone();
        box command(move |args, _, _| {
          let r = args.get(0).unwrap_or(&"").parse().unwrap_or(0);
          let g = args.get(1).unwrap_or(&"").parse().unwrap_or(0);
          let b = args.get(2).unwrap_or(&"").parse().unwrap_or(0);
          ui_settings.update(|s| apply(s, |s| s.border_color = Color::from_rgb8(r, g, b)));
        })
        box command(move |args, _, _| { ui_settings.update(|s| apply(s, |s| s.border_color = parse_color(args))); })
      })
      .with_command("ui_col_normal", {
        let ui_settings = ui_settings.clone();
        box command(move |args, _, _| {
          let r = args.get(0).unwrap_or(&"").parse().unwrap_or(0);
          let g = args.get(1).unwrap_or(&"").parse().unwrap_or(0);
          let b = args.get(2).unwrap_or(&"").parse().unwrap_or(0);
          ui_settings.update(|s| apply(s, |s| s.normal_color = Color::from_rgb8(r, g, b)));
        })
        box command(move |args, _, _| { ui_settings.update(|s| apply(s, |s| s.normal_color = parse_color(args))); })
      })
      .with_command("ui_col_hilight", {
        let ui_settings = ui_settings.clone();
        box command(move |args, _, _| {
          let r = args.get(0).unwrap_or(&"").parse().unwrap_or(0);
          let g = args.get(1).unwrap_or(&"").parse().unwrap_or(0);
          let b = args.get(2).unwrap_or(&"").parse().unwrap_or(0);
          ui_settings.update(|s| apply(s, |s| s.highlighted_color = Color::from_rgb8(r, g, b)));
        })
        box command(move |args, _, _| { ui_settings.update(|s| apply(s, |s| s.highlighted_color = parse_color(args))); })
      })
      .with_command("ui_col_act", {
        let ui_settings = ui_settings.clone();
        box command(move |args, _, _| {
          let r = args.get(0).unwrap_or(&"").parse().unwrap_or(0);
          let g = args.get(1).unwrap_or(&"").parse().unwrap_or(0);
          let b = args.get(2).unwrap_or(&"").parse().unwrap_or(0);
          ui_settings.update(|s| apply(s, |s| s.active_color = Color::from_rgb8(r, g, b)));
        })
        box command(move |args, _, _| { ui_settings.update(|s| apply(s, |s| s.active_color = parse_color(args))); })
      })
      .with_command("ui_col_disabled", {
        let ui_settings = ui_settings.clone();
        box command(move |args, _, _| {
          let r = args.get(0).unwrap_or(&"").parse().unwrap_or(0);
          let g = args.get(1).unwrap_or(&"").parse().unwrap_or(0);
          let b = args.get(2).unwrap_or(&"").parse().unwrap_or(0);
          ui_settings.update(|s| apply(s, |s| s.disabled_color = Color::from_rgb8(r, g, b)));
        })
        box command(move |args, _, _| { ui_settings.update(|s| apply(s, |s| s.disabled_color = parse_color(args))); })
      })
      .with_command("ui_col_query", {
        let ui_settings = ui_settings.clone();
        box command(move |args, _, _| {
          let r = args.get(0).unwrap_or(&"").parse().unwrap_or(0);
          let g = args.get(1).unwrap_or(&"").parse().unwrap_or(0);
          let b = args.get(2).unwrap_or(&"").parse().unwrap_or(0);
          ui_settings.update(|s| apply(s, |s| s.query_text_color = Color::from_rgb8(r, g, b)));
        })
        box command(move |args, _, _| { ui_settings.update(|s| apply(s, |s| s.query_text_color = parse_color(args))); })
      })
      .with_command("ui_col_text", {
        let ui_settings = ui_settings.clone();
        box command(move |args, _, _| {
          let r = args.get(0).unwrap_or(&"").parse().unwrap_or(0);
          let g = args.get(1).unwrap_or(&"").parse().unwrap_or(0);
          let b = args.get(2).unwrap_or(&"").parse().unwrap_or(0);
          ui_settings.update(|s| apply(s, |s| s.text_color = Color::from_rgb8(r, g, b)));
        })
        box command(move |args, _, _| { ui_settings.update(|s| apply(s, |s| s.text_color = parse_color(args))); })
      })
      .with_command("ui_col_tsel", {
        let ui_settings = ui_settings.clone();
        box command(move |args, _, _| {
          let r = args.get(0).unwrap_or(&"").parse().unwrap_or(0);
          let g = args.get(1).unwrap_or(&"").parse().unwrap_or(0);
          let b = args.get(2).unwrap_or(&"").parse().unwrap_or(0);
          ui_settings.update(|s| apply(s, |s| s.text_selected_background_color = Color::from_rgb8(r, g, b)));
        })
        box command(move |args, _, _| { ui_settings.update(|s| apply(s, |s| s.text_selected_background_color = parse_color(args))); })
      })
      .with_command("exec", box expand_command(move |args, _, out| {
        let file = format!("cfg/{}.cfg", *args.get(0)?);