aboutsummaryrefslogtreecommitdiff
path: root/src/_match.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/_match.rs')
-rw-r--r--src/_match.rs52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/_match.rs b/src/_match.rs
new file mode 100644
index 000000000000..23d3be8aeb0d
--- /dev/null
+++ b/src/_match.rs
@@ -0,0 +1,52 @@
+use crate::{
+ data::Player,
+ lobby::MetaLobby,
+ map::Map,
+ wire::{LobbyUser, MatchId, UserId},
+};
+use async_std::sync::Arc;
+use chrono::{DateTime, Utc};
+use serde::{Deserialize, Serialize};
+
+/// Describes a match for the server
+pub struct Match {
+ /// The match id
+ pub id: MatchId,
+ /// The list of active players
+ pub players: Vec<Player>,
+ /// The active game map
+ pub map: Map,
+ /// The time the match was initialised
+ pub init_t: DateTime<Utc>,
+ /// The synced time the match was started
+ pub start_t: Option<DateTime<Utc>>,
+}
+
+impl From<MetaLobby> for Match {
+ fn from(ml: MetaLobby) -> Self {
+ Self {
+ id: ml.inner.id,
+ players: ml
+ .inner
+ .players
+ .into_iter()
+ .map(|lu| Player {
+ id: lu.id,
+ name: lu.name,
+ color: lu.color,
+ money: 0.into(),
+ })
+ .collect(),
+ map: Map::new(),
+ init_t: Utc::now(),
+ start_t: None,
+ }
+ }
+}
+
+impl Match {
+ /// Set the start time of the match, which may be in the future
+ pub fn set_start(&mut self, t: DateTime<Utc>) {
+ self.start_t = Some(t);
+ }
+}