diff options
Diffstat (limited to 'server/src/lib.rs')
-rw-r--r-- | server/src/lib.rs | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/server/src/lib.rs b/server/src/lib.rs index 3969c67c..306ebd40 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -24,7 +24,7 @@ pub mod scoreboard; pub mod server; pub mod state; -use hurrycurry_protocol::glam::Vec2; +use hurrycurry_protocol::{glam::Vec2, Message}; #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct ConnectionID(pub i64); @@ -66,3 +66,40 @@ macro_rules! trm_param { hurrycurry_protocol::Message::Tile($x) }; } + +#[derive(Debug)] +pub struct TrError { + pub id: &'static str, + pub params: Vec<Message>, +} +impl From<TrError> for Message { + fn from(value: TrError) -> Self { + Self::Translation { + id: value.id.to_owned(), + params: value.params, + } + } +} + +#[macro_export] +macro_rules! tre { + ($id:literal $(, $typ:ident = $param:expr)*) => { + crate::TrError { + id: $id, + params: vec![$(crate::tre_param!($typ, $param)),*] + } + }; +} + +#[macro_export] +macro_rules! tre_param { + (s, $x:expr) => { + hurrycurry_protocol::Message::Text($x) + }; + (i, $x:expr) => { + hurrycurry_protocol::Message::Item($x) + }; + (t, $x:expr) => { + hurrycurry_protocol::Message::Tile($x) + }; +} |