diff options
author | metamuffin <metamuffin@disroot.org> | 2025-10-07 00:13:56 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-10-07 00:14:00 +0200 |
commit | f6458b62e733de11e3665c83bcde4fd4051d7842 (patch) | |
tree | 540942eeee8381d289022668d8cf81f6a73f75a5 | |
parent | dfa1adc6f7e2d57c1897223d1620f28140b518e8 (diff) | |
download | hurrycurry-f6458b62e733de11e3665c83bcde4fd4051d7842.tar hurrycurry-f6458b62e733de11e3665c83bcde4fd4051d7842.tar.bz2 hurrycurry-f6458b62e733de11e3665c83bcde4fd4051d7842.tar.zst |
Book pages from recipe groups
-rw-r--r-- | data/recipes/default.js | 2 | ||||
-rw-r--r-- | server/data/src/book/mod.rs | 63 | ||||
-rw-r--r-- | server/data/src/book/recipe_diagram.rs | 10 | ||||
-rw-r--r-- | server/data/src/lib.rs | 22 | ||||
-rw-r--r-- | server/tools/src/main.rs | 3 |
5 files changed, 25 insertions, 75 deletions
diff --git a/data/recipes/default.js b/data/recipes/default.js index 0f7308af..a5497b83 100644 --- a/data/recipes/default.js +++ b/data/recipes/default.js @@ -231,7 +231,7 @@ function group_hidden(i) { return i } -out({ group: "cleanup", action: "active", duration: 2, tile: "sink", inputs: [new Item("dirty-plate")], outputs: [PL] }) +out({ action: "active", duration: 2, tile: "sink", inputs: [new Item("dirty-plate")], outputs: [PL] }) const tomato = crate("tomato") const steak = crate("steak") diff --git a/server/data/src/book/mod.rs b/server/data/src/book/mod.rs index b52779f3..f9b54d0d 100644 --- a/server/data/src/book/mod.rs +++ b/server/data/src/book/mod.rs @@ -30,64 +30,6 @@ use hurrycurry_protocol::{ book::{Book, BookPage}, }; -struct RecipePageParams<'a> { - name: &'a str, - repr_items: &'a [&'a str], -} -static RECIPE_PAGES: &[RecipePageParams] = &[ - RecipePageParams { - name: "cheese-leek-soup", - repr_items: &["plate:cheese-leek-soup"], - }, - RecipePageParams { - name: "tomato-soup", - repr_items: &["plate:tomato-soup"], - }, - RecipePageParams { - name: "mushroom-soup", - repr_items: &["plate:mushroom-soup"], - }, - RecipePageParams { - name: "burger", - repr_items: &[ - "plate:seared-patty,sliced-bun,sliced-lettuce,sliced-tomato", - "plate:seared-patty,sliced-bun,sliced-cheese,sliced-tomato", - ], - }, - RecipePageParams { - name: "noodles", - repr_items: &["plate:cooked-noodles,sliced-cheese,tomato-juice"], - }, - RecipePageParams { - name: "pizza", - repr_items: &["plate:baked-rolled-dough:sliced-cheese,sliced-mushroom,tomato-juice"], - }, - RecipePageParams { - name: "curry", - repr_items: &["plate:cooked-rice,curry"], - }, - RecipePageParams { - name: "drinks", - repr_items: &[ - "glass:water", - "glass:tomato-juice", - "glass:strawberry-shake", - ], - }, - RecipePageParams { - name: "mochi", - repr_items: &["plate:strawberry-mochi"], - }, - RecipePageParams { - name: "doughnut", - repr_items: &["plate:doughnut"], - }, - RecipePageParams { - name: "doughnut", - repr_items: &["plate:doughnut"], - }, -]; - pub fn book(data: &Gamedata, serverdata: &Serverdata) -> Result<Book> { let mut pages = Vec::new(); @@ -97,8 +39,9 @@ pub fn book(data: &Gamedata, serverdata: &Serverdata) -> Result<Book> { }); let mut toc = Vec::new(); - for &RecipePageParams { name, repr_items } in RECIPE_PAGES { - let mut diagram = recipe_diagram(data, serverdata, repr_items)?; + for (name, repr) in serverdata.recipe_groups.clone() { + let repr = repr.into_iter().collect::<Vec<_>>(); + let mut diagram = recipe_diagram(data, serverdata, &repr)?; diagram_layout(&mut diagram)?; let title = Message::Translation { id: format!("b.{name}.title"), diff --git a/server/data/src/book/recipe_diagram.rs b/server/data/src/book/recipe_diagram.rs index 2ec92b68..a4b9a7b1 100644 --- a/server/data/src/book/recipe_diagram.rs +++ b/server/data/src/book/recipe_diagram.rs @@ -31,7 +31,7 @@ use std::{ pub fn recipe_diagram( data: &Gamedata, serverdata: &Serverdata, - target_items: &[&str], + target_items: &[ItemIndex], ) -> Result<Diagram> { let ambient_items = serverdata .initial_map @@ -40,11 +40,7 @@ pub fn recipe_diagram( .copied() .collect::<HashSet<_>>(); - let mut need = BTreeSet::from_iter( - target_items - .iter() - .map(|name| data.get_item_by_name(name).unwrap()), - ); + let mut need = BTreeSet::from_iter(target_items.iter().copied()); let mut have = BTreeSet::<ItemIndex>::new(); let mut recipes = BTreeSet::new(); @@ -87,7 +83,7 @@ pub fn recipe_diagram( diag.nodes.push(DiagramNode { label: Message::Item(i), position: Vec2::ZERO, - style: if target_items.contains(&data.item_name(i)) { + style: if target_items.contains(&i) { NodeStyle::FinalProduct } else { NodeStyle::IntermediateProduct diff --git a/server/data/src/lib.rs b/server/data/src/lib.rs index 822d6997..fa078643 100644 --- a/server/data/src/lib.rs +++ b/server/data/src/lib.rs @@ -31,7 +31,7 @@ use hurrycurry_protocol::{ }; use serde::{Deserialize, Serialize}; use std::{ - collections::{BTreeMap, HashMap, HashSet}, + collections::{BTreeMap, BTreeSet, HashMap, HashSet}, sync::RwLock, time::Duration, }; @@ -52,14 +52,16 @@ pub enum RecipeDeclAction { #[rustfmt::skip] #[derive(Debug, Clone, Deserialize, Serialize)] pub struct RecipeDecl { - #[serde(default)] tile: Option<String>, + tile: Option<String>, #[serde(default)] inputs: Vec<String>, #[serde(default)] outputs: Vec<String>, #[serde(default)] action: RecipeDeclAction, #[serde(default)] warn: bool, - #[serde(default)] revert_duration: Option<f32>, - #[serde(default)] duration: Option<f32>, - #[serde(default)] points: Option<i64>, + revert_duration: Option<f32>, + duration: Option<f32>, + points: Option<i64>, + group: Option<String>, + #[serde(default)] group_hidden: bool, } #[rustfmt::skip] @@ -114,7 +116,8 @@ pub struct Serverdata { pub default_timer: Option<Duration>, pub book: Book, pub flags: ServerdataFlags, - pub entity_decls: Vec<EntityDecl> + pub entity_decls: Vec<EntityDecl>, + pub recipe_groups: BTreeMap<String, BTreeSet<ItemIndex>>, } #[rustfmt::skip] @@ -133,6 +136,7 @@ fn build_data( let mut recipes = Vec::new(); let mut entities = Vec::new(); let mut raw_demands = Vec::new(); + let mut recipe_groups = BTreeMap::<String, BTreeSet<ItemIndex>>::new(); for mut r in recipes_in { #[cfg(feature = "fast_recipes")] @@ -149,6 +153,11 @@ fn build_data( let mut inputs = r.inputs.into_iter().map(|i| reg.register_item(i)); let mut outputs = r.outputs.into_iter().map(|o| reg.register_item(o)); let tile = r.tile.map(|t| reg.register_tile(t)); + if let Some(g) = r.group { + if !r.group_hidden { + recipe_groups.entry(g).or_default().extend(inputs.clone()); + } + } match r.action { RecipeDeclAction::Never => {} RecipeDeclAction::Passive => recipes.push(Recipe::Passive { @@ -327,6 +336,7 @@ fn build_data( book: Book::default(), score_baseline: map_in.score_baseline, entity_decls: entities, + recipe_groups, }, )) } diff --git a/server/tools/src/main.rs b/server/tools/src/main.rs index f70c5755..8d8e4fd0 100644 --- a/server/tools/src/main.rs +++ b/server/tools/src/main.rs @@ -81,7 +81,8 @@ fn main() -> Result<()> { let mut index = DataIndex::default(); index.reload()?; let (data, serverdata) = index.generate("5star")?; - let mut diagram = recipe_diagram(&data, &serverdata, &[&out])?; + let out = data.get_item_by_name(&out).unwrap(); + let mut diagram = recipe_diagram(&data, &serverdata, &[out])?; let out = if dot_out { diagram_dot(&data, &diagram, false)? } else if custom_svg { |