Input replication (#62)
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
use crate::{
|
||||
abilities::TriggerCashHeal, cash::CashResource, global_observer, hitpoints::Hitpoints,
|
||||
player::Player, sounds::PlaySound,
|
||||
cash::CashResource, control::ControlState, hitpoints::Hitpoints, player::Player,
|
||||
sounds::PlaySound,
|
||||
};
|
||||
use bevy::prelude::*;
|
||||
use lightyear::prelude::input::native::ActionState;
|
||||
|
||||
pub fn plugin(app: &mut App) {
|
||||
global_observer!(app, on_heal_trigger);
|
||||
app.add_systems(FixedUpdate, on_heal_trigger);
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
@@ -15,27 +16,28 @@ struct HealAction {
|
||||
}
|
||||
|
||||
fn on_heal_trigger(
|
||||
_trigger: Trigger<TriggerCashHeal>,
|
||||
mut cmds: Commands,
|
||||
mut cash: ResMut<CashResource>,
|
||||
mut query: Query<&mut Hitpoints, With<Player>>,
|
||||
mut query: Query<(&mut Hitpoints, &ActionState<ControlState>), With<Player>>,
|
||||
) {
|
||||
let Ok(mut hp) = query.single_mut() else {
|
||||
return;
|
||||
};
|
||||
for (mut hp, controls) in query.iter_mut() {
|
||||
if !controls.cash_heal {
|
||||
continue;
|
||||
}
|
||||
|
||||
if hp.max() || cash.cash == 0 {
|
||||
return;
|
||||
if hp.max() || cash.cash == 0 {
|
||||
return;
|
||||
}
|
||||
|
||||
let action = heal(cash.cash, hp.get().1 - hp.get().0);
|
||||
|
||||
hp.heal(action.damage_healed);
|
||||
|
||||
cash.cash = cash.cash.saturating_sub(action.cost);
|
||||
|
||||
//TODO: trigger ui cost animation
|
||||
cmds.trigger(PlaySound::CashHeal);
|
||||
}
|
||||
|
||||
let action = heal(cash.cash, hp.get().1 - hp.get().0);
|
||||
|
||||
hp.heal(action.damage_healed);
|
||||
|
||||
cash.cash = cash.cash.saturating_sub(action.cost);
|
||||
|
||||
//TODO: trigger ui cost animation
|
||||
cmds.trigger(PlaySound::CashHeal);
|
||||
}
|
||||
|
||||
fn heal(cash: i32, damage: u32) -> HealAction {
|
||||
|
||||
Reference in New Issue
Block a user