diff options
author | metamuffin <metamuffin@disroot.org> | 2025-09-30 01:19:01 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-09-30 01:19:09 +0200 |
commit | 5033c326094edc1ff4234b994e95d987cb937fc4 (patch) | |
tree | 5fa426a77109722df163c15ce8d647170cd8fcea /server/src/data | |
parent | 727752b87bbe7146adb0f9e9e27d6e64b785ec2f (diff) | |
download | hurrycurry-5033c326094edc1ff4234b994e95d987cb937fc4.tar hurrycurry-5033c326094edc1ff4234b994e95d987cb937fc4.tar.bz2 hurrycurry-5033c326094edc1ff4234b994e95d987cb937fc4.tar.zst |
Implement tile placeable items for server-side (#433)
Diffstat (limited to 'server/src/data')
-rw-r--r-- | server/src/data/index.rs | 39 | ||||
-rw-r--r-- | server/src/data/mod.rs | 31 |
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, |