aboutsummaryrefslogtreecommitdiff
path: root/server/data/src/book
diff options
context:
space:
mode:
Diffstat (limited to 'server/data/src/book')
-rw-r--r--server/data/src/book/diagram_layout.rs5
-rw-r--r--server/data/src/book/mod.rs13
-rw-r--r--server/data/src/book/recipe_diagram.rs14
3 files changed, 27 insertions, 5 deletions
diff --git a/server/data/src/book/diagram_layout.rs b/server/data/src/book/diagram_layout.rs
index 0ea26a69..29240b69 100644
--- a/server/data/src/book/diagram_layout.rs
+++ b/server/data/src/book/diagram_layout.rs
@@ -32,6 +32,11 @@ pub struct Layout {
}
pub fn diagram_layout(diagram: &mut Diagram) -> Result<()> {
+ // seems to have problems with a single node
+ if diagram.nodes.len() < 2 {
+ return Ok(());
+ }
+
let mut child = Command::new("dot")
.arg("-Tjson")
.arg("-Kdot")
diff --git a/server/data/src/book/mod.rs b/server/data/src/book/mod.rs
index 263e8111..a0776f41 100644
--- a/server/data/src/book/mod.rs
+++ b/server/data/src/book/mod.rs
@@ -23,7 +23,7 @@ use crate::{
Serverdata,
book::{diagram_layout::diagram_layout, recipe_diagram::recipe_diagram},
};
-use anyhow::Result;
+use anyhow::{Context, Result};
use hurrycurry_locale::trm;
use hurrycurry_protocol::{
Gamedata, Message,
@@ -40,9 +40,16 @@ pub fn book(data: &Gamedata, serverdata: &Serverdata) -> Result<Book> {
let mut toc = Vec::new();
for (name, repr) in serverdata.recipe_groups.clone() {
- let repr = repr.into_iter().collect::<Vec<_>>();
+ let repr = repr
+ .into_iter()
+ .filter(|&i| data.demands.iter().any(|d| d.input == i))
+ .collect::<Vec<_>>();
+ if repr.is_empty() {
+ continue;
+ }
+
let mut diagram = recipe_diagram(data, serverdata, &repr)?;
- diagram_layout(&mut diagram)?;
+ diagram_layout(&mut diagram).context("during layouting")?;
let title = Message::Translation {
id: format!("b.{name}.title"),
params: vec![],
diff --git a/server/data/src/book/recipe_diagram.rs b/server/data/src/book/recipe_diagram.rs
index a4b9a7b1..6ec9965f 100644
--- a/server/data/src/book/recipe_diagram.rs
+++ b/server/data/src/book/recipe_diagram.rs
@@ -17,7 +17,7 @@
*/
use crate::Serverdata;
-use anyhow::Result;
+use anyhow::{Result, bail};
use hurrycurry_protocol::{
Gamedata, ItemIndex, Message, Recipe, RecipeIndex,
book::{Diagram, DiagramEdge, DiagramNode, NodeStyle},
@@ -44,6 +44,11 @@ pub fn recipe_diagram(
let mut have = BTreeSet::<ItemIndex>::new();
let mut recipes = BTreeSet::new();
+ // If an ambient item is the target it must be moved from 'need' to 'have' early
+ for i in &ambient_items {
+ have.extend(need.take(i));
+ }
+
#[derive(PartialEq, PartialOrd, Eq, Ord)]
struct GraphRecipe {
index: RecipeIndex,
@@ -51,7 +56,8 @@ pub fn recipe_diagram(
outputs: Vec<ItemIndex>,
}
- while let Some(item) = need.pop_last() {
+ while let Some(item) = need.pop_first() {
+ let mut found_recipe = false;
for (ri, r) in data.recipes() {
if r.outputs().contains(&item) {
let gr = GraphRecipe {
@@ -72,8 +78,12 @@ pub fn recipe_diagram(
need.extend(gr.inputs.iter().filter(|i| !have.contains(&i)));
have.extend(&gr.outputs);
recipes.insert(gr);
+ found_recipe = true;
}
}
+ if !found_recipe {
+ bail!("stuck at making {}", data.item_name(item))
+ }
}
let mut diag = Diagram::default();