rstnode: some client cleanups and better colour handling

wip/yesman
Katharina Fey 3 years ago
parent 2d026c19ab
commit 0472f0fb50
Signed by: kookie
GPG Key ID: 90734A9E619C8A6C
  1. 6
      games/rstnode/rst-client/src/assets.rs
  2. 7
      games/rstnode/rst-client/src/color.rs
  3. 31
      games/rstnode/rst-client/src/graphics/entities/mod.rs
  4. 1
      games/rstnode/rst-client/src/main.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);

@ -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)
}

@ -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(())
}
}

@ -5,6 +5,7 @@ extern crate tracing;
mod assets;
mod cli;
mod color;
mod constants;
mod ctx;
mod error;

Loading…
Cancel
Save