use crate::{extract::Extract, AgentId, Event, StateChange, TryExtract};
use num_enum::{FromPrimitive, IntoPrimitive};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
#[cfg(feature = "strum")]
use strum::{Display, EnumCount, EnumIter, IntoStaticStr, VariantNames};
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct BreakbarStateEvent {
pub time: u64,
pub agent: AgentId,
pub state: BreakbarState,
}
impl Extract for BreakbarStateEvent {
#[inline]
unsafe fn extract(event: &Event) -> Self {
Self {
time: event.time,
agent: AgentId::from_src(event),
state: (event.value as u16).into(),
}
}
}
impl TryExtract for BreakbarStateEvent {
#[inline]
fn can_extract(event: &Event) -> bool {
event.get_statechange() == StateChange::BreakbarState
}
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct BreakbarPercentEvent {
pub time: u64,
pub agent: AgentId,
pub health: f32,
}
impl Extract for BreakbarPercentEvent {
#[inline]
unsafe fn extract(event: &Event) -> Self {
let health = f32::from_ne_bytes(event.value.to_ne_bytes());
Self {
time: event.time,
agent: AgentId::from_src(event),
health,
}
}
}
impl TryExtract for BreakbarPercentEvent {
#[inline]
fn can_extract(event: &Event) -> bool {
event.get_statechange() == StateChange::BreakbarPercent
}
}
#[derive(
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, IntoPrimitive, FromPrimitive,
)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "strum",
derive(Display, EnumCount, EnumIter, IntoStaticStr, VariantNames)
)]
#[repr(u16)]
pub enum BreakbarState {
Active = 0,
Recover = 1,
Immune = 2,
None = 3,
#[num_enum(catch_all)]
Unknown(u16),
}