From c731b470fc162e56f6d81c475bacb41230a5e2d3 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 31 May 2019 02:51:16 +0200 Subject: add option to filter based on boss --- src/csl.rs | 17 ++++++++++++++++- src/filters.rs | 11 +++++++++++ src/main.rs | 13 ++++++++++++- 3 files changed, 39 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/csl.rs b/src/csl.rs index fb11841..df10451 100644 --- a/src/csl.rs +++ b/src/csl.rs @@ -5,6 +5,7 @@ use std::fmt; use super::{SearchField, FightOutcome}; use chrono::Weekday; +use evtclib::statistics::gamedata::Boss; pub trait Variants: Copy { type Output: Iterator; @@ -29,12 +30,26 @@ macro_rules! variants { ].iter().cloned() } } - } + }; + ($target:ident => $($var:ident,)+) => { + variants!($target => $($var),+); + }; } variants! { SearchField => Account, Character } variants! { FightOutcome => Success, Wipe } variants! { Weekday => Mon, Tue, Wed, Thu, Fri, Sat, Sun } +variants! { Boss => + ValeGuardian, Gorseval, Sabetha, + Slothasor, Matthias, + KeepConstruct, Xera, + Cairn, MursaatOverseer, Samarog, Deimos, + SoullessHorror, Dhuum, + ConjuredAmalgamate, LargosTwins, Qadim, + + Skorvald, Artsariiv, Arkk, + MAMA, Siax, Ensolyss, +} /// The character that delimits items from each other. const DELIMITER: char = ','; diff --git a/src/filters.rs b/src/filters.rs index 8433690..02334bc 100644 --- a/src/filters.rs +++ b/src/filters.rs @@ -1,5 +1,8 @@ use evtclib::{Agent, AgentName}; use evtclib::raw::parser::PartialEvtc; +use evtclib::statistics::gamedata::Boss; + +use num_traits::FromPrimitive; use super::{SearchField, LogResult, Opt}; @@ -30,6 +33,14 @@ pub fn filter_name(evtc: &PartialEvtc, opt: &Opt) -> bool { false } +/// Do filtering based on the boss ID. +pub fn filter_boss(evtc: &PartialEvtc, opt: &Opt) -> bool { + let boss = Boss::from_u16(evtc.header.combat_id); + boss + .map(|b| opt.bosses.contains(&b)) + .unwrap_or(true) +} + /// Do filtering based on the fight outcome. pub fn filter_outcome(result: &LogResult, opt: &Opt) -> bool { opt.outcome.contains(&result.outcome) diff --git a/src/main.rs b/src/main.rs index 87ebbb0..89dab09 100644 --- a/src/main.rs +++ b/src/main.rs @@ -123,6 +123,14 @@ pub struct Opt { )] weekdays: CommaSeparatedList, + /// Only show logs from the given encounters. + #[structopt( + short = "e", + long = "bosses", + default_value = "*", + )] + bosses: CommaSeparatedList, + /// Print more debugging information to stderr. #[structopt(long = "debug")] debug: bool, @@ -317,7 +325,10 @@ fn search_log(entry: &DirEntry, opt: &Opt) -> Result, RuntimeE let mut stream = wrapper.get_stream(); let partial = evtclib::raw::parser::parse_partial_file(&mut stream)?; - if filters::filter_name(&partial, opt) == opt.invert { + let early_ok = filters::filter_name(&partial, opt) != opt.invert + && filters::filter_boss(&partial, opt); + + if !early_ok { return Ok(None) } -- cgit v1.2.3