From f480faeefbab83a4396a172a15fce7d264216ef2 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Sun, 4 Oct 2020 12:01:06 +0200 Subject: add Encounter::from_header_id It makes sense to expose this logic as a function, as other programs like raidgrep might want to use the same logic when dealing with partial evtc files. --- CHANGELOG.md | 2 ++ src/gamedata.rs | 16 ++++++++++++++++ src/lib.rs | 4 +--- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d9a506..1417d89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ All notable changes to this project will be documented in this file. - `Log::gadgets` to retrieve all gadget agents. - `Log::build_id` to retrieve the game's build id. - The `serde` optional feature to enable (de)serialization of API types. +- `Encounter::from_header_id` to convert a header ID from arcdps to the correct + encounter. ### Changed - `gamedata::Boss` has been split in `gamedata::Boss` and `gamedata::Encounter` diff --git a/src/gamedata.rs b/src/gamedata.rs index 64b6731..ac8d46a 100644 --- a/src/gamedata.rs +++ b/src/gamedata.rs @@ -1,5 +1,6 @@ //! This module contains some low-level game data, such as different boss IDs. use num_derive::FromPrimitive; +use num_traits::FromPrimitive; use std::{ fmt::{self, Display, Formatter}, str::FromStr, @@ -118,6 +119,21 @@ impl Encounter { Encounter::WhisperOfJormag => &[Boss::WhisperOfJormag], } } + + /// Converts a combat ID as given in the arcdps header into the correct encounter. + /// + /// This properly takes care of encounters with multiple bosses or which could be saved as + /// multiple bosses. + /// + /// ``` + /// # use evtclib::gamedata::Encounter; + /// assert_eq!(Encounter::from_header_id(0x3C4E), Some(Encounter::ValeGuardian)); + /// assert_eq!(Encounter::from_header_id(0x5261), Some(Encounter::TwinLargos)); + /// ``` + #[inline] + pub fn from_header_id(id: u16) -> Option { + Boss::from_u16(id).map(Boss::encounter) + } } /// Error for when converting a string to an encounter fails. diff --git a/src/lib.rs b/src/lib.rs index bb71c77..c950b17 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -88,7 +88,6 @@ //! While there are legitimate use cases for writing/modification support, they are currently not //! implemented (but might be in a future version). -use num_traits::FromPrimitive; use thiserror::Error; pub mod raw; @@ -103,7 +102,6 @@ mod processing; pub use processing::{process, process_file, process_stream, Compression}; pub mod gamedata; -use gamedata::Boss; pub use gamedata::{EliteSpec, Encounter, Profession}; pub mod analyzers; @@ -230,7 +228,7 @@ impl Log { /// if we know about it in [`Encounter`]. #[inline] pub fn encounter(&self) -> Option { - Boss::from_u16(self.boss_id).map(Boss::encounter) + Encounter::from_header_id(self.boss_id) } /// Return an analyzer suitable to analyze the given log. -- cgit v1.2.3