diff options
author | metamuffin <metamuffin@disroot.org> | 2024-06-18 13:28:31 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-06-23 19:21:22 +0200 |
commit | 3d870a714348defc40cd519c00b43c87b1be6480 (patch) | |
tree | 5e013dff20bcb41594dbe168f83b32f0f616aa26 /server/src/recipes.rs | |
parent | fdcf100f756f5d2fe8550705a2a10124bfa1c021 (diff) | |
download | hurrycurry-3d870a714348defc40cd519c00b43c87b1be6480.tar hurrycurry-3d870a714348defc40cd519c00b43c87b1be6480.tar.bz2 hurrycurry-3d870a714348defc40cd519c00b43c87b1be6480.tar.zst |
load map from file
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, } |