diff options
Diffstat (limited to 'server/protocol/src/lib.rs')
-rw-r--r-- | server/protocol/src/lib.rs | 84 |
1 files changed, 16 insertions, 68 deletions
diff --git a/server/protocol/src/lib.rs b/server/protocol/src/lib.rs index 3b87c7b8..146a5a92 100644 --- a/server/protocol/src/lib.rs +++ b/server/protocol/src/lib.rs @@ -25,6 +25,9 @@ use std::{collections::HashSet, sync::LazyLock}; pub use glam; +use crate::book::Book; + +pub mod book; pub mod helpers; pub mod movement; pub mod registry; @@ -320,8 +323,9 @@ pub enum PacketC { #[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode)] #[serde(rename_all = "snake_case", tag = "menu", content = "data")] pub enum Menu { - Document(DocumentElement), Score(Score), + Scoreboard(Scoreboard), + Book(Book), AnnounceStart, } @@ -345,6 +349,17 @@ pub struct Score { pub instant_recipes: usize, } +#[derive(Debug, Serialize, Deserialize, Encode, Decode, Clone, Default)] +pub struct Scoreboard { + pub plays: usize, + pub best: Vec<ScoreboardEntry>, +} +#[derive(Debug, Serialize, Deserialize, Encode, Decode, Clone)] +pub struct ScoreboardEntry { + pub players: Vec<String>, + pub score: Score, +} + #[derive(Debug, Clone, Serialize, Encode, Decode, Deserialize)] #[serde(rename_all = "snake_case")] pub enum Recipe { @@ -377,73 +392,6 @@ pub enum ItemLocation { Player(PlayerID, Hand), } -#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode)] -#[serde(rename_all = "snake_case", tag = "t")] -pub enum DocumentElement { - Document { - es: Vec<DocumentElement>, - }, - /// One page of the document, √2:1 aspect ratio - Page { - /// Name of background image - background: Option<String>, - es: Vec<DocumentElement>, - }, - /// Implicit element layouting - Container { - es: Vec<DocumentElement>, - }, - List { - /// Should only contain par or text elements - es: Vec<DocumentElement>, - }, - /// Table with elements arranged as row arrays - Table { - es: Vec<Vec<DocumentElement>>, - }, - /// A paragraph. - Par { - /// Should only contain text elements - es: Vec<DocumentElement>, - }, - /// A text span - Text { - s: Message, - size: f32, - color: Option<String>, - font: Option<String>, - #[serde(default)] - bold: bool, - }, - /// Document part that is only shown conditionally. Used for image attribution - Conditional { - cond: String, - value: bool, - e: Box<DocumentElement>, - }, - /// Makes the child element clickable that jumps to the label with the same id - Ref { - id: String, - e: Box<DocumentElement>, - }, - /// Declares a label - Label { - id: String, - e: Box<DocumentElement>, - }, - Align { - dir: DocumentAlign, - e: Box<DocumentElement>, - }, -} - -#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode)] -#[serde(rename_all = "snake_case")] -pub enum DocumentAlign { - FlowEnd, - Bottom, -} - fn deser_i64<'de, D: Deserializer<'de>>(deserializer: D) -> Result<i64, D::Error> { let x = f64::deserialize(deserializer)?; Ok(x.trunc() as i64) |