2019-12-28 16:10:39 +00:00
|
|
|
use crate::comp::{ActionState::*, EcsStateData, IdleState, StateHandle, StateUpdate};
|
2019-12-26 14:43:59 +00:00
|
|
|
use std::time::Duration;
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
|
2019-12-28 16:10:39 +00:00
|
|
|
pub struct WieldState {
|
2019-12-26 14:43:59 +00:00
|
|
|
/// How long before a new action can be performed
|
|
|
|
/// after equipping
|
|
|
|
pub equip_delay: Duration,
|
|
|
|
}
|
|
|
|
|
2019-12-28 16:10:39 +00:00
|
|
|
impl StateHandle for WieldState {
|
|
|
|
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
|
|
|
// Only act once equip_delay has expired
|
|
|
|
if self.equip_delay == Duration::default() {
|
|
|
|
// Toggle Weapons
|
|
|
|
if ecs_data.inputs.toggle_wield.is_pressed()
|
|
|
|
&& ecs_data.character.action_state.is_equip_finished()
|
|
|
|
{
|
2019-12-28 16:10:39 +00:00
|
|
|
update.character.action_state = Idle(IdleState);
|
2019-12-26 18:01:19 +00:00
|
|
|
return update;
|
|
|
|
}
|
2019-12-26 14:43:59 +00:00
|
|
|
|
2019-12-26 18:01:19 +00:00
|
|
|
// Try weapon actions
|
|
|
|
if ecs_data.inputs.primary.is_pressed() {
|
|
|
|
// TODO: PrimaryStart
|
|
|
|
} else if ecs_data.inputs.secondary.is_pressed() {
|
|
|
|
// TODO: SecondaryStart
|
|
|
|
}
|
2019-12-28 16:10:39 +00:00
|
|
|
} else {
|
|
|
|
// Equip delay hasn't expired yet
|
2019-12-26 18:01:19 +00:00
|
|
|
// Update wield delay
|
2019-12-28 16:10:39 +00:00
|
|
|
update.character.action_state = Wield(WieldState {
|
2019-12-26 14:43:59 +00:00
|
|
|
equip_delay: self
|
|
|
|
.equip_delay
|
|
|
|
.checked_sub(Duration::from_secs_f32(ecs_data.dt.0))
|
|
|
|
.unwrap_or_default(),
|
2019-12-26 18:01:19 +00:00
|
|
|
});
|
|
|
|
}
|
2019-12-26 14:43:59 +00:00
|
|
|
|
|
|
|
return update;
|
|
|
|
}
|
|
|
|
}
|