diff options
m--------- | evtclib | 0 | ||||
-rw-r--r-- | src/fexpr/grammar.lalrpop | 2 | ||||
-rw-r--r-- | src/filters/log.rs | 2 | ||||
-rw-r--r-- | src/filters/player.rs | 17 | ||||
-rw-r--r-- | src/main.rs | 139 |
5 files changed, 61 insertions, 99 deletions
diff --git a/evtclib b/evtclib -Subproject 3ab7a86d2f6ad3b15e72494928f9f8de255ceef +Subproject 6288027ab8b5e17c9dee30e97042198cfe66646 diff --git a/src/fexpr/grammar.lalrpop b/src/fexpr/grammar.lalrpop index 58ec052..a406490 100644 --- a/src/fexpr/grammar.lalrpop +++ b/src/fexpr/grammar.lalrpop @@ -6,7 +6,7 @@ use super::{ SearchField, Weekday, }; -use evtclib::statistics::gamedata::Boss; +use evtclib::Boss; use std::collections::HashSet; use lalrpop_util::ParseError; diff --git a/src/filters/log.rs b/src/filters/log.rs index 8d4e0b5..6be7acc 100644 --- a/src/filters/log.rs +++ b/src/filters/log.rs @@ -10,7 +10,7 @@ use super::{ use std::collections::HashSet; use evtclib::raw::parser::PartialEvtc; -use evtclib::statistics::gamedata::Boss; +use evtclib::Boss; use chrono::{Datelike, NaiveDateTime}; use num_traits::FromPrimitive as _; diff --git a/src/filters/player.rs b/src/filters/player.rs index 4daeb22..7258bd7 100644 --- a/src/filters/player.rs +++ b/src/filters/player.rs @@ -8,8 +8,10 @@ use super::{ Filter, Inclusion, }; +use std::convert::TryFrom; + use evtclib::raw::parser::PartialEvtc; -use evtclib::{Agent, AgentName}; +use evtclib::{Agent, AgentKind}; use regex::Regex; @@ -31,7 +33,7 @@ impl Filter<PartialEvtc, LogResult> for AllPlayers { continue; } - let agent = Agent::from_raw(agent); + let agent = Agent::try_from(agent); if let Ok(agent) = agent { result = result & self.0.filter_early(&agent); } else { @@ -72,15 +74,10 @@ impl Filter<Agent, Player> for NameFilter { return Inclusion::Unknown; } - if let AgentName::Player { - ref account_name, - ref character_name, - .. - } = agent.name() - { + if let AgentKind::Player(ref player) = agent.kind() { let field = match self.0 { - SearchField::Account => account_name, - SearchField::Character => character_name, + SearchField::Account => player.account_name(), + SearchField::Character => player.character_name(), _ => unreachable!("We already checked for Guild earlier"), }; self.1.is_match(field).into() diff --git a/src/main.rs b/src/main.rs index 231fbdc..8cd1329 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,13 +11,12 @@ use chrono::{NaiveDateTime, Weekday}; use colored::Colorize; use itertools::Itertools; use log::debug; -use num_traits::cast::FromPrimitive; use regex::Regex; use rustyline::Editor; use structopt::StructOpt; use walkdir::{DirEntry, WalkDir}; -use evtclib::{AgentKind, AgentName, EventKind, Log}; +use evtclib::{EliteSpec, EventKind, Log, Profession}; mod fexpr; mod filters; @@ -26,16 +25,6 @@ mod guilds; mod logger; mod output; -macro_rules! unwrap { - ($p:pat = $e:expr => { $r:expr} ) => { - if let $p = $e { - $r - } else { - panic!("Pattern match failed!"); - } - }; -} - /// A program that allows you to search through all your evtc logs for specific people. /// /// raidgrep supports different predicates that determine whether a log is included or not. @@ -405,7 +394,7 @@ fn extract_info(entry: &DirEntry, log: &Log) -> LogResult { debug!( "log file has unknown boss: {:?} (id: {:#x})", entry.path(), - log.boss_id() + log.encounter_id() ); "unknown" }) @@ -415,30 +404,20 @@ fn extract_info(entry: &DirEntry, log: &Log) -> LogResult { let mut players = log .players() - .map(|p| { - unwrap! { AgentKind::Player { profession, elite } = p.kind() => { - unwrap! { AgentName::Player { - account_name, - character_name, - subgroup, - } = p.name() => - { - Player { - account_name: account_name.clone(), - character_name: character_name.clone(), - profession: get_profession_name(*profession, *elite).into(), - subgroup: *subgroup, - guild_id: guild_ids.get(p.addr()).cloned(), - } - }}}} + .map(|p| Player { + account_name: p.account_name().to_owned(), + character_name: p.character_name().to_owned(), + profession: get_profession_name(p.profession(), p.elite()).into(), + subgroup: p.subgroup(), + guild_id: guild_ids.get(&p.addr()).cloned(), }) .collect::<Vec<Player>>(); players.sort_by_key(|p| p.subgroup); LogResult { log_file: entry.path().to_path_buf(), - time: NaiveDateTime::from_timestamp(i64::from(get_start_timestamp(log)), 0), - boss_id: log.boss_id(), + time: NaiveDateTime::from_timestamp(i64::from(log.local_start_timestamp().unwrap_or(0)), 0), + boss_id: log.encounter_id(), boss_name, players, outcome: get_fight_outcome(log), @@ -466,34 +445,19 @@ fn get_guild_mapping(log: &Log) -> HashMap<u64, String> { .collect() } -/// Get the timestamp of the log start time. -fn get_start_timestamp(log: &Log) -> u32 { - for event in log.events() { - if let EventKind::LogStart { - local_timestamp, .. - } = event.kind - { - return local_timestamp; - } - } - 0 -} - /// Get the outcome of the fight. fn get_fight_outcome(log: &Log) -> FightOutcome { - for event in log.events() { - if let EventKind::Reward { .. } = event.kind { - return FightOutcome::Success; - } + if log.was_rewarded() { + FightOutcome::Success + } else { + FightOutcome::Wipe } - FightOutcome::Wipe } /// Get the (english) name for the given encounter fn get_encounter_name(log: &Log) -> Option<&'static str> { - use evtclib::statistics::gamedata::Boss; - let boss = Boss::from_u16(log.boss_id())?; - Some(match boss { + use evtclib::Boss; + Some(match log.encounter()? { Boss::ValeGuardian => "Vale Guardian", Boss::Gorseval => "Gorseval", Boss::Sabetha => "Sabetha", @@ -537,41 +501,42 @@ fn get_encounter_name(log: &Log) -> Option<&'static str> { } /// Get the (english) name for the given profession/elite specialization. -fn get_profession_name(profession: u32, elite: u32) -> &'static str { - match (profession, elite) { - (1, 0) => "Guardian", - (2, 0) => "Warrior", - (3, 0) => "Engineer", - (4, 0) => "Ranger", - (5, 0) => "Thief", - (6, 0) => "Elementalist", - (7, 0) => "Mesmer", - (8, 0) => "Necromancer", - (9, 0) => "Revenant", - - (1, 27) => "Dragonhunter", - (2, 18) => "Berserker", - (3, 43) => "Scrapper", - (4, 5) => "Druid", - (5, 7) => "Daredevil", - (6, 48) => "Tempest", - (7, 40) => "Chronomancer", - (8, 34) => "Reaper", - (9, 52) => "Herald", - - (1, 62) => "Firebrand", - (2, 61) => "Spellbreaker", - (3, 57) => "Holosmith", - (4, 55) => "Soulbeast", - (5, 58) => "Deadeye", - (6, 56) => "Weaver", - (7, 59) => "Mirage", - (8, 60) => "Scourge", - (9, 63) => "Renegade", - - _ => { - debug!("Unknown spec (prof: {}, elite: {})", profession, elite); - "Unknown" +fn get_profession_name(profession: Profession, elite: Option<EliteSpec>) -> &'static str { + use EliteSpec::*; + use Profession::*; + + if let Some(elite) = elite { + match elite { + Dragonhunter => "Dragonhunter", + Firebrand => "Firebrand", + Berserker => "Berserker", + Spellbreaker => "Spellbreaker", + Herald => "Herald", + Renegade => "Renegade", + Scrapper => "Scrapper", + Holosmith => "Holosmith", + Druid => "Druid", + Soulbeast => "Soulbeast", + Daredevil => "Daredevil", + Deadeye => "Deadeye", + Tempest => "Tempest", + Weaver => "Weaver", + Chronomancer => "Chronomancer", + Mirage => "Mirage", + Reaper => "Reaper", + Scourge => "Scourge", + } + } else { + match profession { + Guardian => "Guardian", + Warrior => "Warrior", + Revenant => "Revenant", + Engineer => "Engineer", + Ranger => "Ranger", + Thief => "Thief", + Elementalist => "Elementalist", + Mesmer => "Mesmer", + Necromancer => "Necromancer", } } } |