aboutsummaryrefslogtreecommitdiff
path: root/src/filters/player.rs
diff options
context:
space:
mode:
authorDaniel <kingdread@gmx.de>2020-05-04 15:25:33 +0200
committerDaniel <kingdread@gmx.de>2020-05-04 15:25:33 +0200
commit74dc6574650a157ab57779dc633e140d020b792a (patch)
tree6543a81e0545b9acfeea64a63547c0f7aadf996c /src/filters/player.rs
parent6afe5879579ad39397024fbdbe75ad3207ff50a1 (diff)
downloadraidgrep-74dc6574650a157ab57779dc633e140d020b792a.tar.gz
raidgrep-74dc6574650a157ab57779dc633e140d020b792a.tar.bz2
raidgrep-74dc6574650a157ab57779dc633e140d020b792a.zip
add -class player filter
Diffstat (limited to 'src/filters/player.rs')
-rw-r--r--src/filters/player.rs26
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))
+}