aboutsummaryrefslogtreecommitdiff
path: root/server/tools/src/diagram_layout.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-10-06 23:03:32 +0200
committermetamuffin <metamuffin@disroot.org>2025-10-06 23:03:40 +0200
commit176e6bc6c4c29bea3be2aceca99743b997c76c97 (patch)
tree1161e7a966843324756340da4b6452492902fa07 /server/tools/src/diagram_layout.rs
parentea86b11b682500160f37b35ea8f06b081cd05036 (diff)
downloadhurrycurry-176e6bc6c4c29bea3be2aceca99743b997c76c97.tar
hurrycurry-176e6bc6c4c29bea3be2aceca99743b997c76c97.tar.bz2
hurrycurry-176e6bc6c4c29bea3be2aceca99743b997c76c97.tar.zst
Move data code to own crate + general data refactor
Diffstat (limited to 'server/tools/src/diagram_layout.rs')
-rw-r--r--server/tools/src/diagram_layout.rs78
1 files changed, 0 insertions, 78 deletions
diff --git a/server/tools/src/diagram_layout.rs b/server/tools/src/diagram_layout.rs
deleted file mode 100644
index 0ea26a69..00000000
--- a/server/tools/src/diagram_layout.rs
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- Hurry Curry! - a game about cooking
- Copyright (C) 2025 Hurry Curry! Contributors
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, version 3 of the License only.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <https://www.gnu.org/licenses/>.
-
-*/
-
-use anyhow::{Result, anyhow};
-use hurrycurry_protocol::{book::Diagram, glam::Vec2};
-use serde::Deserialize;
-use std::{
- collections::BTreeMap,
- fmt::Write as W2,
- io::Write,
- process::{Command, Stdio},
-};
-
-pub struct Layout {
- pub nodes: BTreeMap<String, Vec2>,
- pub edges: Vec<(usize, usize)>,
-}
-
-pub fn diagram_layout(diagram: &mut Diagram) -> Result<()> {
- let mut child = Command::new("dot")
- .arg("-Tjson")
- .arg("-Kdot")
- .stdin(Stdio::piped())
- .stdout(Stdio::piped())
- .spawn()?;
-
- let mut out = String::new();
- writeln!(out, "digraph {{")?;
- for (i, _) in diagram.nodes.iter().enumerate() {
- writeln!(out, "k{i} [width=1, height=1]")?;
- }
- for edge in &diagram.edges {
- writeln!(out, "k{} -> k{}", edge.src, edge.dst)?;
- }
- writeln!(out, "}}")?;
-
- child.stdin.as_mut().unwrap().write_all(out.as_bytes())?;
- let output = child.wait_with_output()?;
-
- #[derive(Deserialize)]
- struct Out {
- objects: Vec<Object>,
- }
- #[derive(Deserialize)]
- struct Object {
- name: String,
- pos: String,
- }
- let graph: Out = serde_json::from_slice(&output.stdout)?;
- for o in graph.objects {
- let pos = o.pos.split_once(",").ok_or(anyhow!("malformed position"))?;
- let pos = Vec2::new(pos.0.parse()?, pos.1.parse()?);
-
- let index = o
- .name
- .strip_prefix("k")
- .ok_or(anyhow!("invalid node name"))?
- .parse::<usize>()?;
- diagram.nodes[index].position = pos
- }
-
- Ok(())
-}