aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock18
-rw-r--r--Cargo.toml3
-rw-r--r--server/book-export/Cargo.toml15
-rw-r--r--server/book-export/src/book_html.css (renamed from server/tools/src/book_html.css)0
-rw-r--r--server/book-export/src/book_html.rs (renamed from server/tools/src/book_html.rs)0
-rw-r--r--server/book-export/src/diagram_svg.rs (renamed from server/tools/src/diagram_svg.rs)0
-rw-r--r--server/book-export/src/main.rs60
-rw-r--r--server/data/src/book/mod.rs6
-rw-r--r--server/locale-export/Cargo.toml (renamed from locale/tools/Cargo.toml)0
-rw-r--r--server/locale-export/src/main.rs (renamed from locale/tools/src/main.rs)11
-rw-r--r--server/tools/Cargo.toml3
-rw-r--r--server/tools/src/diagram_dot.rs11
-rw-r--r--server/tools/src/main.rs33
13 files changed, 109 insertions, 51 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 50cf378b..4e50c07b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -969,6 +969,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9"
[[package]]
+name = "hurrycurry-book-export"
+version = "0.1.0"
+dependencies = [
+ "anyhow",
+ "clap",
+ "env_logger",
+ "hurrycurry-data",
+ "hurrycurry-locale",
+ "hurrycurry-protocol",
+ "log",
+ "markup",
+ "serde_json",
+]
+
+[[package]]
name = "hurrycurry-bot"
version = "2.3.5"
dependencies = [
@@ -1140,10 +1155,7 @@ dependencies = [
"hurrycurry-data",
"hurrycurry-locale",
"hurrycurry-protocol",
- "hurrycurry-server",
"log",
- "markup",
- "serde",
"serde_json",
]
diff --git a/Cargo.toml b/Cargo.toml
index 7c4252db..f3221e74 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -10,6 +10,7 @@ members = [
"server/data",
"server/editor",
"server/tools",
- "locale/tools",
+ "server/locale-export",
+ "server/book-export",
]
resolver = "2"
diff --git a/server/book-export/Cargo.toml b/server/book-export/Cargo.toml
new file mode 100644
index 00000000..d106dab8
--- /dev/null
+++ b/server/book-export/Cargo.toml
@@ -0,0 +1,15 @@
+[package]
+name = "hurrycurry-book-export"
+version = "0.1.0"
+edition = "2024"
+
+[dependencies]
+anyhow = "1.0.100"
+log = "0.4.28"
+env_logger = "0.11.8"
+clap = { version = "4.5.47", features = ["derive"] }
+hurrycurry-protocol = { path = "../protocol" }
+hurrycurry-locale = { path = "../locale" }
+hurrycurry-data = { path = "../data" }
+serde_json = "1.0.145"
+markup = "0.15.0"
diff --git a/server/tools/src/book_html.css b/server/book-export/src/book_html.css
index 9171aa5e..9171aa5e 100644
--- a/server/tools/src/book_html.css
+++ b/server/book-export/src/book_html.css
diff --git a/server/tools/src/book_html.rs b/server/book-export/src/book_html.rs
index 08a12e88..08a12e88 100644
--- a/server/tools/src/book_html.rs
+++ b/server/book-export/src/book_html.rs
diff --git a/server/tools/src/diagram_svg.rs b/server/book-export/src/diagram_svg.rs
index d006ce78..d006ce78 100644
--- a/server/tools/src/diagram_svg.rs
+++ b/server/book-export/src/diagram_svg.rs
diff --git a/server/book-export/src/main.rs b/server/book-export/src/main.rs
new file mode 100644
index 00000000..b57aa04f
--- /dev/null
+++ b/server/book-export/src/main.rs
@@ -0,0 +1,60 @@
+/*
+ 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/>.
+
+*/
+pub mod book_html;
+pub mod diagram_svg;
+
+use crate::book_html::render_html_book;
+use anyhow::Result;
+use clap::{Parser, ValueEnum};
+use hurrycurry_data::{book::book, index::DataIndex};
+use hurrycurry_locale::FALLBACK_LOCALE;
+
+#[derive(Parser)]
+struct Args {
+ #[arg(short, long)]
+ format: ExportFormat,
+ #[arg(short, long, default_value = "5star")]
+ map: String,
+}
+
+#[derive(ValueEnum, Clone, Copy)]
+enum ExportFormat {
+ Json,
+ Html,
+}
+
+fn main() -> Result<()> {
+ env_logger::init_from_env("LOG");
+ let args = Args::parse();
+
+ let mut index = DataIndex::default();
+ index.reload()?;
+ let (data, serverdata) = index.generate(&args.map)?;
+
+ let book = book(&data, &serverdata)?;
+
+ match args.format {
+ ExportFormat::Json => {
+ println!("{}", serde_json::to_string(&book).unwrap())
+ }
+ ExportFormat::Html => {
+ println!("{}", render_html_book(&data, &book, &FALLBACK_LOCALE));
+ }
+ }
+ Ok(())
+}
diff --git a/server/data/src/book/mod.rs b/server/data/src/book/mod.rs
index f9b54d0d..263e8111 100644
--- a/server/data/src/book/mod.rs
+++ b/server/data/src/book/mod.rs
@@ -63,9 +63,3 @@ pub fn book(data: &Gamedata, serverdata: &Serverdata) -> Result<Book> {
}
Ok(Book { pages })
}
-
-pub fn print_book(data: &Gamedata, serverdata: &Serverdata) -> Result<()> {
- let book = book(data, serverdata)?;
- println!("{}", serde_json::to_string_pretty(&book).unwrap());
- Ok(())
-}
diff --git a/locale/tools/Cargo.toml b/server/locale-export/Cargo.toml
index 89543937..89543937 100644
--- a/locale/tools/Cargo.toml
+++ b/server/locale-export/Cargo.toml
diff --git a/locale/tools/src/main.rs b/server/locale-export/src/main.rs
index 2f8c9718..23823716 100644
--- a/locale/tools/src/main.rs
+++ b/server/locale-export/src/main.rs
@@ -1,4 +1,3 @@
-#![feature(iterator_try_collect)]
use anyhow::{anyhow, Context, Result};
use clap::Parser;
use std::{
@@ -142,7 +141,7 @@ msgstr ""
})
.transpose()
})
- .try_collect::<BTreeMap<_, _>>()?;
+ .collect::<Result<BTreeMap<_, _>>>()?;
let langs = translations.keys().cloned().collect::<Vec<String>>();
let mut tr_tr = BTreeMap::<String, BTreeMap<String, String>>::new();
@@ -161,7 +160,7 @@ msgstr ""
"{k},{}",
v.values()
.map(serde_json::to_string)
- .try_collect::<Vec<_>>()?
+ .collect::<Result<Vec<_>, serde_json::Error>>()?
.join(",")
)?;
Ok::<_, anyhow::Error>(a)
@@ -186,7 +185,7 @@ msgstr ""
.map(|(k, v)| (v, k))
.ok_or(anyhow!("invalid ini"))
})
- .try_collect::<BTreeMap<&str, &str>>()?;
+ .collect::<Result<BTreeMap<&str, &str>>>()?;
let mut outmap = BTreeMap::new();
let mut mode = 0;
@@ -253,7 +252,7 @@ msgstr ""
.map(|(k, v)| (v.to_owned(), k.to_owned()))
.ok_or(anyhow!("invalid ini"))
})
- .try_collect::<BTreeMap<String, String>>()?;
+ .collect::<Result<BTreeMap<String, String>>>()?;
let mut id = false;
let mut msgid = String::new();
@@ -310,5 +309,5 @@ fn load_ini(path: &Path) -> Result<BTreeMap<String, String>> {
let (k, v) = l.split_once("=").ok_or(anyhow!("'=' missing"))?;
Ok::<_, anyhow::Error>((k.trim_end().to_owned(), v.trim_start().replace("%n", "\n")))
})
- .try_collect()
+ .collect()
}
diff --git a/server/tools/Cargo.toml b/server/tools/Cargo.toml
index 1c427c81..ffffa426 100644
--- a/server/tools/Cargo.toml
+++ b/server/tools/Cargo.toml
@@ -9,9 +9,6 @@ log = "0.4.28"
env_logger = "0.11.8"
clap = { version = "4.5.47", features = ["derive"] }
hurrycurry-protocol = { path = "../protocol" }
-hurrycurry-server = { path = ".." }
hurrycurry-locale = { path = "../locale" }
hurrycurry-data = { path = "../data" }
serde_json = "1.0.145"
-serde = { version = "1.0.225", features = ["derive"] }
-markup = "0.15.0"
diff --git a/server/tools/src/diagram_dot.rs b/server/tools/src/diagram_dot.rs
index fb223dbf..1701f4ab 100644
--- a/server/tools/src/diagram_dot.rs
+++ b/server/tools/src/diagram_dot.rs
@@ -16,7 +16,6 @@
*/
-use crate::diagram_svg::node_color;
use anyhow::{Result, bail};
use hurrycurry_protocol::{
Gamedata, Message,
@@ -91,6 +90,16 @@ pub fn diagram_dot(data: &Gamedata, diagram: &Diagram, use_position: bool) -> Re
Ok(out)
}
+fn node_color(node: &DiagramNode) -> &'static str {
+ match node.style {
+ NodeStyle::FinalProduct => "#555",
+ NodeStyle::IntermediateProduct => "#333",
+ NodeStyle::ProcessActive => "#47c42b",
+ NodeStyle::ProcessPassive => "#c4a32b",
+ NodeStyle::ProcessInstant => "#5452d8",
+ }
+}
+
fn node_style(attrs: &mut Vec<String>, node: &DiagramNode) {
let shape = match node.style {
NodeStyle::FinalProduct => "circle",
diff --git a/server/tools/src/main.rs b/server/tools/src/main.rs
index 8d8e4fd0..07c5d45b 100644
--- a/server/tools/src/main.rs
+++ b/server/tools/src/main.rs
@@ -16,17 +16,13 @@
*/
-pub mod book_html;
pub mod diagram_dot;
-pub mod diagram_svg;
pub mod graph;
pub mod graph_summary;
pub mod map_linter;
use crate::{
- book_html::render_html_book,
diagram_dot::{diagram_dot, diagram_dot_svg},
- diagram_svg::diagram_svg,
graph::graph,
graph_summary::graph_summary,
map_linter::check_map,
@@ -34,10 +30,9 @@ use crate::{
use anyhow::Result;
use clap::Parser;
use hurrycurry_data::{
- book::{book, diagram_layout::diagram_layout, print_book, recipe_diagram::recipe_diagram},
+ book::{diagram_layout::diagram_layout, recipe_diagram::recipe_diagram},
index::DataIndex,
};
-use hurrycurry_locale::FALLBACK_LOCALE;
#[derive(Parser)]
enum Action {
@@ -46,12 +41,8 @@ enum Action {
GraphSingle {
out: String,
#[arg(short)]
- custom_svg: bool,
- #[arg(short)]
dot_out: bool,
},
- Book,
- BookHtml,
MapDemands {
map: String,
},
@@ -73,11 +64,7 @@ fn main() -> Result<()> {
match action {
Action::Graph => graph()?,
Action::GraphSummary => graph_summary()?,
- Action::GraphSingle {
- out,
- custom_svg,
- dot_out,
- } => {
+ Action::GraphSingle { out, dot_out } => {
let mut index = DataIndex::default();
index.reload()?;
let (data, serverdata) = index.generate("5star")?;
@@ -85,28 +72,12 @@ fn main() -> Result<()> {
let mut diagram = recipe_diagram(&data, &serverdata, &[out])?;
let out = if dot_out {
diagram_dot(&data, &diagram, false)?
- } else if custom_svg {
- diagram_layout(&mut diagram)?;
- diagram_svg(&data, &diagram)?
} else {
diagram_layout(&mut diagram)?;
diagram_dot_svg(&data, &diagram)?
};
println!("{out}");
}
- Action::Book => {
- let mut index = DataIndex::default();
- index.reload()?;
- let (data, serverdata) = index.generate("5star")?;
- print_book(&data, &serverdata)?
- }
- Action::BookHtml => {
- let mut index = DataIndex::default();
- index.reload()?;
- let (data, serverdata) = index.generate("5star")?;
- let book = book(&data, &serverdata)?;
- println!("{}", render_html_book(&data, &book, &FALLBACK_LOCALE));
- }
Action::MapDemands { map } => {
let mut index = DataIndex::default();
index.reload()?;