diff options
author | Daniel Schadt <kingdread@gmx.de> | 2020-05-19 15:24:28 +0200 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2020-05-19 15:24:28 +0200 |
commit | a2c77bd2f8110c505464077c22d489d6a6d4c8c8 (patch) | |
tree | fd0b7710f22e095c8120584a60cca5ca687debf6 | |
parent | 0c14e920aec0d28d0145766670bb0ac6c5d58263 (diff) | |
download | evtclib-a2c77bd2f8110c505464077c22d489d6a6d4c8c8.tar.gz evtclib-a2c77bd2f8110c505464077c22d489d6a6d4c8c8.tar.bz2 evtclib-a2c77bd2f8110c505464077c22d489d6a6d4c8c8.zip |
add CbtStateChange::Unknown
This is not defined by arcdps, but we'd have to adjust evtclib every
time a new statechange is introduced. This way, we stay
forward-compatible.
-rw-r--r-- | src/event.rs | 3 | ||||
-rw-r--r-- | src/raw/parser.rs | 4 | ||||
-rw-r--r-- | src/raw/types.rs | 10 |
3 files changed, 14 insertions, 3 deletions
diff --git a/src/event.rs b/src/event.rs index cf2a42f..df0d5d3 100644 --- a/src/event.rs +++ b/src/event.rs @@ -365,7 +365,8 @@ impl TryFrom<&raw::CbtEvent> for Event { | CbtStateChange::SkillTiming | CbtStateChange::BreakbarState | CbtStateChange::BreakbarPercent - | CbtStateChange::Error => { + | CbtStateChange::Error + | CbtStateChange::Unknown => { return Err(FromRawEventError::UnknownStateChange( raw_event.is_statechange, )) diff --git a/src/raw/parser.rs b/src/raw/parser.rs index bf61f8c..8401146 100644 --- a/src/raw/parser.rs +++ b/src/raw/parser.rs @@ -350,7 +350,7 @@ pub fn parse_event_rev0<R: Read>(mut input: R) -> ParseResult<CbtEvent> { let is_fifty = input.read_u8()? != 0; let is_moving = input.read_u8()? != 0; let is_statechange = - CbtStateChange::from_u8(input.read_u8()?).ok_or(ParseError::InvalidData)?; + CbtStateChange::from_u8(input.read_u8()?).unwrap_or(CbtStateChange::Unknown); let is_flanking = input.read_u8()? != 0; let is_shields = input.read_u8()? != 0; @@ -411,7 +411,7 @@ pub fn parse_event_rev1<R: Read>(mut input: R) -> ParseResult<CbtEvent> { let is_fifty = input.read_u8()? != 0; let is_moving = input.read_u8()? != 0; let is_statechange = - CbtStateChange::from_u8(input.read_u8()?).ok_or(ParseError::InvalidData)?; + CbtStateChange::from_u8(input.read_u8()?).unwrap_or(CbtStateChange::Unknown); let is_flanking = input.read_u8()? != 0; let is_shields = input.read_u8()? != 0; let is_offcycle = input.read_u8()? != 0; diff --git a/src/raw/types.rs b/src/raw/types.rs index 820d7a5..9931ea9 100644 --- a/src/raw/types.rs +++ b/src/raw/types.rs @@ -201,6 +201,16 @@ pub enum CbtStateChange { BreakbarPercent, /// `time` is the start of the error string. Error, + /// The given state change is unknown. + /// + /// Note that this is not defined by arcdps itself, we just use this value as an easy way out + /// for when unknown statechanges are introduces. + /// + /// This is for future proofing, whenever a new event is added, we'd otherwise have to update + /// `evtclib` as well. The arcdps evtc README states to *make sure to ignore unknown + /// statechange types.* + // Keep this as the highest value, so we don't clash with future statechange additions. + Unknown = 255, } impl Default for CbtStateChange { |