aboutsummaryrefslogtreecommitdiff
path: root/server/client-lib/src/lib.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-08-13 12:48:31 +0200
committermetamuffin <metamuffin@disroot.org>2024-08-13 16:03:38 +0200
commit16ff78180669411326d42ea32d4a9260c018236c (patch)
treed7c6a7ab498bb1b4f9a3b3db99d54e8781216e05 /server/client-lib/src/lib.rs
parent11ff74f034aeec58c06dbe15a3f1ee650ef18c9f (diff)
downloadhurrycurry-16ff78180669411326d42ea32d4a9260c018236c.tar
hurrycurry-16ff78180669411326d42ea32d4a9260c018236c.tar.bz2
hurrycurry-16ff78180669411326d42ea32d4a9260c018236c.tar.zst
refactor server to use client-lib data model (breaks customers)
Diffstat (limited to 'server/client-lib/src/lib.rs')
-rw-r--r--server/client-lib/src/lib.rs35
1 files changed, 26 insertions, 9 deletions
diff --git a/server/client-lib/src/lib.rs b/server/client-lib/src/lib.rs
index d949ac6e..b04f46f7 100644
--- a/server/client-lib/src/lib.rs
+++ b/server/client-lib/src/lib.rs
@@ -20,8 +20,8 @@ pub mod network;
pub mod spatial_index;
use hurrycurry_protocol::{
- glam::IVec2, movement::MovementBase, ClientGamedata, ItemIndex, ItemLocation, Message, PacketC,
- PlayerID, Score, TileIndex,
+ glam::IVec2, movement::MovementBase, Gamedata, ItemIndex, ItemLocation, Message, PacketC,
+ PlayerID, RecipeIndex, Score, TileIndex,
};
use spatial_index::SpatialIndex;
use std::{
@@ -31,9 +31,17 @@ use std::{
};
#[derive(Debug, PartialEq)]
+pub struct Involvement {
+ pub progress: f32,
+ pub recipe: RecipeIndex,
+ pub working: usize,
+ pub warn: bool,
+}
+
+#[derive(Debug, PartialEq)]
pub struct Item {
pub kind: ItemIndex,
- pub progress: Option<(f32, bool)>,
+ pub active: Option<Involvement>,
}
pub struct Tile {
@@ -52,7 +60,7 @@ pub struct Player {
}
pub struct Game {
- pub data: Arc<ClientGamedata>,
+ pub data: Arc<Gamedata>,
pub tiles: HashMap<IVec2, Tile>,
pub walkable: HashSet<IVec2>,
pub players: HashMap<PlayerID, Player>,
@@ -125,17 +133,20 @@ impl Game {
*self.get_item(to) = self.get_item(from).take();
}
PacketC::SetItem { location, item } => {
- *self.get_item(location) = item.map(|kind| Item {
- kind,
- progress: None,
- });
+ *self.get_item(location) = item.map(|kind| Item { kind, active: None });
}
PacketC::SetProgress {
item,
progress,
warn,
} => {
- self.get_item(item).as_mut().unwrap().progress = progress.map(|s| (s, warn));
+ self.get_item(item).as_mut().unwrap().active =
+ progress.map(|progress| Involvement {
+ working: 1,
+ warn,
+ progress,
+ recipe: RecipeIndex(0),
+ });
}
PacketC::UpdateMap {
tile,
@@ -204,3 +215,9 @@ impl Game {
}
}
}
+
+impl From<TileIndex> for Tile {
+ fn from(kind: TileIndex) -> Self {
+ Self { kind, item: None }
+ }
+}