diff options
author | Daniel <kingdread@gmx.de> | 2020-05-04 15:00:01 +0200 |
---|---|---|
committer | Daniel <kingdread@gmx.de> | 2020-05-04 15:03:51 +0200 |
commit | 9537ffb07dd80c408ae475308e748ad1831d6462 (patch) | |
tree | 5658a06e4b5016de46c727b245922a27974e6cac /src/main.rs | |
parent | 13e7b0142c4103ac22ceb244cda36889438fb37a (diff) | |
download | raidgrep-9537ffb07dd80c408ae475308e748ad1831d6462.tar.gz raidgrep-9537ffb07dd80c408ae475308e748ad1831d6462.tar.bz2 raidgrep-9537ffb07dd80c408ae475308e748ad1831d6462.zip |
replace Player::profession with PlayerClass enum
Away with stringly typed stuff, we now have a proper way to save the
profession of a player without relying on a string. Theoretically, that
is better for memory consumption, as we now save only the identifier and
use fmt::Display and static strings, but that was not the main reason
for this change.
The main reason is that now we can programatically work with the
profession and elite spec, so that we can (for example) implement a
filter to filter players based on their class.
The word "class" has been chosen because it is a common synonym for the
profession/elite, and because this is neither a profession nor the elite
- it's a combination of both.
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 51 |
1 files changed, 6 insertions, 45 deletions
diff --git a/src/main.rs b/src/main.rs index 625e869..d9f0817 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,7 +17,7 @@ use structopt::StructOpt; use walkdir::{DirEntry, WalkDir}; use evtclib::raw::parser::PartialEvtc; -use evtclib::{EliteSpec, EventKind, Log, Profession}; +use evtclib::{EventKind, Log}; mod fexpr; mod filters; @@ -26,6 +26,8 @@ mod guilds; mod logger; mod output; mod paths; +mod playerclass; +use playerclass::PlayerClass; /// Application name, as it should be used in configuration directory paths. const APP_NAME: &str = "raidgrep"; @@ -145,8 +147,8 @@ pub struct Player { account_name: String, /// Character name of the player. character_name: String, - /// Profession (or elite specialization) as english name. - profession: String, + /// Profession or elite specialization. + profession: PlayerClass, /// Subsquad that the player was in. subgroup: u8, /// Guild ID, ready for API consumption. @@ -478,7 +480,7 @@ fn extract_info(entry: &DirEntry, log: &Log) -> LogResult { .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(), + profession: (p.profession(), p.elite()).into(), subgroup: p.subgroup(), guild_id: guild_ids.get(&p.addr()).cloned(), }) @@ -570,44 +572,3 @@ fn get_encounter_name(log: &Log) -> Option<&'static str> { Boss::WhisperOfJormag => "Whisper of Jormag", }) } - -/// Get the (english) name for the given profession/elite specialization. -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", - } - } -} |