diff options
Diffstat (limited to 'src/filters')
-rw-r--r-- | src/filters/player.rs | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/filters/player.rs b/src/filters/player.rs index 3af2be2..2b14eb0 100644 --- a/src/filters/player.rs +++ b/src/filters/player.rs @@ -3,12 +3,12 @@ //! Additionally, it provides methods to lift a player filter to a log filter with [`any`][any] and //! [`all`][all]. use super::{ - super::{guilds, EarlyLogResult, LogResult, Player, SearchField}, + super::{guilds, playerclass::PlayerClass, EarlyLogResult, LogResult, Player, SearchField}, log::LogFilter, Filter, Inclusion, }; -use std::convert::TryFrom; +use std::{collections::HashSet, convert::TryFrom}; use evtclib::{Agent, AgentKind}; @@ -113,3 +113,25 @@ pub fn character(regex: Regex) -> Box<dyn PlayerFilter> { pub fn account(regex: Regex) -> Box<dyn PlayerFilter> { name(SearchField::Account, regex) } + +#[derive(Clone, Debug)] +struct ClassFilter(HashSet<PlayerClass>); + +impl Filter<Agent, Player> for ClassFilter { + fn filter_early(&self, agent: &Agent) -> Inclusion { + if let AgentKind::Player(ref player) = agent.kind() { + self.0.contains(&player.into()).into() + } else { + Inclusion::Unknown + } + } + + fn filter(&self, player: &Player) -> bool { + self.0.contains(&player.profession) + } +} + +/// Construct a `PlayerFilter` that matches only the given classes. +pub fn class(classes: HashSet<PlayerClass>) -> Box<dyn PlayerFilter> { + Box::new(ClassFilter(classes)) +} |