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

35 lines
1.1 KiB
Rust
Raw Normal View History

2020-01-07 15:49:08 +00:00
use crate::comp::{ActionState::Wield, EcsStateData, ItemKind::Tool, StateHandler, StateUpdate};
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 IdleState;
2020-01-05 18:19:09 +00:00
impl StateHandler for IdleState {
2020-01-07 15:49:08 +00:00
fn new(_ecs_data: &EcsStateData) -> Self {
2020-01-05 23:17:22 +00:00
Self {}
}
2019-12-28 16:10:39 +00:00
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 wield
2019-12-29 16:36:59 +00:00
if ecs_data.inputs.primary.is_pressed()
2019-12-28 16:10:39 +00:00
|| ecs_data.inputs.secondary.is_pressed()
2019-12-29 16:36:59 +00:00
|| (ecs_data.inputs.toggle_wield.is_just_pressed()
&& update.character.action_state.is_equip_finished())
2019-12-28 16:10:39 +00:00
{
2020-01-07 15:49:08 +00:00
if let Some(Tool(_)) = ecs_data.stats.equipment.main.as_ref().map(|i| &i.kind) {
update.character.action_state = Wield(None);
2019-12-28 16:10:39 +00:00
}
// else unarmed stuff?
}
return update;
}
}