veloren/common/src/comp/states/sit.rs

67 lines
2.1 KiB
Rust
Raw Normal View History

2019-12-26 18:01:19 +00:00
use crate::comp::{
ActionState::*, EcsCharacterState, EcsStateUpdate, FallHandler, JumpHandler, MoveState::*,
RunHandler, StandHandler, StateHandle, SwimHandler,
2019-12-26 14:43:59 +00:00
};
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
pub struct SitHandler;
impl StateHandle for SitHandler {
2019-12-26 18:01:19 +00:00
fn handle(&self, ecs_data: &EcsCharacterState) -> EcsStateUpdate {
let mut update = EcsStateUpdate {
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
update.character.action_disabled = true;
update.character.action_state = Idle;
update.character.move_state = Sit(SitHandler);
2019-12-26 14:43:59 +00:00
// Falling
// Idk, maybe the ground disappears,
// suddenly maybe a water spell appears.
// Can't hurt to be safe :shrug:
if !ecs_data.physics.on_ground {
if ecs_data.physics.in_fluid {
2019-12-26 18:01:19 +00:00
update.character.move_state = Swim(SwimHandler);
2019-12-26 14:43:59 +00:00
2019-12-26 18:01:19 +00:00
update.character.action_disabled = false;
2019-12-26 14:43:59 +00:00
return update;
} else {
2019-12-26 18:01:19 +00:00
update.character.move_state = Fall(FallHandler);
2019-12-26 14:43:59 +00:00
2019-12-26 18:01:19 +00:00
update.character.action_disabled = false;
2019-12-26 14:43:59 +00:00
return update;
}
}
// Jumping
if ecs_data.inputs.jump.is_pressed() {
2019-12-26 18:01:19 +00:00
update.character.move_state = Jump(JumpHandler);
2019-12-26 14:43:59 +00:00
2019-12-26 18:01:19 +00:00
update.character.action_disabled = false;
2019-12-26 14:43:59 +00:00
return update;
}
// Moving
if ecs_data.inputs.move_dir.magnitude_squared() > 0.0 {
2019-12-26 18:01:19 +00:00
update.character.move_state = Run(RunHandler);
2019-12-26 14:43:59 +00:00
2019-12-26 18:01:19 +00:00
update.character.action_disabled = false;
2019-12-26 14:43:59 +00:00
return update;
}
// Standing back up (unsitting)
if ecs_data.inputs.sit.is_just_pressed() {
2019-12-26 18:01:19 +00:00
update.character.move_state = Stand(StandHandler);
2019-12-26 14:43:59 +00:00
2019-12-26 18:01:19 +00:00
update.character.action_disabled = false;
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;
}
}