diff options
author | Katharina Fey <kookie@spacekookie.de> | 2021-02-07 16:44:44 +0100 |
---|---|---|
committer | Katharina Fey <kookie@spacekookie.de> | 2021-02-07 16:44:44 +0100 |
commit | 79c8b9ab441493e3b3a37a59263f66896c9c90b3 (patch) | |
tree | ca111686fa202369a5730ff8151480b04e391cbb /games/rstnode/rst-client/src/state.rs | |
parent | f5b36ff6b99256030201c878608a07d163b4c802 (diff) |
rstnode: basic asset loading and prototype sprite rendering
* restructure assets directory
* implement asset loading and dynamic conversion to sprites
* reload sprites with unique URIs to load at runtime
* provide an updated renderer API to give access to client state
* use new APIs to draw a single node frame on screen
* use colour APIs to dynamically change node frame colour
Diffstat (limited to 'games/rstnode/rst-client/src/state.rs')
-rw-r--r-- | games/rstnode/rst-client/src/state.rs | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/games/rstnode/rst-client/src/state.rs b/games/rstnode/rst-client/src/state.rs index c55dc2faa6d6..6b7312f13d7f 100644 --- a/games/rstnode/rst-client/src/state.rs +++ b/games/rstnode/rst-client/src/state.rs @@ -1,7 +1,11 @@ //! Game client state handling use crate::{ - graphics::entities::{Coordinates, NodeRndr}, + assets::Assets, + graphics::{ + entities::{Coordinates, NodeRndr}, + Renderer, + }, GameSettings, }; use ggez::{event::EventHandler, graphics, Context, GameResult}; @@ -9,12 +13,18 @@ use rst_core::data::{Node, Owner, Upgrade}; use std::sync::Arc; pub struct ClientState { + assets: Assets, + settings: GameSettings, + + // Game state node: NodeRndr, } impl ClientState { - pub fn new(_settings: &GameSettings) -> Self { + pub fn new(settings: GameSettings, assets: Assets) -> Self { Self { + assets, + settings, node: NodeRndr { loc: Coordinates(250.0, 250.0), inner: Arc::new(Node { @@ -30,6 +40,10 @@ impl ClientState { }, } } + + pub fn assets(&self) -> &Assets { + &self.assets + } } impl EventHandler for ClientState { @@ -41,7 +55,7 @@ impl EventHandler for ClientState { graphics::clear(ctx, graphics::Color::from_rgb(15, 15, 15)); // Render the node - self.node.draw(ctx).unwrap(); + self.node.draw(&self, ctx).unwrap(); graphics::present(ctx) } |