aboutsummaryrefslogtreecommitdiff
path: root/server/src/entity/campaign.rs
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/entity/campaign.rs')
-rw-r--r--server/src/entity/campaign.rs28
1 files changed, 12 insertions, 16 deletions
diff --git a/server/src/entity/campaign.rs b/server/src/entity/campaign.rs
index 53ea6582..fdc169d1 100644
--- a/server/src/entity/campaign.rs
+++ b/server/src/entity/campaign.rs
@@ -18,16 +18,16 @@
use super::{Entity, EntityContext};
use crate::{scoreboard::ScoreboardStore, server::GameServerExt};
use anyhow::Result;
+use hurrycurry_data::entities::GateCondition;
use hurrycurry_locale::{trm, TrError};
use hurrycurry_protocol::{
glam::{IVec2, Vec2},
Message, PacketC, PlayerID, TileIndex,
};
-use serde::{Deserialize, Serialize};
#[derive(Debug, Default, Clone)]
pub struct Map {
- pub location: Vec2,
+ pub pos: Vec2,
pub name: String,
}
@@ -36,7 +36,7 @@ impl Entity for Map {
let mut activate = false;
c.game
.players_spatial_index
- .query(self.location, 0.5, |_, _| activate = true);
+ .query(self.pos, 0.5, |_, _| activate = true);
if activate {
*c.load_map = Some(self.name.clone());
@@ -46,19 +46,11 @@ impl Entity for Map {
}
}
-#[derive(Debug, Clone, Deserialize, Serialize)]
-#[serde(rename_all = "kebab-case")]
-pub enum GateCondition {
- All(Vec<GateCondition>),
- Any(Vec<GateCondition>),
- Stars(String, u8),
-}
-
#[derive(Debug, Clone)]
pub struct Gate {
pub active: bool,
pub unlocked: bool,
- pub location: IVec2,
+ pub pos: IVec2,
pub blocker_tile: TileIndex,
pub condition: GateCondition,
}
@@ -69,7 +61,7 @@ impl Entity for Gate {
self.unlocked = self.condition.check(c.scoreboard);
if !self.unlocked {
c.game
- .set_tile(self.location, Some(self.blocker_tile), c.packet_out);
+ .set_tile(self.pos, Some(self.blocker_tile), c.packet_out);
c.packet_out.push_back(PacketC::FlushMap); // TODO dont send too often
}
}
@@ -81,7 +73,7 @@ impl Entity for Gate {
pos: Option<IVec2>,
_player: PlayerID,
) -> Result<bool, TrError> {
- if !self.unlocked && pos == Some(self.location) {
+ if !self.unlocked && pos == Some(self.pos) {
c.packet_out.push_back(PacketC::ServerMessage {
message: trm!(
"s.campaign.unlock_condition",
@@ -95,7 +87,11 @@ impl Entity for Gate {
}
}
-impl GateCondition {
+trait GateConditionExt {
+ fn check(&self, scoreboard: &ScoreboardStore) -> bool;
+ fn show(&self, scoreboard: &ScoreboardStore) -> Message;
+}
+impl GateConditionExt for GateCondition {
fn check(&self, scoreboard: &ScoreboardStore) -> bool {
match self {
GateCondition::All(cs) => cs.iter().all(|c| c.check(scoreboard)),
@@ -105,7 +101,7 @@ impl GateCondition {
.is_some_and(|s| s.best.first().is_some_and(|b| b.score.stars >= *thres)),
}
}
- pub fn show(&self, scoreboard: &ScoreboardStore) -> Message {
+ fn show(&self, scoreboard: &ScoreboardStore) -> Message {
match self {
GateCondition::All(cs) => cs
.iter()