diff options
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/entity/campaign.rs | 45 | ||||
-rw-r--r-- | server/src/lib.rs | 2 |
2 files changed, 20 insertions, 27 deletions
diff --git a/server/src/entity/campaign.rs b/server/src/entity/campaign.rs index 2e45e650..8edebd41 100644 --- a/server/src/entity/campaign.rs +++ b/server/src/entity/campaign.rs @@ -20,10 +20,9 @@ use crate::{scoreboard::ScoreboardStore, server::GameServerExt, trm, TrError}; use anyhow::Result; use hurrycurry_protocol::{ glam::{IVec2, Vec2}, - PacketC, PlayerID, TileIndex, + Message, PacketC, PlayerID, TileIndex, }; use serde::{Deserialize, Serialize}; -use std::fmt::Write; #[derive(Debug, Default, Clone)] pub struct Map { @@ -84,7 +83,7 @@ impl Entity for Gate { c.packet_out.push_back(PacketC::ServerMessage { message: trm!( "s.campaign.unlock_condition", - s = self.condition.show(c.scoreboard) // TODO localize + m = self.condition.show(c.scoreboard) // TODO localize ), error: false, }); @@ -104,32 +103,24 @@ impl GateCondition { }), } } - pub fn show(&self, scoreboard: &ScoreboardStore) -> String { + pub fn show(&self, scoreboard: &ScoreboardStore) -> Message { match self { - GateCondition::All(cs) => { - let mut o = String::new(); - for c in cs { - if !c.check(scoreboard) { - writeln!(o, "- {}", c.show(scoreboard)).unwrap(); - } - } - o - } - GateCondition::Any(cs) => { - let mut o = String::new(); - for c in cs { - writeln!(o, "- {}", c.show(scoreboard)).unwrap(); - } - o - } + GateCondition::All(cs) => cs + .iter() + .map(|c| c.show(scoreboard)) + .reduce(|a, b| trm!("s.campaign.list_helper", m = a, m = b)) + .unwrap_or(Message::Text(String::new())), + GateCondition::Any(cs) => cs + .iter() + .map(|c| c.show(scoreboard)) + .reduce(|a, b| trm!("s.campaign.list_helper", m = a, m = b)) + .unwrap_or(Message::Text(String::new())), GateCondition::Stars(map, thres) => { - // TODO what if the language wants map first? - // trm!( - // "s.campaign.condition.stars", - // s = thres.to_string(), - // s = map.to_string() - // ) - format!("Reach at least {thres} stars in {map}") + trm!( + "s.campaign.condition.stars", + s = thres.to_string(), + s = map.to_string() + ) } } } diff --git a/server/src/lib.rs b/server/src/lib.rs index 112f28ea..c35a2b5a 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -72,6 +72,7 @@ macro_rules! trm_param { (t, $x:expr) => { hurrycurry_protocol::Message::Tile($x) }; + (m, $x:expr) => { $x }; } #[derive(Debug)] @@ -109,4 +110,5 @@ macro_rules! tre_param { (t, $x:expr) => { hurrycurry_protocol::Message::Tile($x) }; + (m, $x:expr) => { $x }; } |