2019-12-26 14:43:59 +00:00
|
|
|
// Module declarations
|
2020-02-03 10:54:50 +00:00
|
|
|
pub mod basic_attack;
|
2020-01-08 16:56:36 +00:00
|
|
|
pub mod climb;
|
|
|
|
pub mod glide;
|
|
|
|
pub mod idle;
|
|
|
|
pub mod roll;
|
|
|
|
pub mod sit;
|
2020-01-09 16:23:20 +00:00
|
|
|
pub mod utils;
|
2020-01-21 22:54:32 +00:00
|
|
|
pub mod wielded;
|
|
|
|
pub mod wielding;
|
2019-12-26 14:43:59 +00:00
|
|
|
|
2020-01-21 22:54:32 +00:00
|
|
|
use crate::comp::{EcsStateData, StateUpdate};
|
2020-01-05 18:19:09 +00:00
|
|
|
|
2020-01-07 15:49:08 +00:00
|
|
|
/// ## A type for implementing State Handling Behavior.
|
|
|
|
///
|
|
|
|
/// Called by state machines' update functions to allow current states to handle updating
|
|
|
|
/// their parent machine's current state.
|
|
|
|
///
|
|
|
|
/// Structures must implement a `handle()` fn to handle update behavior, and a `new()` for
|
|
|
|
/// instantiating new instances of a state. `handle()` function recieves `EcsStateData`, a struct
|
|
|
|
/// of readonly ECS Component data, and returns a `StateUpdate` tuple, with new components that will
|
|
|
|
/// overwrite an entitie's old components.
|
|
|
|
///
|
|
|
|
/// ## Example Implementation:
|
|
|
|
/// ```
|
2020-01-17 16:39:21 +00:00
|
|
|
/// use crate::states::utils;
|
2020-01-08 13:17:36 +00:00
|
|
|
///
|
2020-01-07 15:49:08 +00:00
|
|
|
/// #[derive(Clone, Copy, Default, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
|
|
|
|
/// pub struct RunState {
|
|
|
|
/// active_duration: Duration,
|
|
|
|
/// }
|
|
|
|
///
|
|
|
|
/// impl StateHandler for RunState {
|
|
|
|
/// fn new(ecs_data: &EcsStateData) -> Self {
|
|
|
|
/// Self {
|
|
|
|
/// active_duration: Duration::default(),
|
|
|
|
/// }
|
|
|
|
/// }
|
|
|
|
///
|
|
|
|
/// fn handle(&self, ecs_data: &EcsStateData) -> StateUpdate {
|
|
|
|
/// let mut update = StateUpdate {
|
|
|
|
/// character: *ecs_data.character,
|
|
|
|
/// pos: *ecs_data.pos,
|
|
|
|
/// vel: *ecs_data.vel,
|
|
|
|
/// ori: *ecs_data.ori,
|
|
|
|
/// };
|
|
|
|
///
|
2020-01-08 13:17:36 +00:00
|
|
|
/// // -- snip --
|
2020-01-17 16:39:21 +00:00
|
|
|
/// // Updates; checks for gliding, climbing, etc.
|
2020-01-07 15:49:08 +00:00
|
|
|
///
|
|
|
|
/// // Update based on groundedness
|
|
|
|
/// update.character.move_state =
|
2020-01-17 16:39:21 +00:00
|
|
|
/// utils::determine_move_from_grounded_state(ecs_data.physics, ecs_data.inputs);
|
2020-01-07 15:49:08 +00:00
|
|
|
///
|
2020-01-12 23:14:08 +00:00
|
|
|
/// update
|
2020-01-07 15:49:08 +00:00
|
|
|
/// }
|
|
|
|
/// }
|
|
|
|
/// ```
|
2020-01-05 18:19:09 +00:00
|
|
|
pub trait StateHandler: Default {
|
2019-12-28 16:10:39 +00:00
|
|
|
fn handle(&self, ecs_data: &EcsStateData) -> StateUpdate;
|
2020-01-05 23:17:22 +00:00
|
|
|
fn new(ecs_data: &EcsStateData) -> Self;
|
2019-12-26 14:43:59 +00:00
|
|
|
}
|