aboutsummaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-09-27 17:18:25 +0200
committermetamuffin <metamuffin@disroot.org>2025-09-27 17:35:01 +0200
commit001c0c2e00082a87fb15754003f6b01a1b4fb89d (patch)
treed6d70017b5064abfb6f58a2ea027e06a8817b3e6 /server
parent2e301a9cae6b3944a5e6e32ba8184d31a7bddfba (diff)
downloadhurrycurry-001c0c2e00082a87fb15754003f6b01a1b4fb89d.tar
hurrycurry-001c0c2e00082a87fb15754003f6b01a1b4fb89d.tar.bz2
hurrycurry-001c0c2e00082a87fb15754003f6b01a1b4fb89d.tar.zst
Less flexible diagram node styles; use rendered item/tile images
Diffstat (limited to 'server')
-rw-r--r--server/protocol/src/book.rs12
-rw-r--r--server/tools/src/diagram_dot.rs67
-rw-r--r--server/tools/src/recipe_diagram.rs28
3 files changed, 71 insertions, 36 deletions
diff --git a/server/protocol/src/book.rs b/server/protocol/src/book.rs
index 33b5654e..02dfa425 100644
--- a/server/protocol/src/book.rs
+++ b/server/protocol/src/book.rs
@@ -54,8 +54,16 @@ pub struct DiagramNode {
#[bincode(with_serde)]
pub position: Vec2,
pub label: Message,
- pub color: Option<String>,
- pub shape: Option<String>,
+ pub style: NodeStyle,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode)]
+pub enum NodeStyle {
+ IntermediateProduct,
+ FinalProduct,
+ ProcessActive,
+ ProcessPassive,
+ ProcessInstant,
}
#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode)]
diff --git a/server/tools/src/diagram_dot.rs b/server/tools/src/diagram_dot.rs
index e78f831f..2c953987 100644
--- a/server/tools/src/diagram_dot.rs
+++ b/server/tools/src/diagram_dot.rs
@@ -17,7 +17,10 @@
*/
use anyhow::Result;
-use hurrycurry_protocol::{Gamedata, Message, book::Diagram};
+use hurrycurry_protocol::{
+ Gamedata, Message,
+ book::{Diagram, NodeStyle},
+};
use std::fmt::Write;
pub fn diagram_dot(data: &Gamedata, diagram: &Diagram) -> Result<String> {
@@ -25,20 +28,37 @@ pub fn diagram_dot(data: &Gamedata, diagram: &Diagram) -> Result<String> {
writeln!(out, "digraph {{")?;
for (i, n) in diagram.nodes.iter().enumerate() {
let mut attrs = Vec::new();
- if let Some(color) = &n.color {
- attrs.push(format!("style=filled"));
- attrs.push(format!("fillcolor={color:?}"));
- attrs.push(format!("color={color:?}"));
- }
- if let Some(shape) = &n.shape {
- attrs.push(format!("shape={shape}"));
+
+ node_style(&mut attrs, &n.style);
+ match &n.label {
+ Message::Text(text) => {
+ attrs.push(format!("label=\"{text}\""));
+ }
+ Message::Item(item_index) => {
+ attrs.push(format!(
+ "image=\"/tmp/items/{}.png\"",
+ data.item_name(*item_index)
+ ));
+ attrs.push("imagescale=true".to_owned());
+ attrs.push("width=1".to_owned());
+ attrs.push("height=1".to_owned());
+ attrs.push("fixedsize=true".to_owned());
+ attrs.push("label=\"\"".to_owned());
+ }
+ Message::Tile(tile_index) => {
+ attrs.push(format!(
+ "image=\"/tmp/tiles/{}.png\"",
+ data.tile_name(*tile_index)
+ ));
+ attrs.push("imagescale=true".to_owned());
+ attrs.push("width=1".to_owned());
+ attrs.push("height=1".to_owned());
+ attrs.push("fixedsize=true".to_owned());
+ attrs.push("label=\"\"".to_owned());
+ }
+ _ => unimplemented!(),
}
- writeln!(
- out,
- "k{i} [label=\"{}\" {}]",
- message_str(data, &n.label),
- attrs.join(" ")
- )?;
+ writeln!(out, "k{i} [{}]", attrs.join(" "))?;
}
for edge in &diagram.edges {
writeln!(out, "k{} -> k{}", edge.src, edge.dst)?;
@@ -47,11 +67,16 @@ pub fn diagram_dot(data: &Gamedata, diagram: &Diagram) -> Result<String> {
Ok(out)
}
-fn message_str(data: &Gamedata, message: &Message) -> String {
- match message {
- Message::Translation { .. } => todo!(),
- Message::Text(x) => x.to_owned(),
- Message::Item(item_index) => data.item_name(*item_index).to_string(),
- Message::Tile(tile_index) => data.tile_name(*tile_index).to_string(),
- }
+fn node_style(attrs: &mut Vec<String>, style: &NodeStyle) {
+ let (shape, color) = match style {
+ NodeStyle::FinalProduct => ("circle", "#555"),
+ NodeStyle::IntermediateProduct => ("circle", "#333"),
+ NodeStyle::ProcessActive => ("box", "#47c42b"),
+ NodeStyle::ProcessPassive => ("box", "#c4a32b"),
+ NodeStyle::ProcessInstant => ("box", "#5452d8"),
+ };
+ attrs.push(format!("shape={shape}"));
+ attrs.push("style=filled".to_owned());
+ attrs.push(format!("fillcolor=\"{color}\""));
+ attrs.push(format!("color=\"{color}\""));
}
diff --git a/server/tools/src/recipe_diagram.rs b/server/tools/src/recipe_diagram.rs
index cdc6a942..5a119494 100644
--- a/server/tools/src/recipe_diagram.rs
+++ b/server/tools/src/recipe_diagram.rs
@@ -19,7 +19,7 @@
use anyhow::Result;
use hurrycurry_protocol::{
Gamedata, ItemIndex, Message, Recipe, RecipeIndex,
- book::{Diagram, DiagramEdge, DiagramNode},
+ book::{Diagram, DiagramEdge, DiagramNode, NodeStyle},
glam::Vec2,
};
use hurrycurry_server::data::Serverdata;
@@ -84,27 +84,29 @@ pub(crate) fn recipe_diagram(
diag.nodes.push(DiagramNode {
label: Message::Item(i),
position: Vec2::ZERO,
- color: None,
- shape: None,
+ style: if target_items.contains(data.item_name(i)) {
+ NodeStyle::FinalProduct
+ } else {
+ NodeStyle::IntermediateProduct
+ },
});
}
for r in recipes {
let index = diag.nodes.len();
let recipe = data.recipe(r.index);
- let (kind, color) = match recipe {
- Recipe::Passive { .. } => ("Passive", "#c4a32b"),
- Recipe::Active { .. } => ("Active", "#47c42b"),
- Recipe::Instant { .. } => ("Instant", "#5452d8"),
+ let (kind, style) = match recipe {
+ Recipe::Passive { .. } => ("Passive", NodeStyle::ProcessPassive),
+ Recipe::Active { .. } => ("Active", NodeStyle::ProcessActive),
+ Recipe::Instant { .. } => ("Instant", NodeStyle::ProcessInstant),
};
diag.nodes.push(DiagramNode {
position: Vec2::ZERO,
- label: Message::Text(if let Some(tile) = recipe.tile() {
- format!("{kind} on {}", data.tile_name(tile))
+ label: if let Some(tile) = recipe.tile() {
+ Message::Tile(tile)
} else {
- format!("{kind}")
- }),
- color: Some(color.to_string()),
- shape: Some("box".to_string()),
+ Message::Text(format!("{kind}"))
+ },
+ style,
});
for i in r.inputs {