use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum BehaviorBlock {
Seek,
Flee,
Orbit,
AlignToVelocity,
AlignToSurfaceNormal,
Drift,
Wobble,
Settle,
Hover,
Tether,
Fuse,
Split,
ParticleLite,
}
impl BehaviorBlock {
pub const ALL: &[BehaviorBlock] = &[
Self::Seek,
Self::Flee,
Self::Orbit,
Self::AlignToVelocity,
Self::AlignToSurfaceNormal,
Self::Drift,
Self::Wobble,
Self::Settle,
Self::Hover,
Self::Tether,
Self::Fuse,
Self::Split,
Self::ParticleLite,
];
pub fn name(&self) -> &'static str {
match self {
Self::Seek => "Seek",
Self::Flee => "Flee",
Self::Orbit => "Orbit",
Self::AlignToVelocity => "Align to Velocity",
Self::AlignToSurfaceNormal => "Align to Surface Normal",
Self::Drift => "Drift",
Self::Wobble => "Wobble",
Self::Settle => "Settle",
Self::Hover => "Hover",
Self::Tether => "Tether",
Self::Fuse => "Fuse",
Self::Split => "Split",
Self::ParticleLite => "Particle Lite",
}
}
pub fn compute_weight(&self) -> f32 {
match self {
Self::Seek | Self::Flee | Self::Drift => 1.0,
Self::Orbit | Self::Hover | Self::Wobble => 1.2,
Self::AlignToVelocity | Self::AlignToSurfaceNormal => 1.5,
Self::Settle | Self::Tether => 1.0,
Self::Fuse | Self::Split => 2.0,
Self::ParticleLite => 3.0,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn behavior_block_all() {
assert_eq!(BehaviorBlock::ALL.len(), 13);
}
#[test]
fn behavior_serde_roundtrip() {
for &b in BehaviorBlock::ALL {
let json = serde_json::to_string(&b).unwrap();
let restored: BehaviorBlock = serde_json::from_str(&json).unwrap();
assert_eq!(b, restored);
}
}
}