aboutsummaryrefslogtreecommitdiff
path: root/games/rstnode/rst-client/src/graphics
diff options
context:
space:
mode:
Diffstat (limited to 'games/rstnode/rst-client/src/graphics')
-rw-r--r--games/rstnode/rst-client/src/graphics/entities/mod.rs43
-rw-r--r--games/rstnode/rst-client/src/graphics/mod.rs16
-rw-r--r--games/rstnode/rst-client/src/graphics/ui/mod.rs1
3 files changed, 60 insertions, 0 deletions
diff --git a/games/rstnode/rst-client/src/graphics/entities/mod.rs b/games/rstnode/rst-client/src/graphics/entities/mod.rs
new file mode 100644
index 000000000000..168f40d2aeee
--- /dev/null
+++ b/games/rstnode/rst-client/src/graphics/entities/mod.rs
@@ -0,0 +1,43 @@
+//! Game entity rendering
+//!
+//! Generally the naming convention should be: `{type}Rndr`
+//! (`Renderer`, but shorter).
+
+use super::prelude::*;
+
+use rst_core::data::Node;
+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 loc: Coordinates,
+ pub inner: Arc<Node>,
+}
+
+impl EventHandler for NodeRndr {
+ fn update(&mut self, _: &mut Context) -> GameResult<()> {
+ Ok(())
+ }
+
+ fn draw(&mut self, ctx: &mut Context) -> GameResult<()> {
+ let circ = Mesh::new_circle(
+ ctx,
+ DrawMode::fill(),
+ Point2::from(&self.loc),
+ 35.0,
+ 0.1,
+ graphics::WHITE,
+ ).unwrap();
+
+ circ.draw(ctx, DrawParam::new()).unwrap();
+ Ok(())
+ }
+}
diff --git a/games/rstnode/rst-client/src/graphics/mod.rs b/games/rstnode/rst-client/src/graphics/mod.rs
new file mode 100644
index 000000000000..8118207d70af
--- /dev/null
+++ b/games/rstnode/rst-client/src/graphics/mod.rs
@@ -0,0 +1,16 @@
+//! Graphics module
+//!
+//! Each entity in the game has a graphics companion object in
+//! [`entities`](self::entities), which knows how to render a given
+//! object. Different game screens and UI elements can be found in
+//! [`ui`](self::ui).
+
+pub mod entities;
+pub mod ui;
+
+/// A utility module to include everything required to implement a
+/// graphics entity
+pub(self) mod prelude {
+ pub use ggez::{event::EventHandler, graphics::{self, Drawable, DrawParam, Mesh, DrawMode}, Context, GameResult};
+ pub use mint::Point2;
+}
diff --git a/games/rstnode/rst-client/src/graphics/ui/mod.rs b/games/rstnode/rst-client/src/graphics/ui/mod.rs
new file mode 100644
index 000000000000..3b63b5b9b0aa
--- /dev/null
+++ b/games/rstnode/rst-client/src/graphics/ui/mod.rs
@@ -0,0 +1 @@
+//! Different UI states