aboutsummaryrefslogtreecommitdiff
path: root/src/filters
diff options
context:
space:
mode:
authorDaniel <kingdread@gmx.de>2021-11-19 22:04:50 +0100
committerDaniel <kingdread@gmx.de>2021-11-19 22:04:50 +0100
commit53123d5ab01f2b6ee0282ff067ba39e10b28528e (patch)
tree11c616ea7a20be3f7e9f8688c2d5d3134359731d /src/filters
parent0c634d3c2d279ef75347ac635b69d396d5bf695a (diff)
parenta7682465132e4758bd50777f17a7c4b2048b4c8c (diff)
downloadraidgrep-53123d5ab01f2b6ee0282ff067ba39e10b28528e.tar.gz
raidgrep-53123d5ab01f2b6ee0282ff067ba39e10b28528e.tar.bz2
raidgrep-53123d5ab01f2b6ee0282ff067ba39e10b28528e.zip
Merge branch 'gamemode-filters'
Diffstat (limited to 'src/filters')
-rw-r--r--src/filters/log.rs29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/filters/log.rs b/src/filters/log.rs
index ac166e1..c878b78 100644
--- a/src/filters/log.rs
+++ b/src/filters/log.rs
@@ -9,7 +9,7 @@ use super::{
use std::collections::HashSet;
-use evtclib::Encounter;
+use evtclib::{Encounter, GameMode};
use chrono::{DateTime, Datelike, Utc, Weekday};
@@ -37,6 +37,33 @@ pub fn encounter(bosses: HashSet<Encounter>) -> Box<dyn LogFilter> {
}
#[derive(Debug, Clone)]
+struct GameModeFilter(HashSet<GameMode>);
+
+impl Filter<EarlyLogResult, LogResult> for GameModeFilter {
+ fn filter_early(&self, early_log: &EarlyLogResult) -> Inclusion {
+ let encounter_id = early_log.evtc.header.combat_id;
+ // Special WvW encounter
+ const GENERIC_ENCOUNTER_ID: u16 = 1;
+ let mode = if encounter_id == GENERIC_ENCOUNTER_ID {
+ Some(GameMode::WvW)
+ } else {
+ Encounter::from_header_id(encounter_id).map(Encounter::game_mode)
+ };
+ mode.map(|m| self.0.contains(&m).into())
+ .unwrap_or(Inclusion::Exclude)
+ }
+
+ fn filter(&self, log: &LogResult) -> bool {
+ log.game_mode.map(|m| self.0.contains(&m)).unwrap_or(false)
+ }
+}
+
+/// A [`LogFilter`] that only accepts logs with the given game mode.
+pub fn game_mode(game_modes: HashSet<GameMode>) -> Box<dyn LogFilter> {
+ Box::new(GameModeFilter(game_modes))
+}
+
+#[derive(Debug, Clone)]
struct OutcomeFilter(HashSet<FightOutcome>);
impl Filter<EarlyLogResult, LogResult> for OutcomeFilter {