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 | |
parent | fdcf100f756f5d2fe8550705a2a10124bfa1c021 (diff) | |
download | hurrycurry-3d870a714348defc40cd519c00b43c87b1be6480.tar hurrycurry-3d870a714348defc40cd519c00b43c87b1be6480.tar.bz2 hurrycurry-3d870a714348defc40cd519c00b43c87b1be6480.tar.zst |
load map from file
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | data/map.yaml | 28 | ||||
-rw-r--r-- | data/recipes.yaml | 38 | ||||
-rw-r--r-- | server/src/game.rs | 44 | ||||
-rw-r--r-- | server/src/main.rs | 6 | ||||
-rw-r--r-- | server/src/recipes.rs | 23 |
6 files changed, 76 insertions, 64 deletions
@@ -1,2 +1,3 @@ /target .vscode/ +/test-client/*.js diff --git a/data/map.yaml b/data/map.yaml new file mode 100644 index 00000000..096bb945 --- /dev/null +++ b/data/map.yaml @@ -0,0 +1,28 @@ +map: + - "+--------------------+" + - "|ctc.ctc.ctc.ctc.ctc.|" + - "|.....c..............|" + - "|c...c...+--www---dd-+" + - "|tc.ctc..|##...##W..#|" + - "|c...c...w..........S|" + - "|c.......w..######..T|" + - "|tc......w..........F|" + - "|c.....ct|##ss##ooo##|" + - "+---dd---+-----------+" + +tiles: + ".": floor + "+": wall + "-": wall + "|": wall + "d": door + "t": table + "c": chair + "#": counter + "w": window + "s": sink + "o": oven + "W": watercooler + "S": raw-steak-spawn + "T": tomato-spawn + "F": flour-spawn diff --git a/data/recipes.yaml b/data/recipes.yaml index f356912c..e95c6e03 100644 --- a/data/recipes.yaml +++ b/data/recipes.yaml @@ -1,30 +1,30 @@ - { tile: floor, action: !never } -- { tile: counter, inputs: [steak-meal, void] } -- { tile: counter, inputs: [sliced-tomato-meal, void] } -- { tile: counter, inputs: [bread-meal, void] } -- { tile: counter, inputs: [burger-meal, void] } -- { tile: counter, inputs: [tomatosteak-meal, void] } -- { tile: counter, inputs: [tomatoburger-meal, void] } +- { tile: window, inputs: [steak-meal, void] } +- { tile: window, inputs: [sliced-tomato-meal, void] } +- { tile: window, inputs: [bread-meal, void] } +- { tile: window, inputs: [burger-meal, void] } +- { tile: window, inputs: [tomatosteak-meal, void] } +- { tile: window, inputs: [tomatoburger-meal, void] } - { tile: trash, action: !instant , inputs: [raw-steak] } - { tile: trash, action: !instant , inputs: [steak] } - { tile: trash, action: !instant , inputs: [flour] } - { tile: trash, action: !instant , inputs: [dough] } - { tile: trash, action: !instant , inputs: [steak-meal] } -- { tile: table, inputs: [raw-steak, void] } -- { tile: table, inputs: [sliced-tomato, void] } -- { tile: table, inputs: [dough, void] } -- { tile: table, inputs: [bread, void] } +- { tile: counter, inputs: [raw-steak, void] } +- { tile: counter, inputs: [sliced-tomato, void] } +- { tile: counter, inputs: [dough, void] } +- { tile: counter, inputs: [bread, void] } - tile: tomato-spawn # Tomato pipeline outputs: [tomato] action: !instant -- tile: table +- tile: counter inputs: [tomato] outputs: [sliced-tomato] action: !active 3 -- tile: table +- tile: counter inputs: [sliced-tomato, plate] outputs: [sliced-tomato-meal] action: !instant @@ -32,7 +32,7 @@ - tile: flour-spawn # Bread pipeline outputs: [flour] action: !instant -- tile: table +- tile: counter inputs: [flour] outputs: [dough] action: !active 5 @@ -40,7 +40,7 @@ inputs: [dough] outputs: [bread] action: !passive 20 -- tile: table +- tile: counter inputs: [bread, plate] outputs: [bread-meal] action: !instant @@ -52,24 +52,24 @@ inputs: [raw-steak] outputs: [steak] action: !passive 15 -- tile: table +- tile: counter inputs: [steak, plate] outputs: [steak-meal] action: !instant -- tile: table # Combination meals +- tile: counter # Combination meals inputs: [steak-meal, bread] outputs: [burger-meal] action: !instant -- tile: table +- tile: counter inputs: [steak-meal, sliced-tomato] outputs: [tomatosteak-meal] action: !instant -- tile: table +- tile: counter inputs: [burger-meal, sliced-tomato] outputs: [tomatoburger-meal] action: !instant -- tile: table +- tile: counter inputs: [tomatosteak-meal, bread] outputs: [tomatoburger-meal] action: !instant diff --git a/server/src/game.rs b/server/src/game.rs index f91e42d0..16f40a6d 100644 --- a/server/src/game.rs +++ b/server/src/game.rs @@ -49,49 +49,9 @@ impl Game { players: Default::default(), tiles: Default::default(), }; - for x in -5..5 { - for y in -5..5 { - g.tiles - .insert(IVec2 { x, y }, gamedata.get_tile("floor").unwrap().into()); - } + for (&p, &t) in &gamedata.initial_map { + g.tiles.insert(p, t.into()); } - for x in -5..5 { - g.tiles.insert( - IVec2 { x, y: -5 }, - gamedata.get_tile("counter").unwrap().into(), - ); - g.tiles.insert( - IVec2 { x, y: 4 }, - gamedata.get_tile("table").unwrap().into(), - ); - } - for y in -5..5 { - g.tiles.insert( - IVec2 { x: -5, y }, - gamedata.get_tile("table").unwrap().into(), - ); - g.tiles.insert( - IVec2 { x: 4, y }, - gamedata.get_tile("table").unwrap().into(), - ); - } - - g.tiles.extend( - [ - ([1, 4], "pan"), - ([2, 4], "pan"), - ([-1, 4], "oven"), - ([-2, 4], "oven"), - ([-5, 2], "sink"), - ([-5, 3], "dirty-plate-spawn"), - ([4, 0], "flour-spawn"), - ([4, 1], "tomato-spawn"), - ([4, 2], "raw-steak-spawn"), - ([4, -4], "trash"), - ] - .map(|(k, v)| (IVec2::from_array(k), gamedata.get_tile(v).unwrap().into())), - ); - g } diff --git a/server/src/main.rs b/server/src/main.rs index d747e737..5414e9fd 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -27,8 +27,10 @@ async fn main() -> Result<()> { ); info!("listening for websockets on {}", ws_listener.local_addr()?); - let data = - build_gamedata(serde_yaml::from_reader(File::open("data/recipes.yaml").unwrap()).unwrap()); + let data = build_gamedata( + serde_yaml::from_reader(File::open("data/recipes.yaml").unwrap()).unwrap(), + serde_yaml::from_reader(File::open("data/map.yaml").unwrap()).unwrap(), + ); let game = Arc::new(RwLock::new(Game::new(data.into()))); let (tx, rx) = broadcast::channel::<PacketC>(1024); 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, } |