From 0472f0fb50ffb945c83d662cd21b994562bee12d Mon Sep 17 00:00:00 2001 From: Katharina Fey Date: Sun, 7 Feb 2021 21:12:22 +0100 Subject: rstnode: some client cleanups and better colour handling --- games/rstnode/rst-client/src/assets.rs | 6 ----- games/rstnode/rst-client/src/color.rs | 7 +++++ .../rst-client/src/graphics/entities/mod.rs | 31 ++++++++++------------ games/rstnode/rst-client/src/main.rs | 1 + 4 files changed, 22 insertions(+), 23 deletions(-) create mode 100644 games/rstnode/rst-client/src/color.rs diff --git a/games/rstnode/rst-client/src/assets.rs b/games/rstnode/rst-client/src/assets.rs index d1ccdaf875ed..76556213fc70 100644 --- a/games/rstnode/rst-client/src/assets.rs +++ b/games/rstnode/rst-client/src/assets.rs @@ -4,7 +4,6 @@ use ggez::graphics::Image; use librsvg::{CairoRenderer, Loader}; use std::{ collections::BTreeMap, - error::Error, ffi::OsStr, fs::{read_dir, File}, io::BufWriter, @@ -15,11 +14,6 @@ use tempfile::tempdir; pub type Result = std::result::Result; -/// Construct a `node` prefixed URI -pub fn node(tt: &str) -> URI { - ("node/".to_owned() + tt).into() -} - #[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] pub struct URI(String, String); diff --git a/games/rstnode/rst-client/src/color.rs b/games/rstnode/rst-client/src/color.rs new file mode 100644 index 000000000000..4fbd7519dcd0 --- /dev/null +++ b/games/rstnode/rst-client/src/color.rs @@ -0,0 +1,7 @@ +use ggez::graphics::Color as EzColor; +use rst_core::data::Color; + + +pub fn to(Color(r, g, b): Color) -> EzColor { + EzColor::from_rgb(r, g, b) +} diff --git a/games/rstnode/rst-client/src/graphics/entities/mod.rs b/games/rstnode/rst-client/src/graphics/entities/mod.rs index 17f26a8e5a70..a3289f6f412d 100644 --- a/games/rstnode/rst-client/src/graphics/entities/mod.rs +++ b/games/rstnode/rst-client/src/graphics/entities/mod.rs @@ -3,9 +3,10 @@ //! Generally the naming convention should be: `{type}Rndr` //! (`Renderer`, but shorter). +use crate::color; use super::prelude::*; -use rst_core::data::Node; +use rst_core::data::{Owner, Node, Color}; use std::sync::Arc; /// A set of universal X/Y coordinates @@ -29,23 +30,19 @@ impl Renderer for NodeRndr { fn draw(&self, s: &ClientState, ctx: &mut Context) -> GameResult<()> { let frame = s.assets().find("frame/frame_s").unwrap(); + let icon = s.assets().find("relay/relay1").unwrap(); + + let x = self.loc.0 - frame.width() as f32; + let y = self.loc.1 - frame.height() as f32; + + let color = match self.inner.owner { + Owner::Player(ref p) => color::to(p.color), + Owner::Neutral => color::to(Color::white()), + }; + + frame.draw(ctx, DrawParam::new().dest([x, y]).color(color))?; + icon.draw(ctx, DrawParam::new().dest([x, y]).color(color))?; - frame.draw( - ctx, - DrawParam::new().dest([256.0, 256.0]).color(graphics::RED), - )?; - - let circ = Mesh::new_circle( - ctx, - DrawMode::fill(), - Point2::from(&self.loc), - 64.0, - 0.1, - graphics::WHITE, - ) - .unwrap(); - - circ.draw(ctx, DrawParam::new()).unwrap(); Ok(()) } } diff --git a/games/rstnode/rst-client/src/main.rs b/games/rstnode/rst-client/src/main.rs index b86ee341075e..240f302c55df 100644 --- a/games/rstnode/rst-client/src/main.rs +++ b/games/rstnode/rst-client/src/main.rs @@ -5,6 +5,7 @@ extern crate tracing; mod assets; mod cli; +mod color; mod constants; mod ctx; mod error; -- cgit v1.2.3