diff options
Diffstat (limited to 'server/data/src/book')
-rw-r--r-- | server/data/src/book/mod.rs | 63 | ||||
-rw-r--r-- | server/data/src/book/recipe_diagram.rs | 10 |
2 files changed, 6 insertions, 67 deletions
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 |