From a5814a2a81c0ea7bcf6d56626ff7167af78d63a6 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Mon, 6 Oct 2025 14:04:52 +0200 Subject: Collapse anywhere passive recipes --- server/tools/src/diagram_dot.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'server/tools/src/diagram_dot.rs') diff --git a/server/tools/src/diagram_dot.rs b/server/tools/src/diagram_dot.rs index b3e54881..f86a2d4e 100644 --- a/server/tools/src/diagram_dot.rs +++ b/server/tools/src/diagram_dot.rs @@ -19,7 +19,7 @@ use anyhow::{Result, bail}; use hurrycurry_protocol::{ Gamedata, Message, - book::{Diagram, NodeStyle}, + book::{Diagram, DiagramNode, NodeStyle}, }; use std::{ fmt::Write, @@ -27,6 +27,8 @@ use std::{ process::{Command, Stdio}, }; +use crate::diagram_svg::{edge_color, node_color}; + pub fn diagram_dot_svg(data: &Gamedata, diagram: &Diagram) -> Result { let mut child = Command::new("dot") .arg("-Tsvg") @@ -52,7 +54,7 @@ pub fn diagram_dot(data: &Gamedata, diagram: &Diagram, use_position: bool) -> Re if use_position { attrs.push(format!("pos=\"{},{}!\"", n.position.x, n.position.y)); } - node_style(&mut attrs, &n.style); + node_style(&mut attrs, &n); match &n.label { Message::Text(text) => { attrs.push(format!("label=\"{text}\"")); @@ -84,20 +86,22 @@ pub fn diagram_dot(data: &Gamedata, diagram: &Diagram, use_position: bool) -> Re writeln!(out, "k{i} [{}]", attrs.join(" "))?; } for edge in &diagram.edges { - writeln!(out, "k{} -> k{}", edge.src, edge.dst)?; + let color = edge_color(edge); + writeln!(out, "k{} -> k{} [color=\"{color}\"]", edge.src, edge.dst)?; } writeln!(out, "}}")?; Ok(out) } -fn node_style(attrs: &mut Vec, 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"), +fn node_style(attrs: &mut Vec, node: &DiagramNode) { + let shape = match node.style { + NodeStyle::FinalProduct => "circle", + NodeStyle::IntermediateProduct => "circle", + NodeStyle::ProcessActive => "box", + NodeStyle::ProcessPassive => "box", + NodeStyle::ProcessInstant => "box", }; + let color = node_color(node); attrs.push(format!("shape={shape}")); attrs.push("style=filled".to_owned()); attrs.push(format!("fillcolor=\"{color}\"")); -- cgit v1.2.3-70-g09d2