use crate::statistics::Marks; use serde::Deserialize; /// One Arena variant, derived from the game queue. #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum Format { Arena3x6, BraveryArena, Arena16, Other(u32), } impl Format { /// `None` for queues that are not real Matches (1704 is the PBE test queue). pub fn from_queue(queue_id: u32) -> Option { match queue_id { 1750 => Some(Format::Arena3x6), 1740 => Some(Format::BraveryArena), 1700 | 1710 => Some(Format::Arena16), 1704 => None, other => Some(Format::Other(other)), } } pub fn name(&self) -> String { match self { Format::Arena3x6 => "Arena 3x6".into(), Format::BraveryArena => "Bravery Arena".into(), Format::Arena16 => "Arena 16 joueurs".into(), Format::Other(queue) => format!("Arena (file {queue})"), } } } #[derive(Clone, Debug, PartialEq, Eq, Deserialize)] #[serde(rename_all = "camelCase")] pub struct Account { pub puuid: String, pub game_name: String, pub tag_line: String, } /// A stored Match as the user sees it. #[derive(Clone, Debug, PartialEq)] pub struct Match { pub match_id: String, pub format: Format, pub champion_id: u32, pub champion_name: String, pub placement: u8, pub win: bool, pub started_at_ms: i64, } /// What a followed Match brought its champion's Challenge, from the weakest to the strongest: /// the animation it plays on « Défi » is in proportion. #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)] pub enum MatchEnd { /// Nothing new: the tick blinks. Nothing, /// A new Mark, « Joué » or « Victoire »: the tick steps up. Mark, /// The champion's first top 1, it is Completed: the comet. Completed, } impl MatchEnd { /// The strongest change from the champion's Marks without the Match to those with it. pub fn between(without: Marks, with: Marks) -> MatchEnd { if with.completed && !without.completed { MatchEnd::Completed } else if with != without { MatchEnd::Mark } else { MatchEnd::Nothing } } } /// A Match the live follow saw end and stored, with what it brought its champion's Challenge /// in its Season. A Match stored by a sync of the history is never one. #[derive(Clone, Debug, Eq, PartialEq)] pub struct FollowedMatch { pub puuid: String, pub season: String, pub champion_id: u32, pub started_at_ms: i64, pub end: MatchEnd, } #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct SyncProgress { pub fetched: usize, pub to_fetch: usize, } #[derive(Clone, Debug)] pub struct SyncReport { pub account: Account, /// Matches newly stored by this sync. pub added: usize, /// All Matches stored for the Account once the sync is done. pub stored: usize, } #[cfg(test)] mod tests { use super::*; #[test] fn queues_map_to_formats() { assert_eq!(Format::from_queue(1750), Some(Format::Arena3x6)); assert_eq!(Format::from_queue(1740), Some(Format::BraveryArena)); assert_eq!(Format::from_queue(1700), Some(Format::Arena16)); assert_eq!(Format::from_queue(1710), Some(Format::Arena16)); assert_eq!(Format::from_queue(1704), None); assert_eq!(Format::from_queue(1800), Some(Format::Other(1800))); } #[test] fn formats_have_french_facing_names() { assert_eq!(Format::Arena3x6.name(), "Arena 3x6"); assert_eq!(Format::BraveryArena.name(), "Bravery Arena"); assert_eq!(Format::Arena16.name(), "Arena 16 joueurs"); assert_eq!(Format::Other(1800).name(), "Arena (file 1800)"); } }