From 16ff78180669411326d42ea32d4a9260c018236c Mon Sep 17 00:00:00 2001 From: metamuffin Date: Tue, 13 Aug 2024 12:48:31 +0200 Subject: refactor server to use client-lib data model (breaks customers) --- server/client-lib/src/lib.rs | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'server/client-lib') 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::{ @@ -30,10 +30,18 @@ use std::{ time::Instant, }; +#[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, } pub struct Tile { @@ -52,7 +60,7 @@ pub struct Player { } pub struct Game { - pub data: Arc, + pub data: Arc, pub tiles: HashMap, pub walkable: HashSet, pub players: HashMap, @@ -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 for Tile { + fn from(kind: TileIndex) -> Self { + Self { kind, item: None } + } +} -- cgit v1.2.3-70-g09d2