diff options
author | Daniel Schadt <kingdread@gmx.de> | 2021-11-17 20:07:18 +0100 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2021-11-17 20:07:18 +0100 |
commit | 70750b3c10aa05e8fe922b5d70e9cfe61253c72a (patch) | |
tree | 455dfb7be43e3f6724f52d4974eb4769ff9e8c40 | |
parent | b962896e0d31667162b0a844e3f2186707b641ad (diff) | |
download | evtclib-70750b3c10aa05e8fe922b5d70e9cfe61253c72a.tar.gz evtclib-70750b3c10aa05e8fe922b5d70e9cfe61253c72a.tar.bz2 evtclib-70750b3c10aa05e8fe922b5d70e9cfe61253c72a.zip |
Move game_mode to Encounter
If we already have an Encounter, it might be nice to determine the game
mode from it as well - without needing to go through the whole log
first.
This is especially useful for raidgrep, where we can use the early
filters - which don't have access to the whole Log item.
-rw-r--r-- | CHANGELOG.md | 3 | ||||
-rw-r--r-- | src/gamedata.rs | 41 | ||||
-rw-r--r-- | src/lib.rs | 42 |
3 files changed, 47 insertions, 39 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 60d78c1..f51a115 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,8 @@ All notable changes to this project will be documented in this file. - `Encounter::EaterOfSouls` (`Boss::EaterOfSouls`) - `Encounter::StatueOfDarkness` (`Boss::EyeOfJudgment` and `Boss::EyeOfFate`) - `Log::is_generic` to check whether a log is generic (WvW) -- `GameMode` and the `Log::game_mode` method +- `gamedata::GameMode` and the `Encounter::game_mode` and `Log::game_mode` + methods - `FromRawEventError::UnknownLanguage` has been added to deal with an invalid language byte. diff --git a/src/gamedata.rs b/src/gamedata.rs index 8f9e3dc..a07ac05 100644 --- a/src/gamedata.rs +++ b/src/gamedata.rs @@ -7,6 +7,25 @@ use std::{ }; use thiserror::Error; +/// The game mode in which a log was produced. +/// +/// Note that the distinction made here is relatively arbitrary, but hopefully still useful. In +/// Guild Wars 2 terms, there is no clear definition of what a "game mode" is. +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] +pub enum GameMode { + /// The log is from a raid encounter. + Raid, + /// The log is from a fractal fight. + Fractal, + /// The log is from a strike mission. + Strike, + /// The log is from a training golem. + Golem, + /// The log is from a world-versus-world fight. + WvW, +} + /// Enum containing all encounters with their IDs. /// /// An encounter is a fight or event for which a log can exist. An encounter consists of no, one or @@ -177,6 +196,28 @@ impl Encounter { } Boss::from_u16(id).map(Boss::encounter) } + + /// Returns the game mode of the encounter. + /// + /// This is one of [`GameMode::Raid`], [`GameMode::Fractal`], [`GameMode::Golem`] or + /// [`GameMode::Strike`]. + pub fn game_mode(self) -> GameMode { + use Encounter::*; + match self { + MAMA | Siax | Ensolyss | Skorvald | Artsariiv | Arkk | Ai => GameMode::Fractal, + + ValeGuardian | Gorseval | Sabetha | Slothasor | BanditTrio | Matthias + | KeepConstruct | Xera | Cairn | MursaatOverseer | Samarog | Deimos + | SoullessHorror | RiverOfSouls | BrokenKing | EaterOfSouls | StatueOfDarkness + | VoiceInTheVoid | ConjuredAmalgamate | TwinLargos | Qadim | CardinalAdina + | CardinalSabir | QadimThePeerless => GameMode::Raid, + + IcebroodConstruct | Boneskinner | SuperKodanBrothers | FraenirOfJormag + | WhisperOfJormag => GameMode::Strike, + + StandardKittyGolem | MediumKittyGolem | LargeKittyGolem => GameMode::Golem, + } + } } /// Error for when converting a string to an encounter fails. @@ -102,7 +102,7 @@ mod processing; pub use processing::{process, process_file, process_stream, Compression}; pub mod gamedata; -pub use gamedata::{EliteSpec, Encounter, Profession}; +pub use gamedata::{EliteSpec, Encounter, GameMode, Profession}; pub mod analyzers; pub use analyzers::{Analyzer, Outcome}; @@ -134,27 +134,6 @@ pub enum EvtcError { Utf8Error(#[from] std::str::Utf8Error), } -/// The game mode in which a log was produced. -/// -/// Note that the distinction made here is relatively arbitrary, but hopefully still useful. In -/// Guild Wars 2 terms, there is no clear definition of what a "game mode" is. -/// -/// The game mode of a [`Log`] is obtained through [`Log::game_mode()`]. -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] -pub enum GameMode { - /// The log is from a raid encounter. - Raid, - /// The log is from a fractal fight. - Fractal, - /// The log is from a strike mission. - Strike, - /// The log is from a training golem. - Golem, - /// The log is from a world-versus-world fight. - WvW, -} - /// A fully processed log file. #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug, Clone)] @@ -304,22 +283,9 @@ impl Log { // Here we assume that any generic log is a WvW log, I'm not aware of other generic logs // being produced at the moment. if self.is_generic() { - return Some(GameMode::WvW); - } - use Encounter::*; - match self.encounter()? { - MAMA | Siax | Ensolyss | Skorvald | Artsariiv | Arkk | Ai => Some(GameMode::Fractal), - - ValeGuardian | Gorseval | Sabetha | Slothasor | BanditTrio | Matthias - | KeepConstruct | Xera | Cairn | MursaatOverseer | Samarog | Deimos - | SoullessHorror | RiverOfSouls | BrokenKing | EaterOfSouls | StatueOfDarkness - | VoiceInTheVoid | ConjuredAmalgamate | TwinLargos | Qadim | CardinalAdina - | CardinalSabir | QadimThePeerless => Some(GameMode::Raid), - - IcebroodConstruct | Boneskinner | SuperKodanBrothers | FraenirOfJormag - | WhisperOfJormag => Some(GameMode::Strike), - - StandardKittyGolem | MediumKittyGolem | LargeKittyGolem => Some(GameMode::Golem), + Some(GameMode::WvW) + } else { + self.encounter().map(Encounter::game_mode) } } } |