2019-12-26 18:01:19 +00:00
|
|
|
use crate::comp::{
|
2019-12-28 16:10:39 +00:00
|
|
|
ActionState::*, EcsStateData, IdleState, JumpState, MoveState::*, RunState, StandState,
|
2020-01-05 18:19:09 +00:00
|
|
|
StateHandler, StateUpdate,
|
2019-12-26 14:43:59 +00:00
|
|
|
};
|
2020-01-05 18:19:09 +00:00
|
|
|
use crate::util::state_utils::*;
|
2019-12-28 16:10:39 +00:00
|
|
|
|
2020-01-05 18:19:09 +00:00
|
|
|
#[derive(Clone, Copy, Default, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
|
2019-12-28 16:10:39 +00:00
|
|
|
pub struct SitState;
|
2019-12-26 14:43:59 +00:00
|
|
|
|
2020-01-05 18:19:09 +00:00
|
|
|
impl StateHandler for SitState {
|
2019-12-28 16:10:39 +00:00
|
|
|
fn handle(&self, ecs_data: &EcsStateData) -> StateUpdate {
|
|
|
|
let mut update = StateUpdate {
|
2019-12-26 14:43:59 +00:00
|
|
|
character: *ecs_data.character,
|
|
|
|
pos: *ecs_data.pos,
|
|
|
|
vel: *ecs_data.vel,
|
|
|
|
ori: *ecs_data.ori,
|
|
|
|
};
|
|
|
|
|
2019-12-26 18:01:19 +00:00
|
|
|
// Prevent action state handling
|
2020-01-05 18:19:09 +00:00
|
|
|
update.character.action_state = Idle(Some(IdleState));
|
|
|
|
update.character.move_state = Sit(Some(SitState));
|
2019-12-26 18:01:19 +00:00
|
|
|
|
2019-12-28 16:10:39 +00:00
|
|
|
// Try to Fall
|
|
|
|
// ... maybe the ground disappears,
|
2019-12-26 14:43:59 +00:00
|
|
|
// suddenly maybe a water spell appears.
|
|
|
|
// Can't hurt to be safe :shrug:
|
|
|
|
if !ecs_data.physics.on_ground {
|
2019-12-28 16:10:39 +00:00
|
|
|
update.character.move_state = determine_fall_or_swim(ecs_data.physics);
|
|
|
|
return update;
|
2019-12-26 14:43:59 +00:00
|
|
|
}
|
2019-12-28 16:10:39 +00:00
|
|
|
// Try to jump
|
2019-12-26 14:43:59 +00:00
|
|
|
if ecs_data.inputs.jump.is_pressed() {
|
2020-01-05 18:19:09 +00:00
|
|
|
update.character.move_state = Jump(Some(JumpState));
|
2019-12-26 14:43:59 +00:00
|
|
|
return update;
|
|
|
|
}
|
|
|
|
|
2019-12-28 16:10:39 +00:00
|
|
|
// Try to Run
|
2019-12-26 14:43:59 +00:00
|
|
|
if ecs_data.inputs.move_dir.magnitude_squared() > 0.0 {
|
2020-01-05 18:19:09 +00:00
|
|
|
update.character.move_state = Run(Some(RunState));
|
2019-12-26 14:43:59 +00:00
|
|
|
return update;
|
|
|
|
}
|
|
|
|
|
2019-12-28 16:10:39 +00:00
|
|
|
// Try to Stand
|
2019-12-26 14:43:59 +00:00
|
|
|
if ecs_data.inputs.sit.is_just_pressed() {
|
2020-01-05 18:19:09 +00:00
|
|
|
update.character.move_state = Stand(Some(StandState));
|
2019-12-26 14:43:59 +00:00
|
|
|
return update;
|
|
|
|
}
|
|
|
|
|
2019-12-26 18:01:19 +00:00
|
|
|
// No move has occurred, keep sitting
|
2019-12-26 14:43:59 +00:00
|
|
|
return update;
|
|
|
|
}
|
|
|
|
}
|