diff options
author | metamuffin <metamuffin@disroot.org> | 2024-10-14 22:48:42 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-10-14 22:48:42 +0200 |
commit | fe23eeba70fce16764c8f2deb6d628487c2da131 (patch) | |
tree | 92b0b54eb50914bf8d6e0427879099e36894411c | |
parent | 188c76572d8606cefd394945bbce789d55797ec6 (diff) | |
download | hurrycurry-fe23eeba70fce16764c8f2deb6d628487c2da131.tar hurrycurry-fe23eeba70fce16764c8f2deb6d628487c2da131.tar.bz2 hurrycurry-fe23eeba70fce16764c8f2deb6d628487c2da131.tar.zst |
send /top as document, add docstrings to doc structs
-rw-r--r-- | server/protocol/Cargo.toml | 2 | ||||
-rw-r--r-- | server/protocol/src/lib.rs | 11 | ||||
-rw-r--r-- | server/src/commands.rs | 78 |
3 files changed, 73 insertions, 18 deletions
diff --git a/server/protocol/Cargo.toml b/server/protocol/Cargo.toml index a9210d33..f600fa8a 100644 --- a/server/protocol/Cargo.toml +++ b/server/protocol/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hurrycurry-protocol" -version = "7.3.0" +version = "7.4.0" edition = "2021" [dependencies] diff --git a/server/protocol/src/lib.rs b/server/protocol/src/lib.rs index 3337db0a..dd773a3d 100644 --- a/server/protocol/src/lib.rs +++ b/server/protocol/src/lib.rs @@ -353,24 +353,31 @@ 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>, }, 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, - color: String, size: f32, - font: String, + color: Option<String>, + font: Option<String>, #[serde(default)] bold: bool, }, diff --git a/server/src/commands.rs b/server/src/commands.rs index 25b51bff..08b521ad 100644 --- a/server/src/commands.rs +++ b/server/src/commands.rs @@ -24,7 +24,7 @@ use crate::{ use anyhow::Result; use clap::{Parser, ValueEnum}; use hurrycurry_bot::algos::ALGO_CONSTRUCTORS; -use hurrycurry_protocol::{Menu, Message, PacketC, PlayerClass, PlayerID}; +use hurrycurry_protocol::{DocumentElement, Menu, Message, PacketC, PlayerClass, PlayerID}; use std::{fmt::Write, time::Duration}; #[derive(Parser)] @@ -43,6 +43,9 @@ enum Command { Top { /// Name of the map, default: current map: Option<String>, + /// Send text instead of document + #[arg(short, long)] + text: bool, }, #[clap(alias = "mapinfo")] Info { @@ -245,23 +248,68 @@ impl Server { algo, ))); } - Command::Top { map } => { + Command::Top { map, text } => { let mapname = map.as_ref().unwrap_or(&self.game.data.current_map); + if let Some(board) = self.scoreboard.get(mapname) { - let mut o = format!("Scoreboard for {}:\n", mapname); - for (i, entry) in board.best.iter().take(5).enumerate() { - writeln!( - o, - " {i}. {} points by {}", - entry.score.points, - entry.players.clone().join(", ") - ) - .unwrap(); + if text { + let mut o = format!("Scoreboard for {}:\n", mapname); + for (i, entry) in board.best.iter().take(5).enumerate() { + writeln!( + o, + " {i}. {} points by {}", + entry.score.points, + entry.players.clone().join(", ") + ) + .unwrap(); + } + replies.push(PacketC::ServerMessage { + message: Message::Text(o), + error: false, + }); + } else { + replies.push(PacketC::Menu(Menu::Document(DocumentElement::Document { + es: vec![DocumentElement::Page { + es: vec![ + DocumentElement::Par { + es: vec![DocumentElement::Text { + s: Message::Translation { + id: "c.menu.scoreboard".to_string(), + params: vec![], + }, + size: 30., + bold: false, + color: None, + font: None, + }], + }, + DocumentElement::List { + es: board + .best + .iter() + .take(5) + .enumerate() + .map(|(place, entry)| DocumentElement::Par { + es: vec![DocumentElement::Text { + s: trm!( + "c.menu.scoreboard.entry", + s = place.to_string(), + s = entry.score.points.to_string(), + s = entry.players.clone().join(", ") + ), + size: 15., + bold: false, + color: None, + font: None, + }], + }) + .collect(), + }, + ], + background: None, + }], + }))); } - replies.push(PacketC::ServerMessage { - message: Message::Text(o), - error: false, - }); } } Command::Info { map } => { |