Add base data structures for pool matches
Some checks failed
Build Crate / build (push) Failing after 4m29s
Some checks failed
Build Crate / build (push) Failing after 4m29s
This commit is contained in:
@@ -1,11 +1,56 @@
|
||||
use crate::data::user::PlayerId;
|
||||
use chrono::serde::ts_seconds;
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
pub struct PoolMatch {
|
||||
pub players: Vec<String>,
|
||||
pub winner: String,
|
||||
pub type MatchId = u32;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub enum MatchData {
|
||||
Standard8Ball {
|
||||
winner: PlayerId,
|
||||
loser: PlayerId,
|
||||
},
|
||||
Standard9Ball {
|
||||
winner: PlayerId,
|
||||
loser: PlayerId,
|
||||
},
|
||||
CutThroat {
|
||||
winner: PlayerId,
|
||||
losers: [PlayerId; 2],
|
||||
},
|
||||
}
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct PoolMatch {
|
||||
pub id: MatchId,
|
||||
pub data: MatchData,
|
||||
#[serde(with = "ts_seconds")]
|
||||
pub time: DateTime<Utc>,
|
||||
}
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct PoolMatchList {
|
||||
pub pool_matches: Vec<PoolMatch>,
|
||||
pub max_id: MatchId,
|
||||
}
|
||||
|
||||
impl PoolMatch {
|
||||
pub fn new(data: MatchData, time: DateTime<Utc>) -> PoolMatch {
|
||||
PoolMatch { id: 0, data, time }
|
||||
}
|
||||
}
|
||||
|
||||
impl PoolMatchList {
|
||||
pub fn new() -> PoolMatchList {
|
||||
PoolMatchList {
|
||||
pool_matches: vec![],
|
||||
max_id: 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_pool_match(&mut self, mut pool_match: PoolMatch) {
|
||||
pool_match.id = self.max_id + 1;
|
||||
self.max_id += 1;
|
||||
self.pool_matches.push(pool_match);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user