aboutsummaryrefslogtreecommitdiff
path: root/server/protocol/src/book.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-09-19 22:27:46 +0200
committermetamuffin <metamuffin@disroot.org>2025-09-19 22:40:39 +0200
commit402067b8317195fd2bc4ab4d92b5ace94fadb7c0 (patch)
tree2437c52ae71a11c4d17a6fa4597f8152dae96ddc /server/protocol/src/book.rs
parent2f311fec691cd7a62fa4f95ee0419089913b5dd8 (diff)
downloadhurrycurry-402067b8317195fd2bc4ab4d92b5ace94fadb7c0.tar
hurrycurry-402067b8317195fd2bc4ab4d92b5ace94fadb7c0.tar.bz2
hurrycurry-402067b8317195fd2bc4ab4d92b5ace94fadb7c0.tar.zst
Refactor book part 1
Diffstat (limited to 'server/protocol/src/book.rs')
-rw-r--r--server/protocol/src/book.rs70
1 files changed, 70 insertions, 0 deletions
diff --git a/server/protocol/src/book.rs b/server/protocol/src/book.rs
new file mode 100644
index 00000000..5bcd0a22
--- /dev/null
+++ b/server/protocol/src/book.rs
@@ -0,0 +1,70 @@
+/*
+ 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 crate::Message;
+use bincode::{Decode, Encode};
+use glam::Vec2;
+use serde::{Deserialize, Serialize};
+
+#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode)]
+pub struct Book {
+ pub pages: Vec<BookPage>,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode)]
+#[serde(rename_all = "snake_case", tag = "page_type")]
+pub enum BookPage {
+ Cover,
+ Contents {
+ table: Vec<(Message, usize)>,
+ },
+ Text {
+ paragraphs: Vec<Message>,
+ },
+ Recipe {
+ description: Message,
+ instruction: Message,
+ diagram: Diagram,
+ },
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode, Default)]
+pub struct Diagram {
+ pub nodes: Vec<DiagramNode>,
+ pub edges: Vec<DiagramEdge>,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode)]
+pub struct DiagramNode {
+ #[bincode(with_serde)]
+ pub position: Vec2,
+ pub label: Message,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode)]
+pub struct DiagramEdge {
+ pub src: usize,
+ pub dst: usize,
+ pub label: Option<Message>,
+}
+
+impl Default for Book {
+ fn default() -> Self {
+ Book { pages: vec![] }
+ }
+}