My personal project and infrastructure archive
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
nomicon/games/rstnode/rst-client/src/graphics/entities/mod.rs

67 lines
1.9 KiB

//! Game entity rendering
//!
//! Generally the naming convention should be: `{type}Rndr`
//! (`Renderer`, but shorter).
use super::prelude::*;
use crate::color;
use rst_core::data::{Color, Link, Node, Owner};
use std::sync::Arc;
/// A set of universal X/Y coordinates
pub struct Coordinates(pub f32, pub f32);
impl<'a> From<&'a Coordinates> for Point2<f32> {
fn from(c: &'a Coordinates) -> Self {
Point2 { x: c.0, y: c.1 }
}
}
pub struct NodeRndr {
pub inner: Arc<Node>,
}
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.inner.pos.x - frame.width() as f32;
let y = self.inner.pos.y - 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))?;
Ok(())
}
}
pub struct LinkRndr {
pub inner: Arc<Link>,
}
impl Renderer for LinkRndr {
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))?;
Ok(())
}
}