From 7df4af963c93e3bfc92f9e42b9e946186c1f89d2 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sat, 29 Jun 2024 14:44:14 +0200 Subject: change maps again and change spec order --- server/src/data.rs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'server/src/data.rs') diff --git a/server/src/data.rs b/server/src/data.rs index 6b0442ce..763a67bc 100644 --- a/server/src/data.rs +++ b/server/src/data.rs @@ -122,42 +122,39 @@ impl DataIndex { } pub fn generate(&self, spec: String) -> anyhow::Result { - let [demands, map, recipes] = spec - .split("-") - .collect::>() - .try_into() - .map_err(|_| anyhow!("data specification malformed"))?; + let (map, rest) = spec.split_once("-").unwrap_or((spec.as_str(), "default")); + let (demands, recipes) = rest.split_once("-").unwrap_or((rest, "default")); - if !self.demands.contains(demands) { - bail!("unknown demands: {demands:?}"); - } if !self.maps.contains(map) { bail!("unknown map: {map:?}"); } + if !self.demands.contains(demands) { + bail!("unknown demands: {demands:?}"); + } if !self.recipes.contains(recipes) { bail!("unknown recipes: {recipes:?}"); } - let demands_path = data_dir().join(format!("demands/{demands}.yaml")); let map_path = data_dir().join(format!("maps/{map}.yaml")); + let demands_path = data_dir().join(format!("demands/{demands}.yaml")); let recipes_path = data_dir().join(format!("recipes/{recipes}.yaml")); + let map_in = serde_yaml::from_reader(File::open(map_path).context("opening map failed")?)?; let demands_in = serde_yaml::from_reader(File::open(demands_path).context("opening demands failed")?)?; - let map_in = serde_yaml::from_reader(File::open(map_path).context("opening map failed")?)?; let recipes_in = serde_yaml::from_reader( File::open(recipes_path).context("opening recipes failed. are they generated yet?")?, )?; - Ok(Gamedata::build(recipes_in, map_in, demands_in)?) + Ok(Gamedata::build(map_in, demands_in, recipes_in)?) } } impl Gamedata { pub fn build( - recipes_in: Vec, map_in: InitialMap, demands_in: Vec, + recipes_in: Vec, ) -> Result { let item_names = RwLock::new(Vec::new()); let tile_names = RwLock::new(Vec::new()); -- cgit v1.2.3-70-g09d2