aboutsummaryrefslogtreecommitdiff
path: root/server/tools/src/diagram_dot.rs
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/tools/src/diagram_dot.rs
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/tools/src/diagram_dot.rs')
-rw-r--r--server/tools/src/diagram_dot.rs67
1 files changed, 46 insertions, 21 deletions
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}\""));
}