aboutsummaryrefslogtreecommitdiff
path: root/server/src/data
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/data')
-rw-r--r--server/src/data/index.rs39
-rw-r--r--server/src/data/mod.rs31
2 files changed, 19 insertions, 51 deletions
diff --git a/server/src/data/index.rs b/server/src/data/index.rs
deleted file mode 100644
index a9ffbb81..00000000
--- a/server/src/data/index.rs
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- Hurry Curry! - a game about cooking
- Copyright (C) 2025 Hurry Curry! Contributors
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, version 3 of the License only.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <https://www.gnu.org/licenses/>.
-
-*/
-use hurrycurry_protocol::{Gamedata, ItemIndex, Recipe, RecipeIndex};
-use std::collections::HashMap;
-
-#[derive(Debug, Default)]
-pub struct GamedataIndex {
- pub recipe_passive_by_input: HashMap<ItemIndex, Vec<RecipeIndex>>,
-}
-
-impl GamedataIndex {
- pub fn update(&mut self, data: &Gamedata) {
- self.recipe_passive_by_input.clear();
-
- for (ri, r) in data.recipes() {
- if let Recipe::Passive { input, .. } = r {
- self.recipe_passive_by_input
- .entry(*input)
- .or_default()
- .push(ri);
- }
- }
- }
-}
diff --git a/server/src/data/mod.rs b/server/src/data/mod.rs
index d19b32a3..e5cd4552 100644
--- a/server/src/data/mod.rs
+++ b/server/src/data/mod.rs
@@ -16,7 +16,6 @@
*/
pub mod demands;
-pub mod index;
use crate::entity::{construct_entity, Entities, EntityDecl};
use anyhow::{anyhow, bail, Context, Result};
@@ -29,7 +28,7 @@ use hurrycurry_protocol::{
};
use serde::{Deserialize, Serialize};
use std::{
- collections::{HashMap, HashSet},
+ collections::{BTreeMap, HashMap, HashSet},
fs::{read_to_string, File},
path::PathBuf,
str::FromStr,
@@ -307,16 +306,24 @@ pub fn build_data(
maps.sort_unstable_by_key(|(_, m)| m.difficulty);
maps.sort_by_key(|(_, m)| m.players);
+ let mut tile_placeable_items = BTreeMap::new();
+ for tile_name in map_in.collider.iter().chain(map_in.walkable.iter()) {
+ let tile = reg.register_tile(tile_name.to_string());
+ let whitelist = recipes
+ .iter()
+ .filter(|r| r.tile() == Some(tile))
+ .flat_map(|e| e.inputs())
+ .collect();
+ tile_placeable_items.insert(tile, whitelist);
+ }
+ let tile_walkable = map_in
+ .walkable
+ .into_iter()
+ .map(|name| reg.register_tile(name))
+ .collect();
+
let item_names = reg.items.into_inner().unwrap();
let tile_names = reg.tiles.into_inner().unwrap();
- let tile_collide = tile_names
- .iter()
- .map(|i| !map_in.walkable.contains(i))
- .collect();
- let tile_interact = tile_names
- .iter()
- .map(|i| !map_in.collider.contains(i) && !map_in.walkable.contains(i))
- .collect();
let default_timer = if map_name.ends_with("lobby") {
None
@@ -329,8 +336,8 @@ pub fn build_data(
bot_algos,
current_map: map_name,
maps,
- tile_collide,
- tile_interact,
+ tile_walkable,
+ tile_placeable_items,
recipes,
item_names,
demands,