diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/src/data.rs | 19 | ||||
-rw-r--r-- | server/src/game.rs | 13 |
2 files changed, 22 insertions, 10 deletions
diff --git a/server/src/data.rs b/server/src/data.rs index fd268cb5..9c200e5b 100644 --- a/server/src/data.rs +++ b/server/src/data.rs @@ -31,7 +31,10 @@ pub struct RecipeDecl { #[derive(Debug, Clone, Deserialize)] pub struct InitialMap { map: Vec<String>, - tiles: HashMap<String, String>, + tiles: HashMap<char, String>, + items: HashMap<char, String>, + chef_spawn: char, + customer_spawn: char, } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -55,7 +58,7 @@ pub struct Gamedata { pub item_names: Vec<String>, pub tile_names: Vec<String>, #[serde(skip)] - pub initial_map: HashMap<IVec2, TileIndex>, + pub initial_map: HashMap<IVec2, (TileIndex, Option<ItemIndex>)>, pub chef_spawn: Vec2, pub customer_spawn: Vec2, } @@ -121,17 +124,17 @@ pub fn build_gamedata( for (y, line) in map_in.map.iter().enumerate() { for (x, tile) in line.trim().char_indices() { let pos = IVec2::new(x as i32, y as i32); - let mut tilename = map_in.tiles[&tile.to_string()].clone(); - if tilename == "chef-spawn" { + if tile == map_in.chef_spawn { chef_spawn = pos.as_vec2(); - tilename = "floor".to_owned(); } - if tilename == "customer-spawn" { + if tile == map_in.customer_spawn { customer_spawn = pos.as_vec2(); - tilename = "floor".to_owned(); } + let tilename = map_in.tiles[&tile].clone(); + let itemname = map_in.items.get(&tile).cloned(); let tile = TileIndex(register(&tile_names, tilename)); - initial_map.insert(pos, tile); + let item = itemname.map(|i| ItemIndex(register(&item_names, i))); + initial_map.insert(pos, (tile, item)); } } diff --git a/server/src/game.rs b/server/src/game.rs index e4693e4a..973b257b 100644 --- a/server/src/game.rs +++ b/server/src/game.rs @@ -54,8 +54,17 @@ impl Game { players: Default::default(), tiles: Default::default(), }; - for (&p, &t) in &gamedata.initial_map { - g.tiles.insert(p, t.into()); + for (&p, (tile, item)) in &gamedata.initial_map { + g.tiles.insert( + p, + Tile { + kind: *tile, + item: item.map(|i| Item { + kind: i, + active: None, + }), + }, + ); } g } |