diff options
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/data.rs | 23 | ||||
-rw-r--r-- | server/src/game.rs | 6 |
2 files changed, 20 insertions, 9 deletions
diff --git a/server/src/data.rs b/server/src/data.rs index 2d190f3b..7f5ed9a6 100644 --- a/server/src/data.rs +++ b/server/src/data.rs @@ -98,20 +98,21 @@ pub struct Demand { pub points: i64, } -#[derive(Debug, Clone, Serialize, Deserialize, Default)] +#[derive(Debug, Clone, Default)] #[rustfmt::skip] pub struct Gamedata { pub spec: String, + pub map_name: String, pub item_names: Vec<String>, pub tile_names: Vec<String>, pub tile_collide: Vec<bool>, pub tile_interact: Vec<bool>, pub map: HashMap<String, MapMetadata>, - #[serde(skip)] pub recipes: Vec<Recipe>, - #[serde(skip)] pub initial_map: HashMap<IVec2, (TileIndex, Option<ItemIndex>)>, - #[serde(skip)] pub chef_spawn: Vec2, - #[serde(skip)] pub customer_spawn: Vec2, - #[serde(skip)] pub entities: Vec<Entity>, + pub recipes: Vec<Recipe>, + pub initial_map: HashMap<IVec2, (TileIndex, Option<ItemIndex>)>, + pub chef_spawn: Vec2, + pub customer_spawn: Vec2, + pub entities: Vec<Entity>, } #[derive(Debug, Deserialize, Default)] @@ -164,14 +165,19 @@ impl DataIndex { let map_in = serde_yml::from_str(&self.read_map(map).await?)?; let recipes_in = serde_yml::from_str(&self.read_recipes(recipes).await?)?; - let mut gd = Gamedata::build(spec, map_in, recipes_in)?; + let mut gd = Gamedata::build(spec.clone(), map.to_string(), map_in, recipes_in)?; gd.map = self.maps.clone(); Ok(gd) } } impl Gamedata { - pub fn build(spec: String, map_in: InitialMap, recipes_in: Vec<RecipeDecl>) -> Result<Self> { + pub fn build( + spec: String, + map_name: String, + map_in: InitialMap, + recipes_in: Vec<RecipeDecl>, + ) -> Result<Self> { let reg = ItemTileRegistry::default(); let mut recipes = Vec::new(); let mut entities = Vec::new(); @@ -313,6 +319,7 @@ impl Gamedata { Ok(Gamedata { spec, tile_collide, + map_name, tile_interact, recipes, map: HashMap::new(), diff --git a/server/src/game.rs b/server/src/game.rs index f5670277..bb6d5182 100644 --- a/server/src/game.rs +++ b/server/src/game.rs @@ -135,6 +135,7 @@ impl Game { self.unload(); + self.lobby = gamedata.map_name == "lobby"; self.data = gamedata.into(); self.points = 0; self.end = timer.map(|dur| Instant::now() + dur); @@ -198,6 +199,7 @@ impl Game { tile_names: self.data.tile_names.clone(), tile_collide: self.data.tile_collide.clone(), tile_interact: self.data.tile_interact.clone(), + current_map: self.data.map_name.clone(), map_names: self .data .map @@ -584,7 +586,9 @@ impl Game { } pub fn count_chefs(&self) -> usize { - self.players.values().map(|p| if p.character >= 0 { 1 } else { 0 }) + self.players + .values() + .map(|p| if p.character >= 0 { 1 } else { 0 }) .sum() } } |