diff options
Diffstat (limited to 'server/src/data.rs')
-rw-r--r-- | server/src/data.rs | 21 |
1 files changed, 9 insertions, 12 deletions
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<Gamedata> { - let [demands, map, recipes] = spec - .split("-") - .collect::<Vec<_>>() - .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<RecipeDecl>, map_in: InitialMap, demands_in: Vec<DemandDecl>, + recipes_in: Vec<RecipeDecl>, ) -> Result<Self> { let item_names = RwLock::new(Vec::new()); let tile_names = RwLock::new(Vec::new()); |