diff options
Diffstat (limited to 'server/src/recipes.rs')
| -rw-r--r-- | server/src/recipes.rs | 23 | 
1 files changed, 22 insertions, 1 deletions
| diff --git a/server/src/recipes.rs b/server/src/recipes.rs index b99cd21e..2dcb215c 100644 --- a/server/src/recipes.rs +++ b/server/src/recipes.rs @@ -1,5 +1,8 @@  use crate::protocol::{ItemIndex, TileIndex}; +use glam::IVec2; +use log::debug;  use serde::{Deserialize, Serialize}; +use std::collections::HashMap;  #[derive(Debug, Deserialize, Serialize, Clone, Copy, Default)]  #[serde(rename_all = "snake_case")] @@ -22,13 +25,21 @@ pub struct Recipe<T = TileIndex, I = ItemIndex> {      pub action: Action,  } +#[derive(Debug, Clone, Deserialize)] +pub struct InitialMap { +    map: Vec<String>, +    tiles: HashMap<String, String>, +} +  #[derive(Debug, Clone, Serialize, Deserialize)]  pub struct Gamedata {      pub recipes: Vec<Recipe>,      pub item_names: Vec<String>,      pub tile_names: Vec<String>, +    #[serde(skip)] +    pub initial_map: HashMap<IVec2, TileIndex>,  } -pub fn build_gamedata(recipes_in: Vec<Recipe<String, String>>) -> Gamedata { +pub fn build_gamedata(recipes_in: Vec<Recipe<String, String>>, map_in: InitialMap) -> Gamedata {      let mut item_names = Vec::new();      let mut tile_names = Vec::new();      let mut recipes = Vec::new(); @@ -52,8 +63,18 @@ pub fn build_gamedata(recipes_in: Vec<Recipe<String, String>>) -> Gamedata {          })      } +    let mut initial_map = HashMap::new(); +    for (y, line) in map_in.map.iter().enumerate() { +        for (x, tile) in line.trim().char_indices() { +            debug!("{tile:?}"); +            let tile = register(&mut tile_names, map_in.tiles[&tile.to_string()].clone()); +            initial_map.insert(IVec2::new(x as i32, y as i32), tile); +        } +    } +      Gamedata {          recipes, +        initial_map,          item_names,          tile_names,      } | 
