use serde::{Deserialize, Serialize};
use crate::entity::EntityId;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub enum RiderPhase {
Waiting,
Boarding(EntityId),
Riding(EntityId),
#[serde(alias = "Alighting")]
Exiting(EntityId),
Walking,
Arrived,
Abandoned,
Resident,
}
impl std::fmt::Display for RiderPhase {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Waiting => write!(f, "Waiting"),
Self::Boarding(id) => write!(f, "Boarding({id:?})"),
Self::Riding(id) => write!(f, "Riding({id:?})"),
Self::Exiting(id) => write!(f, "Exiting({id:?})"),
Self::Walking => write!(f, "Walking"),
Self::Arrived => write!(f, "Arrived"),
Self::Abandoned => write!(f, "Abandoned"),
Self::Resident => write!(f, "Resident"),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Rider {
pub(crate) weight: f64,
pub(crate) phase: RiderPhase,
pub(crate) current_stop: Option<EntityId>,
pub(crate) spawn_tick: u64,
pub(crate) board_tick: Option<u64>,
}
impl Rider {
#[must_use]
pub const fn weight(&self) -> f64 {
self.weight
}
#[must_use]
pub const fn phase(&self) -> RiderPhase {
self.phase
}
#[must_use]
pub const fn current_stop(&self) -> Option<EntityId> {
self.current_stop
}
#[must_use]
pub const fn spawn_tick(&self) -> u64 {
self.spawn_tick
}
#[must_use]
pub const fn board_tick(&self) -> Option<u64> {
self.board_tick
}
}