mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
51 lines
1.5 KiB
Rust
51 lines
1.5 KiB
Rust
use super::utils::*;
|
|
use crate::comp::{EcsStateData, MoveState, StateHandler, StateUpdate};
|
|
|
|
#[derive(Clone, Copy, Default, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
|
|
pub struct State;
|
|
|
|
impl StateHandler for State {
|
|
fn new(_ecs_data: &EcsStateData) -> Self {
|
|
Self {}
|
|
}
|
|
|
|
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,
|
|
};
|
|
|
|
// Try to sit
|
|
if can_sit(ecs_data.physics, ecs_data.inputs, ecs_data.body) {
|
|
update.character.move_state = MoveState::Sit(None);
|
|
return update;
|
|
}
|
|
|
|
// Try to climb
|
|
if can_climb(ecs_data.physics, ecs_data.inputs, ecs_data.body) {
|
|
update.character.move_state = MoveState::Climb(None);
|
|
return update;
|
|
}
|
|
|
|
// Try to jump
|
|
if can_jump(ecs_data.physics, ecs_data.inputs) {
|
|
update.character.move_state = MoveState::Jump(None);
|
|
return update;
|
|
}
|
|
|
|
// Check gliding
|
|
if can_glide(ecs_data.physics, ecs_data.inputs, ecs_data.body) {
|
|
update.character.move_state = MoveState::Glide(None);
|
|
return update;
|
|
}
|
|
|
|
// Else update based on groundedness
|
|
update.character.move_state =
|
|
determine_move_from_grounded_state(ecs_data.physics, ecs_data.inputs);
|
|
|
|
return update;
|
|
}
|
|
}
|