aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-07-11 13:48:42 +0200
committermetamuffin <metamuffin@disroot.org>2024-07-11 13:48:42 +0200
commitae29ca99dde89f8b975ce7b3a716411ab2028e50 (patch)
tree0ecd0107dda055f9e5f4391d1df545f662a98920
parent42900ac1c14712f181a9719a85d9df879e15ef29 (diff)
downloadhurrycurry-ae29ca99dde89f8b975ce7b3a716411ab2028e50.tar
hurrycurry-ae29ca99dde89f8b975ce7b3a716411ab2028e50.tar.bz2
hurrycurry-ae29ca99dde89f8b975ce7b3a716411ab2028e50.tar.zst
send map metadata
-rw-r--r--data/index.yaml37
-rw-r--r--server/protocol/src/lib.rs11
-rw-r--r--server/src/data.rs12
-rw-r--r--server/src/game.rs6
-rw-r--r--server/src/state.rs2
-rw-r--r--test-client/protocol.ts8
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 =