diff options
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/bin/graph.rs | 2 | ||||
-rw-r--r-- | server/src/data.rs | 21 | ||||
-rw-r--r-- | server/src/state.rs | 6 |
3 files changed, 13 insertions, 16 deletions
diff --git a/server/src/bin/graph.rs b/server/src/bin/graph.rs index 817352c1..deae2034 100644 --- a/server/src/bin/graph.rs +++ b/server/src/bin/graph.rs @@ -32,7 +32,7 @@ fn main() -> Result<()> { .nth(1) .ok_or(anyhow!("first arg should be recipe set name"))?; - let data = index.generate(format!("default-small-{rn}"))?; + let data = index.generate(format!("small-default-{rn}"))?; for i in 0..data.item_names.len() { println!("i{i} [label=\"{}\"]", data.item_name(ItemIndex(i))) 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()); diff --git a/server/src/state.rs b/server/src/state.rs index 08d8516a..ae3388b6 100644 --- a/server/src/state.rs +++ b/server/src/state.rs @@ -18,7 +18,7 @@ pub struct State { #[clap(multicall = true)] enum Command { Start { - #[arg(default_value = "default-small-default")] + #[arg(default_value = "small-default-default")] spec: String, }, End, @@ -30,7 +30,7 @@ impl State { index.reload()?; let mut game = Game::new(); - game.load(index.generate("none-lobby-none".to_string())?); + game.load(index.generate("lobby-none-none".to_string())?); Ok(Self { game, index, tx }) } @@ -69,7 +69,7 @@ impl State { } Command::End => { self.game - .load(self.index.generate("none-lobby-none".to_string())?); + .load(self.index.generate("lobby-none-none".to_string())?); } } Ok(()) |