diff options
author | Daniel Schadt <kingdread@gmx.de> | 2020-10-04 12:01:06 +0200 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2020-10-04 12:01:06 +0200 |
commit | f480faeefbab83a4396a172a15fce7d264216ef2 (patch) | |
tree | 8a5d5fc9b677d15be439f78d6dbe100157fcfb34 /src/gamedata.rs | |
parent | b6676565c39bb6a2fe8f5f01218fe654ec4d2cb8 (diff) | |
download | evtclib-f480faeefbab83a4396a172a15fce7d264216ef2.tar.gz evtclib-f480faeefbab83a4396a172a15fce7d264216ef2.tar.bz2 evtclib-f480faeefbab83a4396a172a15fce7d264216ef2.zip |
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.
Diffstat (limited to 'src/gamedata.rs')
-rw-r--r-- | src/gamedata.rs | 16 |
1 files changed, 16 insertions, 0 deletions
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<Encounter> { + Boss::from_u16(id).map(Boss::encounter) + } } /// Error for when converting a string to an encounter fails. |