Added utility functions

master
Mark 2024-02-03 11:21:43 -08:00
parent 7c8407f966
commit ae89f0e987
Signed by: Mark
GPG Key ID: C6D63995FE72FD80
1 changed files with 64 additions and 0 deletions

View File

@ -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,
}
}
}