From 5d18c3e79638573fb7ccf03349b7a5ca0c9d97f9 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Wed, 17 Nov 2021 20:32:21 +0100 Subject: Add a game-mode filter --- src/filters/log.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'src/filters/log.rs') 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}; @@ -36,6 +36,33 @@ pub fn encounter(bosses: HashSet) -> Box { Box::new(BossFilter(bosses)) } +#[derive(Debug, Clone)] +struct GameModeFilter(HashSet); + +impl Filter 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) -> Box { + Box::new(GameModeFilter(game_modes)) +} + #[derive(Debug, Clone)] struct OutcomeFilter(HashSet); -- cgit v1.2.3