aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKatharina Fey <kookie@spacekookie.de>2021-02-07 21:12:22 +0100
committerKatharina Fey <kookie@spacekookie.de>2021-02-07 21:12:22 +0100
commit0472f0fb50ffb945c83d662cd21b994562bee12d (patch)
tree58a5dfb1cc0d908c99ba50f5fdf8f7f0ebebd8b7
parent2d026c19ab9af91e316448bb74bfa27e0e295077 (diff)
rstnode: some client cleanups and better colour handling
-rw-r--r--games/rstnode/rst-client/src/assets.rs6
-rw-r--r--games/rstnode/rst-client/src/color.rs7
-rw-r--r--games/rstnode/rst-client/src/graphics/entities/mod.rs31
-rw-r--r--games/rstnode/rst-client/src/main.rs1
4 files changed, 22 insertions, 23 deletions
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<T> = std::result::Result<T, LoadError>;
-/// 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;