aboutsummaryrefslogtreecommitdiff
path: root/server/src/entity/campaign.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-09-20 01:30:36 +0200
committermetamuffin <metamuffin@disroot.org>2024-09-20 01:30:47 +0200
commit02a843b40f4ddba14bb12d0f17454ee96de350a5 (patch)
treec771684285d93e4169799255b626063daf791e7a /server/src/entity/campaign.rs
parentcbe437809df14c30be2e282505adb562589df65a (diff)
downloadhurrycurry-02a843b40f4ddba14bb12d0f17454ee96de350a5.tar
hurrycurry-02a843b40f4ddba14bb12d0f17454ee96de350a5.tar.bz2
hurrycurry-02a843b40f4ddba14bb12d0f17454ee96de350a5.tar.zst
translate campaign conditions
Diffstat (limited to 'server/src/entity/campaign.rs')
-rw-r--r--server/src/entity/campaign.rs45
1 files changed, 18 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()
+ )
}
}
}