aboutsummaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
Diffstat (limited to 'server/src')
-rw-r--r--server/src/entity/tutorial.rs44
-rw-r--r--server/src/lib.rs29
2 files changed, 41 insertions, 32 deletions
diff --git a/server/src/entity/tutorial.rs b/server/src/entity/tutorial.rs
index 24c83550..fba43fd0 100644
--- a/server/src/entity/tutorial.rs
+++ b/server/src/entity/tutorial.rs
@@ -1,3 +1,5 @@
+use crate::trm;
+
use super::{Entity, EntityContext};
use anyhow::Result;
use hurrycurry_protocol::{
@@ -41,7 +43,7 @@ impl Entity for Tutorial {
if self.delete_timer <= 0. {
hint = None
} else {
- hint = Some((None, Message::Text("Tutorial finished.".to_string())));
+ hint = Some((None, trm!("s.tutorial.finished")));
}
}
@@ -122,23 +124,20 @@ impl<'a> StepContext<'a> {
return Ok(pos);
}
self.aquire_item(item)?;
- Err((None, Message::Text("put down this item".to_string())))
+ Err((None, trm!("s.tutorial.put_away")))
}
fn aquire_item(&mut self, item: ItemIndex) -> Result<(), (Option<IVec2>, Message)> {
debug!("aquire item {:?}", self.ent.game.data.item_names[item.0]);
self.recursion_abort += 1;
if self.recursion_abort > 32 {
warn!("too much recursion");
- return Err((
- None,
- Message::Text("server cant handle the recipe, too much recursion".to_string()),
- ));
+ return Err((None, trm!("s.tutorial.error")));
}
if self.is_hand_item(item) {
return Ok(());
}
if let Some(pos) = self.find_item_on_map(item) {
- return Err((Some(pos), Message::Text("pickup".to_string())));
+ return Err((Some(pos), trm!("s.tutorial.pickup")));
}
if let Some(recipe) = self.find_recipe_with_output(item) {
let r = &self.ent.game.data.recipes[recipe.0];
@@ -149,7 +148,7 @@ impl<'a> StepContext<'a> {
..
} => {
if let Some(pos) = self.find_tile(*tile) {
- return Err((Some(pos), Message::Text("take from crate".to_string())));
+ return Err((Some(pos), trm!("s.tutorial.take", i = item)));
}
}
Recipe::Instant {
@@ -159,7 +158,7 @@ impl<'a> StepContext<'a> {
} => {
let apos = self.aquire_placed_item(*a)?;
self.aquire_item(*b)?;
- return Err((Some(apos), Message::Text("interact here".to_string())));
+ return Err((Some(apos), trm!("s.tutorial.interact")));
}
Recipe::Instant {
tile: None,
@@ -167,7 +166,7 @@ impl<'a> StepContext<'a> {
..
} => {
self.aquire_item(*input)?;
- return Err((None, Message::Text("interact with empty tile".to_string())));
+ return Err((None, trm!("s.tutorial.interact_empty")));
}
Recipe::Active {
tile: Some(tile),
@@ -178,18 +177,13 @@ impl<'a> StepContext<'a> {
if let Some(pos) = self.find_tile(*tile) {
if let Some(item) = &self.ent.game.tiles.get(&pos).unwrap().item {
if item.kind == *input {
- return Err((
- Some(pos),
- Message::Text(format!("hold interact here")),
- ));
- } else {
- return Err((Some(pos), Message::Text(format!("clear tile"))));
+ return Err((Some(pos), trm!("s.tutorial.hold_interact")));
}
}
self.aquire_item(*input)?;
return Err((
Some(pos),
- Message::Text(format!("active here for {:.01}s", 1. / speed)),
+ trm!("s.tutorial.active", s = format!("{:.01}", 1. / speed)),
));
}
}
@@ -201,26 +195,18 @@ impl<'a> StepContext<'a> {
if let Some(pos) = self.find_tile(*tile) {
if let Some(item) = &self.ent.game.tiles.get(&pos).unwrap().item {
if item.kind == *input {
- return Err((Some(pos), Message::Text(format!("wait for finish"))));
- } else {
- return Err((Some(pos), Message::Text(format!("clear tile"))));
+ return Err((Some(pos), trm!("s.tutorial.wait_finish")));
}
}
self.aquire_item(*input)?;
- return Err((
- Some(pos),
- Message::Text(format!(
- "put on {}",
- self.ent.game.data.tile_name(*tile)
- )),
- ));
+ return Err((Some(pos), trm!("s.tutorial.put_on", t = *tile)));
}
}
Recipe::Passive {
tile: None, input, ..
} => {
self.aquire_item(*input)?;
- return Err((None, Message::Text(format!("wait for finish"))));
+ return Err((None, trm!("s.tutorial.wait_finish")));
}
_ => warn!("recipe too hard {r:?}"),
}
@@ -229,6 +215,6 @@ impl<'a> StepContext<'a> {
"stuck at making item {:?}",
self.ent.game.data.item_names[item.0]
);
- Err((None, Message::Text(format!("stuck"))))
+ Err((None, trm!("s.tutorial.error")))
}
}
diff --git a/server/src/lib.rs b/server/src/lib.rs
index 89822133..3969c67c 100644
--- a/server/src/lib.rs
+++ b/server/src/lib.rs
@@ -16,13 +16,13 @@
*/
#![feature(if_let_guard, map_many_mut, let_chains, iterator_try_collect, isqrt)]
+pub mod commands;
pub mod data;
pub mod entity;
-pub mod server;
pub mod interaction;
-pub mod state;
pub mod scoreboard;
-pub mod commands;
+pub mod server;
+pub mod state;
use hurrycurry_protocol::glam::Vec2;
@@ -43,3 +43,26 @@ impl InterpolateExt for f32 {
*self = target + (*self - target) * (-dt).exp();
}
}
+
+#[macro_export]
+macro_rules! trm {
+ ($id:literal $(, $typ:ident = $param:expr)*) => {
+ hurrycurry_protocol::Message::Translation {
+ id: $id.to_owned(),
+ params: vec![$(crate::trm_param!($typ, $param)),*]
+ }
+ };
+}
+
+#[macro_export]
+macro_rules! trm_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)
+ };
+}