aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-09-30 02:58:36 +0200
committermetamuffin <metamuffin@disroot.org>2025-09-30 02:58:36 +0200
commit184366186986296cef96ccec75b563f33747ee36 (patch)
treef326bc2e7a68ba2d8f9583a7ca0229d78ef1a69a
parentbdf3c2d0e8221792d3adc8c82e2c2db087319701 (diff)
downloadhurrycurry-184366186986296cef96ccec75b563f33747ee36.tar
hurrycurry-184366186986296cef96ccec75b563f33747ee36.tar.bz2
hurrycurry-184366186986296cef96ccec75b563f33747ee36.tar.zst
Refuse to load maps with unused tiles
-rw-r--r--data/maps/5star.yaml1
-rw-r--r--data/maps/debug.yaml5
-rw-r--r--data/maps/lobby.yaml1
-rw-r--r--server/src/data/mod.rs33
4 files changed, 21 insertions, 19 deletions
diff --git a/data/maps/5star.yaml b/data/maps/5star.yaml
index 56d7dd25..55597460 100644
--- a/data/maps/5star.yaml
+++ b/data/maps/5star.yaml
@@ -84,7 +84,6 @@ tiles:
"d": door -w
"█": wall -c
"▒": wall-window -c
- "=": fence -c
"Ŧ": lamp -c
entities:
diff --git a/data/maps/debug.yaml b/data/maps/debug.yaml
index 6699aa84..91f4c7a6 100644
--- a/data/maps/debug.yaml
+++ b/data/maps/debug.yaml
@@ -38,7 +38,6 @@ tiles:
"⌷": counter
"f": counter -i=foodprocessor
"p": counter -i=plate
- "t": table
"s": sink
"o": oven
"z": freezer
@@ -72,10 +71,6 @@ tiles:
"~": floor -w --chef-spawn --customer-spawn
".": floor -w
"'": grass -w
- "*": tree -c
- "!": path -w
- "_": path -w
- "d": door -w
"Æ": counter-window:blue
"A": wall:blue -c
"B": wall:red -c
diff --git a/data/maps/lobby.yaml b/data/maps/lobby.yaml
index 8396f475..3b7d5777 100644
--- a/data/maps/lobby.yaml
+++ b/data/maps/lobby.yaml
@@ -39,7 +39,6 @@ tiles:
"4": table -i=plate:sliced-lettuce,sliced-tomato
"5": table -i=plate:nigiri
"6": table -i=dirty-plate
- "s": sink
"c": chair -w
"~": floor -w --chef-spawn
".": floor -w --customer-spawn
diff --git a/server/src/data/mod.rs b/server/src/data/mod.rs
index 1fab912a..7d3841d1 100644
--- a/server/src/data/mod.rs
+++ b/server/src/data/mod.rs
@@ -254,6 +254,13 @@ pub fn build_data(
assert_eq!(r.points, None, "points specified where not possible")
}
+ let mut tile_specs = BTreeMap::new();
+ for (char, tile_spec_raw) in map_in.tiles {
+ let mut toks = shlex::split(&tile_spec_raw).ok_or(anyhow!("tile spec quoting invalid"))?;
+ toks.insert(0, "tile-spec".to_string()); // exe name
+ tile_specs.insert(char, TileArgs::try_parse_from(toks)?);
+ }
+
let mut chef_spawn = None;
let mut customer_spawn = None;
let mut initial_map = HashMap::new();
@@ -262,24 +269,19 @@ pub fn build_data(
let mut tile_walkable = HashSet::new();
let mut exclusive_tiles = BTreeSet::new();
for (y, line) in map_in.map.iter().enumerate() {
- for (x, tile) in line.chars().enumerate() {
- if tile == ' ' {
+ for (x, char) in line.chars().enumerate() {
+ if char == ' ' {
continue; // space is empty space
}
let pos = IVec2::new(x as i32, y as i32);
- let tile_spec = map_in
- .tiles
- .get(&tile)
- .ok_or(anyhow!("tile {tile} is undefined"))?
- .clone();
- let mut toks = shlex::split(&tile_spec).ok_or(anyhow!("tile spec quoting invalid"))?;
- toks.insert(0, "tile-spec".to_string()); // exe name
- let tile_spec = TileArgs::try_parse_from(toks)?;
+ let tile_spec = tile_specs
+ .get(&char)
+ .ok_or(anyhow!("tile {char} is undefined"))?;
- let tile = reg.register_tile(tile_spec.tile_name);
+ let tile = reg.register_tile(tile_spec.tile_name.clone());
tiles_used.insert(tile);
- let item = tile_spec.item.map(|i| reg.register_item(i));
+ let item = tile_spec.item.clone().map(|i| reg.register_item(i));
items_used.extend(item);
initial_map.insert(pos, (tile, item));
@@ -300,6 +302,13 @@ pub fn build_data(
}
}
}
+
+ for tile in tile_specs.values() {
+ if !tiles_used.contains(&reg.register_tile(tile.tile_name.clone())) {
+ bail!("tile {:?} is unused", tile.tile_name)
+ }
+ }
+
let chef_spawn = chef_spawn.ok_or(anyhow!("map has no chef spawn"))?;
entities.extend(