diff options
author | Katharina Fey <kookie@spacekookie.de> | 2021-01-29 11:25:05 +0100 |
---|---|---|
committer | Katharina Fey <kookie@spacekookie.de> | 2021-01-29 11:25:05 +0100 |
commit | 31ec889558d6a32d4861d7d14eff1f559e7ca72c (patch) | |
tree | c9bb875698d6ee3544eef864ddec2c9db561707f /games/rstnode/src/_match.rs | |
parent | 9765d1e42dc9d1d3a90f54d87cebdd7ab4549417 (diff) | |
parent | 78d813b2a119b314349555387669f9c33727c5b1 (diff) |
Add 'games/rstnode/' from commit '78d813b2a119b314349555387669f9c33727c5b1'
git-subtree-dir: games/rstnode
git-subtree-mainline: 9765d1e42dc9d1d3a90f54d87cebdd7ab4549417
git-subtree-split: 78d813b2a119b314349555387669f9c33727c5b1
Diffstat (limited to 'games/rstnode/src/_match.rs')
-rw-r--r-- | games/rstnode/src/_match.rs | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/games/rstnode/src/_match.rs b/games/rstnode/src/_match.rs new file mode 100644 index 000000000000..53f4d2604fe4 --- /dev/null +++ b/games/rstnode/src/_match.rs @@ -0,0 +1,67 @@ +use crate::{ + data::Player, + lobby::MetaLobby, + map::Map, + wire::{Action, LobbyUser, MatchId, UserId}, +}; +use async_std::sync::{Arc, RwLock}; +use chrono::{DateTime, Utc}; +use serde::{Deserialize, Serialize}; +use std::collections::VecDeque; + +/// 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, + /// Input inbox, + inbox: RwLock<VecDeque<Action>>, + /// The time the match was initialised + init_t: DateTime<Utc>, + /// The synced time the match was started + 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(), + inbox: Default::default(), + 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); + } + + /// Queue a new game action + pub async fn queue(&self, cmd: Action) { + self.inbox.write().await.push_back(cmd); + } + + pub async fn handle_inbex(&mut self) { + for act in self.inbox.write().await.drain() { + + } + } +} |