diff --git a/crates/system/src/data/ship/shipstate.rs b/crates/system/src/data/ship/shipstate.rs index a2535de..9061b52 100644 --- a/crates/system/src/data/ship/shipstate.rs +++ b/crates/system/src/data/ship/shipstate.rs @@ -1,3 +1,5 @@ +use std::num::NonZeroU32; + use galactica_content::SystemObjectHandle; use rapier2d::math::Isometry; @@ -73,4 +75,66 @@ impl ShipState { _ => None, } } + + /// An integer representing each state. + /// Makes detecting state changes cheap and easy. + pub fn as_int(&self) -> NonZeroU32 { + NonZeroU32::new(match self { + Self::Dead => 1, + Self::Collapsing => 2, + Self::Flying { .. } => 3, + Self::Landed { .. } => 4, + Self::Landing { .. } => 5, + Self::UnLanding { .. } => 6, + }) + .unwrap() + } + + /// Is this state Dead? + pub fn is_dead(&self) -> bool { + match self { + Self::Dead => true, + _ => false, + } + } + + /// Is this state Collapsing? + pub fn is_collapsing(&self) -> bool { + match self { + Self::Collapsing => true, + _ => false, + } + } + + /// Is this state Flying? + pub fn is_flying(&self) -> bool { + match self { + Self::Flying { .. } => true, + _ => false, + } + } + + /// Is this state Landed? + pub fn is_landed(&self) -> bool { + match self { + Self::Landed { .. } => true, + _ => false, + } + } + + /// Is this state Landing? + pub fn is_landing(&self) -> bool { + match self { + Self::Landing { .. } => true, + _ => false, + } + } + + /// Is this state UnLanding? + pub fn is_unlanding(&self) -> bool { + match self { + Self::UnLanding { .. } => true, + _ => false, + } + } }