diff options
-rw-r--r-- | data/index.yaml | 37 | ||||
-rw-r--r-- | server/protocol/src/lib.rs | 11 | ||||
-rw-r--r-- | server/src/data.rs | 12 | ||||
-rw-r--r-- | server/src/game.rs | 6 | ||||
-rw-r--r-- | server/src/state.rs | 2 | ||||
-rw-r--r-- | test-client/protocol.ts | 8 |
6 files changed, 44 insertions, 32 deletions
diff --git a/data/index.yaml b/data/index.yaml index 5ee3719a..38cf0f38 100644 --- a/data/index.yaml +++ b/data/index.yaml @@ -19,25 +19,24 @@ demands: - default maps: - - lobby - - sophomore - - junior - - senior - - test - - 5star - - depot - - line - - teeny - - bus - - rivalry - - village - - zigzag - - bbq - - station - - smallest - - duplex - - conveyors_dot_com - - bar + lobby: { name: "Lobby", players: 0, difficulty: 3 } + sophomore: { name: "Sophomore", players: 1, difficulty: 1 } + junior: { name: "Junior", players: 3, difficulty: 2 } + senior: { name: "Senior", players: 4, difficulty: 2 } + 5star: { name: "5 Star", players: 10, difficulty: 5 } + line: { name: "Line", players: 2, difficulty: 3 } + teeny: { name: "Teeny", players: 3, difficulty: 3 } + depot: { name: "Depot", players: 4, difficulty: 4 } + bus: { name: "Bus", players: 5, difficulty: 6 } + rivalry: { name: "Rivalry", players: 2, difficulty: 3 } + village: { name: "Village", players: 4, difficulty: 3 } + zigzag: { name: "Zig-zag", players: 6, difficulty: 4 } + bbq: { name: "BBQ", players: 2, difficulty: 3 } + station: { name: "Station", players: 3, difficulty: 3 } + smallest: { name: "Smallest", players: 1, difficulty: 1 } + duplex: { name: "Duplex", players: 2, difficulty: 4 } + conveyors_dot_com: { name: "conveyors.com", players: 3, difficulty: 5 } + bar: { name: "Bar", players: 3, difficulty: 3 } recipes: - none diff --git a/server/protocol/src/lib.rs b/server/protocol/src/lib.rs index 147a4fc3..cb72d2ff 100644 --- a/server/protocol/src/lib.rs +++ b/server/protocol/src/lib.rs @@ -17,7 +17,7 @@ */ use glam::{IVec2, Vec2}; use serde::{Deserialize, Serialize}; -use std::{collections::HashSet, fmt::Display}; +use std::{collections::HashMap, fmt::Display}; pub use glam; @@ -38,6 +38,13 @@ pub struct RecipeIndex(pub usize); #[serde(transparent)] pub struct DemandIndex(pub usize); +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct MapMetadata { + name: String, + players: usize, + difficulty: i32, +} + #[derive(Debug, Clone, Serialize, Deserialize, Default)] #[rustfmt::skip] pub struct ClientGamedata { @@ -45,7 +52,7 @@ pub struct ClientGamedata { pub tile_names: Vec<String>, pub tile_collide: Vec<bool>, pub tile_interact: Vec<bool>, - pub map_names: HashSet<String>, + pub maps: HashMap<String, MapMetadata>, } #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/server/src/data.rs b/server/src/data.rs index 5f35a360..c5ed25ad 100644 --- a/server/src/data.rs +++ b/server/src/data.rs @@ -23,7 +23,7 @@ use crate::{ use anyhow::{anyhow, bail, Result}; use hurrycurry_protocol::{ glam::{IVec2, Vec2}, - DemandIndex, ItemIndex, RecipeIndex, TileIndex, + DemandIndex, ItemIndex, MapMetadata, RecipeIndex, TileIndex, }; use serde::{Deserialize, Serialize}; use std::{ @@ -105,7 +105,7 @@ pub struct Gamedata { pub tile_names: Vec<String>, pub tile_collide: Vec<bool>, pub tile_interact: Vec<bool>, - pub map_names: HashSet<String>, + pub map: HashMap<String, MapMetadata>, #[serde(skip)] pub recipes: Vec<Recipe>, #[serde(skip)] pub demands: Vec<Demand>, #[serde(skip)] pub initial_map: HashMap<IVec2, (TileIndex, Option<ItemIndex>)>, @@ -116,7 +116,7 @@ pub struct Gamedata { #[derive(Debug, Deserialize, Default)] pub struct DataIndex { - pub maps: HashSet<String>, + pub maps: HashMap<String, MapMetadata>, pub demands: HashSet<String>, pub recipes: HashSet<String>, } @@ -137,7 +137,7 @@ impl DataIndex { } pub async fn read_map(&self, name: &str) -> Result<String> { - if !self.maps.contains(name) { + if !self.maps.contains_key(name) { bail!("unknown map: {name:?}"); } let path = data_dir().join(format!("maps/{name}.yaml")); @@ -167,7 +167,7 @@ impl DataIndex { let recipes_in = serde_yaml::from_str(&self.read_recipes(recipes).await?)?; let mut gd = Gamedata::build(spec, map_in, demands_in, recipes_in)?; - gd.map_names = self.maps.clone(); + gd.map = self.maps.clone(); Ok(gd) } } @@ -288,7 +288,7 @@ impl Gamedata { tile_collide, tile_interact, recipes, - map_names: HashSet::new(), + map: HashMap::new(), initial_map, item_names, entities, diff --git a/server/src/game.rs b/server/src/game.rs index b20dfeb7..f196fd1f 100644 --- a/server/src/game.rs +++ b/server/src/game.rs @@ -169,12 +169,12 @@ impl Game { tile_names: self.data.tile_names.clone(), tile_collide: self.data.tile_collide.clone(), tile_interact: self.data.tile_interact.clone(), - map_names: self + maps: self .data - .map_names + .map .clone() .into_iter() - .filter(|n| n != "lobby") + .filter(|(n, _)| n != "lobby") .collect(), }, }); diff --git a/server/src/state.rs b/server/src/state.rs index 2af436a3..e9cb1722 100644 --- a/server/src/state.rs +++ b/server/src/state.rs @@ -184,7 +184,7 @@ impl State { Command::List => { bail!( "Maps: {:?}\nDemands: {:?}\nRecipes: {:?}", - self.index.maps, + self.index.maps.keys().collect::<Vec<_>>(), self.index.demands, self.index.recipes ) diff --git a/test-client/protocol.ts b/test-client/protocol.ts index ddbc43c8..10b5b2dc 100644 --- a/test-client/protocol.ts +++ b/test-client/protocol.ts @@ -20,13 +20,19 @@ export type PlayerID = number export type ItemIndex = number export type TileIndex = number +export interface MapMetadata { + name: string, + players: number, + difficulty: number, +} + export interface Gamedata { item_names: string[], // Look-up table for ItemIndex tile_names: string[], // Look-up table for TileIndex tile_collide: boolean[], // Look-up table for TileIndex to check tile collision with players tile_interact: boolean[], // Look-up table for TileIndex to check if a tile is interactable spawn: Vec2, // Where players spawn when they join. - map_names: string[], + maps: { [key: string]: MapMetadata }, } export type PacketS = |