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,
|
|
|
|
StateHandle, StateUpdate,
|
2019-12-26 14:43:59 +00:00
|
|
|
};
|
2019-12-28 16:10:39 +00:00
|
|
|
use crate::util::movement_utils::*;
|
|
|
|
|
2019-12-26 14:43:59 +00:00
|
|
|
#[derive(Clone, Copy, 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
|
|
|
|
2019-12-28 16:10:39 +00:00
|
|
|
impl StateHandle for SitState {
|
|
|
|
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
|
2019-12-28 16:10:39 +00:00
|
|
|
update.character.action_state = Idle(IdleState);
|
|
|
|
update.character.move_state = Sit(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() {
|
2019-12-28 16:10:39 +00:00
|
|
|
update.character.move_state = Jump(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 {
|
2019-12-28 16:10:39 +00:00
|
|
|
update.character.move_state = Run(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() {
|
2019-12-28 16:10:39 +00:00
|
|
|
update.character.move_state = Stand(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;
|
|
|
|
}
|
|
|
|
}
|