aboutsummaryrefslogtreecommitdiff
path: root/games/rstnode/rst-client
diff options
context:
space:
mode:
Diffstat (limited to 'games/rstnode/rst-client')
-rw-r--r--games/rstnode/rst-client/Cargo.toml10
-rw-r--r--games/rstnode/rst-client/src/graphics/entities/mod.rs35
-rw-r--r--games/rstnode/rst-client/src/graphics/mod.rs2
-rw-r--r--games/rstnode/rst-client/src/input.rs2
-rw-r--r--games/rstnode/rst-client/src/main.rs6
-rw-r--r--games/rstnode/rst-client/src/net.rs1
-rw-r--r--games/rstnode/rst-client/src/settings.rs1
-rw-r--r--games/rstnode/rst-client/src/state/_match.rs0
-rw-r--r--games/rstnode/rst-client/src/state/if_impl.rs70
-rw-r--r--games/rstnode/rst-client/src/state/map.rs10
-rw-r--r--games/rstnode/rst-client/src/state/mod.rs (renamed from games/rstnode/rst-client/src/state.rs)51
11 files changed, 166 insertions, 22 deletions
diff --git a/games/rstnode/rst-client/Cargo.toml b/games/rstnode/rst-client/Cargo.toml
index 7b5155f8108c..281b44376902 100644
--- a/games/rstnode/rst-client/Cargo.toml
+++ b/games/rstnode/rst-client/Cargo.toml
@@ -8,14 +8,18 @@ authors = ["Bread Machine", "Katharina Fey <kookie@spacekookie.de>"]
[dependencies]
rst-core = { path = "../rst-core" }
+# async-quic = { path = "../async-quic" }
cairo-rs = { version="0.8.0", features=["v1_16", "png", "svg"] }
librsvg = { git = "https://gitlab.gnome.org/GNOME/librsvg.git", rev = "d34f570f" }
-ggez = "0.6.0-rc0"
+ggez = "0.6.0-rc1"
mint = "0.5" # Required because ggez is trash
svg = "0.9"
+async-trait = "0.1"
+async-std = { version = "1.0", features = ["unstable", "attributes"] }
+chrono = { version = "0.4", features = ["serde"] }
clap = "2.0"
+tempfile = "*"
tracing = "0.1"
-tracing-subscriber = "0.2"
-tempfile = "*" \ No newline at end of file
+tracing-subscriber = "0.2" \ No newline at end of file
diff --git a/games/rstnode/rst-client/src/graphics/entities/mod.rs b/games/rstnode/rst-client/src/graphics/entities/mod.rs
index a3289f6f412d..db675f816fbf 100644
--- a/games/rstnode/rst-client/src/graphics/entities/mod.rs
+++ b/games/rstnode/rst-client/src/graphics/entities/mod.rs
@@ -3,10 +3,10 @@
//! Generally the naming convention should be: `{type}Rndr`
//! (`Renderer`, but shorter).
-use crate::color;
use super::prelude::*;
+use crate::color;
-use rst_core::data::{Owner, Node, Color};
+use rst_core::data::{Color, Link, Node, Owner};
use std::sync::Arc;
/// A set of universal X/Y coordinates
@@ -24,10 +24,6 @@ pub struct NodeRndr {
}
impl Renderer for NodeRndr {
- fn update(&mut self, _: &mut ClientState, _: &mut Context) -> GameResult<()> {
- Ok(())
- }
-
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();
@@ -39,10 +35,35 @@ impl Renderer for NodeRndr {
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 loc: Coordinates,
+ 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(())
+ }
+}
diff --git a/games/rstnode/rst-client/src/graphics/mod.rs b/games/rstnode/rst-client/src/graphics/mod.rs
index a7ba676ecc6b..757d44d312d4 100644
--- a/games/rstnode/rst-client/src/graphics/mod.rs
+++ b/games/rstnode/rst-client/src/graphics/mod.rs
@@ -31,6 +31,6 @@ pub(self) mod prelude {
/// A rendering trait which is given graphics context, and game state
pub trait Renderer {
- fn update(&mut self, _state: &mut ClientState, _ctx: &mut Context) -> GameResult<()>;
+ // fn update(&mut self, _state: &mut ClientState, _ctx: &mut Context) -> GameResult<()>:
fn draw(&self, _state: &ClientState, _ctx: &mut Context) -> GameResult<()>;
}
diff --git a/games/rstnode/rst-client/src/input.rs b/games/rstnode/rst-client/src/input.rs
index e9d2516a94c3..83ae17286d61 100644
--- a/games/rstnode/rst-client/src/input.rs
+++ b/games/rstnode/rst-client/src/input.rs
@@ -60,7 +60,7 @@ impl EventHandler for InputHandle {
}
fn mouse_wheel_event(&mut self, _ctx: &mut Context, _: f32, y: f32) {
- self.scroll_offset += y * 0.1;
+ self.scroll_offset -= y * 0.25;
}
fn draw(&mut self, _: &mut Context) -> GameResult<()> {
diff --git a/games/rstnode/rst-client/src/main.rs b/games/rstnode/rst-client/src/main.rs
index a6ba4a59cdc1..4159a37d1d4a 100644
--- a/games/rstnode/rst-client/src/main.rs
+++ b/games/rstnode/rst-client/src/main.rs
@@ -1,5 +1,8 @@
//! RST Node game client
+// Remove the warning spam
+#![allow(warnings)]
+
#[macro_use]
extern crate tracing;
@@ -21,7 +24,8 @@ mod window;
pub(crate) use settings::{GameSettings, GraphicsSettings, WindowSettings};
pub(crate) use state::*;
-fn main() {
+#[async_std::main]
+async fn main() {
// Initialise logging mechanism
log::initialise();
diff --git a/games/rstnode/rst-client/src/net.rs b/games/rstnode/rst-client/src/net.rs
new file mode 100644
index 000000000000..ff3c47774ac6
--- /dev/null
+++ b/games/rstnode/rst-client/src/net.rs
@@ -0,0 +1 @@
+//! Client networking endpoint logic
diff --git a/games/rstnode/rst-client/src/settings.rs b/games/rstnode/rst-client/src/settings.rs
index cb44eacca3a3..7fd0ba6881c1 100644
--- a/games/rstnode/rst-client/src/settings.rs
+++ b/games/rstnode/rst-client/src/settings.rs
@@ -43,7 +43,6 @@ pub struct Samples(pub u8);
impl<'s> From<&'s Samples> for NumSamples {
fn from(s: &'s Samples) -> Self {
match s.0 {
- 0 => Self::Zero,
1 => Self::One,
2 => Self::Two,
4 => Self::Four,
diff --git a/games/rstnode/rst-client/src/state/_match.rs b/games/rstnode/rst-client/src/state/_match.rs
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/games/rstnode/rst-client/src/state/_match.rs
diff --git a/games/rstnode/rst-client/src/state/if_impl.rs b/games/rstnode/rst-client/src/state/if_impl.rs
new file mode 100644
index 000000000000..38bac369d3cc
--- /dev/null
+++ b/games/rstnode/rst-client/src/state/if_impl.rs
@@ -0,0 +1,70 @@
+#![allow(unused)]
+
+use super::ClientState;
+use async_trait::async_trait;
+use chrono::{DateTime, Utc};
+use rst_core::{
+ wire::{
+ game::Action, AuthErr, Lobby, LobbyErr, LobbyId, LobbyUpdate, MatchErr, MatchId, RegErr,
+ UpdateState, User, UserId,
+ },
+ GameIf, Match,
+};
+use std::sync::Arc;
+
+#[async_trait]
+impl GameIf for ClientState {
+ async fn register(self: Arc<Self>, name: String, pw: String) -> Result<UserId, RegErr> {
+ todo!()
+ }
+
+ async fn login(self: Arc<Self>, name: String, pw: String) -> Result<User, AuthErr> {
+ todo!()
+ }
+
+ async fn logout(self: Arc<Self>, user: User) -> Result<(), AuthErr> {
+ todo!()
+ }
+
+ async fn anonymous(self: Arc<Self>, name: String) -> Result<User, AuthErr> {
+ todo!()
+ }
+
+ async fn join(self: Arc<Self>, user: User, lobby: LobbyId) -> Result<Lobby, LobbyErr> {
+ todo!()
+ }
+
+ async fn leave(self: Arc<Self>, user: User, lobby: LobbyId) -> Result<(), LobbyErr> {
+ todo!()
+ }
+
+ async fn ready(
+ self: Arc<Self>,
+ user: User,
+ lobby: LobbyId,
+ ready: bool,
+ ) -> Result<LobbyUpdate, LobbyErr> {
+ todo!()
+ }
+
+ async fn start_req(
+ self: Arc<Self>,
+ user: UserId,
+ lobby: LobbyId,
+ ) -> Result<DateTime<Utc>, LobbyErr> {
+ todo!()
+ }
+
+ async fn perform_action(
+ self: Arc<Self>,
+ user: User,
+ mtch: MatchId,
+ act: Action,
+ ) -> UpdateState {
+ todo!()
+ }
+
+ async fn leave_match(self: Arc<Self>, user: User, mtch: MatchId) -> Result<(), MatchErr> {
+ todo!()
+ }
+}
diff --git a/games/rstnode/rst-client/src/state/map.rs b/games/rstnode/rst-client/src/state/map.rs
new file mode 100644
index 000000000000..1c4666da6b4f
--- /dev/null
+++ b/games/rstnode/rst-client/src/state/map.rs
@@ -0,0 +1,10 @@
+use rst_core::map::{Map, MapNode};
+
+/// Client map state wrapper
+///
+/// The map state is calculated by the server and updates are streamed
+/// to all clients in a [Match](rst_core::Match).
+pub struct MapState {
+ inner: Map,
+}
+
diff --git a/games/rstnode/rst-client/src/state.rs b/games/rstnode/rst-client/src/state/mod.rs
index 8099cf9add96..45e69eee10bb 100644
--- a/games/rstnode/rst-client/src/state.rs
+++ b/games/rstnode/rst-client/src/state/mod.rs
@@ -1,5 +1,10 @@
//! Game client state handling
+mod map;
+pub use map::*;
+
+mod if_impl;
+
use crate::{
assets::Assets,
graphics::{
@@ -11,7 +16,10 @@ use crate::{
GameSettings,
};
use ggez::{event::EventHandler, graphics, Context, GameResult};
-use rst_core::data::{Color, Level, Node, Owner, Player, Upgrade};
+use rst_core::{
+ data::{Color, Level, Link, Node, Owner, Player, Upgrade},
+ io::Io,
+};
use std::sync::Arc;
pub struct ClientState {
@@ -21,17 +29,28 @@ pub struct ClientState {
vp: Viewport,
// Game state
- node: NodeRndr,
+ node1: NodeRndr,
+ node2: NodeRndr,
+ link: Arc<Link>,
}
impl ClientState {
pub fn new(settings: GameSettings, assets: Assets) -> Self {
+ let link = Arc::new(Link {
+ id: 0,
+ a: 0,
+ b: 1,
+ length: 12,
+ pp: vec![],
+ io: Io::default(),
+ });
+
Self {
assets,
settings,
vp: Viewport::new(),
input: InputHandle::new(),
- node: NodeRndr {
+ node1: NodeRndr {
loc: Coordinates(512.0, 512.0),
inner: Arc::new(Node {
id: 0,
@@ -44,11 +63,27 @@ impl ClientState {
money: 1000.into(),
}),
type_: Upgrade::Relay(Level::One),
- links: 0,
- link_states: vec![],
- buffer: vec![],
+ links: 1,
+ router: None,
+ link_states: vec![Arc::clone(&link)],
+ buffer: vec![].into(),
+ }),
+ },
+ node2: NodeRndr {
+ loc: Coordinates(128.0, 128.0),
+ inner: Arc::new(Node {
+ id: 0,
+ health: 100.into(),
+ max_health: 100.into(),
+ owner: Owner::Neutral,
+ type_: Upgrade::Relay(Level::One),
+ links: 1,
+ router: None,
+ link_states: vec![Arc::clone(&link)],
+ buffer: vec![].into(),
}),
},
+ link,
}
}
@@ -80,14 +115,14 @@ impl EventHandler for ClientState {
self.input.mouse_wheel_event(ctx, x, y);
let zoom = self.input.scroll_offset;
self.viewport().zoom(zoom);
-
}
fn draw(&mut self, ctx: &mut Context) -> GameResult<()> {
graphics::clear(ctx, graphics::Color::from_rgb(15, 15, 15));
// Render the node
- self.node.draw(&self, ctx).unwrap();
+ self.node1.draw(&self, ctx).unwrap();
+ self.node2.draw(&self, ctx).unwrap();
graphics::present(ctx)
}