From ae29ca99dde89f8b975ce7b3a716411ab2028e50 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Thu, 11 Jul 2024 13:48:42 +0200 Subject: send map metadata --- server/src/data.rs | 12 ++++++------ server/src/game.rs | 6 +++--- server/src/state.rs | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'server/src') diff --git a/server/src/data.rs b/server/src/data.rs index 5f35a360..c5ed25ad 100644 --- a/server/src/data.rs +++ b/server/src/data.rs @@ -23,7 +23,7 @@ use crate::{ use anyhow::{anyhow, bail, Result}; use hurrycurry_protocol::{ glam::{IVec2, Vec2}, - DemandIndex, ItemIndex, RecipeIndex, TileIndex, + DemandIndex, ItemIndex, MapMetadata, RecipeIndex, TileIndex, }; use serde::{Deserialize, Serialize}; use std::{ @@ -105,7 +105,7 @@ pub struct Gamedata { pub tile_names: Vec, pub tile_collide: Vec, pub tile_interact: Vec, - pub map_names: HashSet, + pub map: HashMap, #[serde(skip)] pub recipes: Vec, #[serde(skip)] pub demands: Vec, #[serde(skip)] pub initial_map: HashMap)>, @@ -116,7 +116,7 @@ pub struct Gamedata { #[derive(Debug, Deserialize, Default)] pub struct DataIndex { - pub maps: HashSet, + pub maps: HashMap, pub demands: HashSet, pub recipes: HashSet, } @@ -137,7 +137,7 @@ impl DataIndex { } pub async fn read_map(&self, name: &str) -> Result { - if !self.maps.contains(name) { + if !self.maps.contains_key(name) { bail!("unknown map: {name:?}"); } let path = data_dir().join(format!("maps/{name}.yaml")); @@ -167,7 +167,7 @@ impl DataIndex { let recipes_in = serde_yaml::from_str(&self.read_recipes(recipes).await?)?; let mut gd = Gamedata::build(spec, map_in, demands_in, recipes_in)?; - gd.map_names = self.maps.clone(); + gd.map = self.maps.clone(); Ok(gd) } } @@ -288,7 +288,7 @@ impl Gamedata { tile_collide, tile_interact, recipes, - map_names: HashSet::new(), + map: HashMap::new(), initial_map, item_names, entities, diff --git a/server/src/game.rs b/server/src/game.rs index b20dfeb7..f196fd1f 100644 --- a/server/src/game.rs +++ b/server/src/game.rs @@ -169,12 +169,12 @@ impl Game { tile_names: self.data.tile_names.clone(), tile_collide: self.data.tile_collide.clone(), tile_interact: self.data.tile_interact.clone(), - map_names: self + maps: self .data - .map_names + .map .clone() .into_iter() - .filter(|n| n != "lobby") + .filter(|(n, _)| n != "lobby") .collect(), }, }); diff --git a/server/src/state.rs b/server/src/state.rs index 2af436a3..e9cb1722 100644 --- a/server/src/state.rs +++ b/server/src/state.rs @@ -184,7 +184,7 @@ impl State { Command::List => { bail!( "Maps: {:?}\nDemands: {:?}\nRecipes: {:?}", - self.index.maps, + self.index.maps.keys().collect::>(), self.index.demands, self.index.recipes ) -- cgit v1.2.3-70-g09d2