From 0988b97da5d56b8d4c6a4903ace58192e90969d8 Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 31 Oct 2020 13:44:00 -0500 Subject: [PATCH] Removed most hardcoded ability keys. --- common/src/comp/ability.rs | 5 +++++ common/src/states/charged_melee.rs | 6 ++++-- common/src/states/charged_ranged.rs | 8 +++++--- common/src/states/combo_melee.rs | 8 ++++++-- common/src/states/dash_melee.rs | 10 +++++++--- common/src/states/spin_melee.rs | 9 +++++++-- 6 files changed, 34 insertions(+), 12 deletions(-) diff --git a/common/src/comp/ability.rs b/common/src/comp/ability.rs index 85b819fe95..af635ab264 100644 --- a/common/src/comp/ability.rs +++ b/common/src/comp/ability.rs @@ -452,6 +452,7 @@ impl From<(&CharacterAbility, AbilityKey)> for CharacterState { swing_duration: *swing_duration, recover_duration: *recover_duration, is_interruptible: *is_interruptible, + ability_key: key, }, auto_charge: false, timer: Duration::default(), @@ -489,6 +490,7 @@ impl From<(&CharacterAbility, AbilityKey)> for CharacterState { speed_increase: 1.0 - *speed_increase, max_speed_increase: *max_speed_increase - 1.0, is_interruptible: *is_interruptible, + ability_key: key, }, stage: 1, combo: 0, @@ -552,6 +554,7 @@ impl From<(&CharacterAbility, AbilityKey)> for CharacterState { is_interruptible: *is_interruptible, forward_speed: *forward_speed, num_spins: *num_spins, + ability_key: key, }, timer: Duration::default(), spins_remaining: *num_spins - 1, @@ -583,6 +586,7 @@ impl From<(&CharacterAbility, AbilityKey)> for CharacterState { charge_duration: *charge_duration, swing_duration: *swing_duration, recover_duration: *recover_duration, + ability_key: key, }, stage_section: StageSection::Charge, timer: Duration::default(), @@ -619,6 +623,7 @@ impl From<(&CharacterAbility, AbilityKey)> for CharacterState { projectile_gravity: *projectile_gravity, initial_projectile_speed: *initial_projectile_speed, max_projectile_speed: *max_projectile_speed, + ability_key: key, }, timer: Duration::default(), stage_section: StageSection::Buildup, diff --git a/common/src/states/charged_melee.rs b/common/src/states/charged_melee.rs index ab85f0fa18..9c6216bc84 100644 --- a/common/src/states/charged_melee.rs +++ b/common/src/states/charged_melee.rs @@ -32,6 +32,8 @@ pub struct StaticData { pub swing_duration: Duration, /// How long the state has until exiting pub recover_duration: Duration, + /// What key is used to press ability + pub ability_key: AbilityKey, } #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] @@ -58,7 +60,7 @@ impl CharacterBehavior for Data { match self.stage_section { StageSection::Charge => { - if data.inputs.secondary.is_pressed() + if ability_key_is_pressed(data, self.static_data.ability_key) && update.energy.current() >= self.static_data.energy_cost && self.timer < self.static_data.charge_duration { @@ -81,7 +83,7 @@ impl CharacterBehavior for Data { amount: -(self.static_data.energy_drain as f32 * data.dt.0) as i32, source: EnergySource::Ability, }); - } else if data.inputs.secondary.is_pressed() + } else if ability_key_is_pressed(data, self.static_data.ability_key) && update.energy.current() >= self.static_data.energy_cost { // Maintains charge diff --git a/common/src/states/charged_ranged.rs b/common/src/states/charged_ranged.rs index 58ad57b272..bbd29dee68 100644 --- a/common/src/states/charged_ranged.rs +++ b/common/src/states/charged_ranged.rs @@ -37,6 +37,8 @@ pub struct StaticData { pub projectile_gravity: Option, pub initial_projectile_speed: f32, pub max_projectile_speed: f32, + /// What key is used to press ability + pub ability_key: AbilityKey, } #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] @@ -80,7 +82,7 @@ impl CharacterBehavior for Data { } }, StageSection::Charge => { - if !data.inputs.secondary.is_pressed() && !self.exhausted { + if !ability_key_is_pressed(data, self.static_data.ability_key) && !self.exhausted { let charge_frac = (self.timer.as_secs_f32() / self.static_data.charge_duration.as_secs_f32()) .min(1.0); @@ -138,7 +140,7 @@ impl CharacterBehavior for Data { ..*self }); } else if self.timer < self.static_data.charge_duration - && data.inputs.secondary.is_pressed() + && ability_key_is_pressed(data, self.static_data.ability_key) { // Charges update.character = CharacterState::ChargedRanged(Data { @@ -154,7 +156,7 @@ impl CharacterBehavior for Data { amount: -(self.static_data.energy_drain as f32 * data.dt.0) as i32, source: EnergySource::Ability, }); - } else if data.inputs.secondary.is_pressed() { + } else if ability_key_is_pressed(data, self.static_data.ability_key) { // Holds charge update.character = CharacterState::ChargedRanged(Data { timer: self diff --git a/common/src/states/combo_melee.rs b/common/src/states/combo_melee.rs index d359b8d9ce..df2c6f885d 100644 --- a/common/src/states/combo_melee.rs +++ b/common/src/states/combo_melee.rs @@ -54,6 +54,8 @@ pub struct StaticData { pub max_speed_increase: f32, /// Whether the state can be interrupted by other abilities pub is_interruptible: bool, + /// What key is used to press ability + pub ability_key: AbilityKey, } /// A sequence of attacks that can incrementally become faster and more /// damaging. @@ -84,7 +86,9 @@ impl CharacterBehavior for Data { let stage_index = (self.stage - 1) as usize; // Allows for other states to interrupt this state - if self.static_data.is_interruptible && !data.inputs.primary.is_pressed() { + if self.static_data.is_interruptible + && !ability_key_is_pressed(data, self.static_data.ability_key) + { handle_interrupt(data, &mut update); match update.character { CharacterState::ComboMelee(_) => {}, @@ -183,7 +187,7 @@ impl CharacterBehavior for Data { StageSection::Recover => { if self.timer < self.static_data.stage_data[stage_index].base_recover_duration { // Recovers - if data.inputs.primary.is_pressed() { + if ability_key_is_pressed(data, self.static_data.ability_key) { // Checks if state will transition to next stage after recover update.character = CharacterState::ComboMelee(Data { static_data: self.static_data.clone(), diff --git a/common/src/states/dash_melee.rs b/common/src/states/dash_melee.rs index 6957ee10d2..8e141c2e68 100644 --- a/common/src/states/dash_melee.rs +++ b/common/src/states/dash_melee.rs @@ -39,6 +39,8 @@ pub struct StaticData { pub recover_duration: Duration, /// Whether the state can be interrupted by other abilities pub is_interruptible: bool, + /// What key is used to press ability + pub ability_key: AbilityKey, } #[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] @@ -66,7 +68,9 @@ impl CharacterBehavior for Data { handle_move(data, &mut update, 0.1); // Allows for other states to interrupt this state - if self.static_data.is_interruptible && !data.inputs.secondary.is_pressed() { + if self.static_data.is_interruptible + && !ability_key_is_pressed(data, self.static_data.ability_key) + { handle_interrupt(data, &mut update); match update.character { CharacterState::DashMelee(_) => {}, @@ -90,7 +94,7 @@ impl CharacterBehavior for Data { } else { // Transitions to charge section of stage update.character = CharacterState::DashMelee(Data { - auto_charge: !data.inputs.secondary.is_pressed(), + auto_charge: !ability_key_is_pressed(data, self.static_data.ability_key), timer: Duration::default(), stage_section: StageSection::Charge, ..*self @@ -100,7 +104,7 @@ impl CharacterBehavior for Data { StageSection::Charge => { if (self.static_data.infinite_charge || self.timer < self.static_data.charge_duration) - && (data.inputs.secondary.is_pressed() + && (ability_key_is_pressed(data, self.static_data.ability_key) || (self.auto_charge && self.timer < self.static_data.charge_duration)) && update.energy.current() > 0 { diff --git a/common/src/states/spin_melee.rs b/common/src/states/spin_melee.rs index ffceb6fb03..452bded7b0 100644 --- a/common/src/states/spin_melee.rs +++ b/common/src/states/spin_melee.rs @@ -38,6 +38,8 @@ pub struct StaticData { pub forward_speed: f32, /// Number of spins pub num_spins: u32, + /// What key is used to press ability + pub ability_key: AbilityKey, } #[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] @@ -65,7 +67,9 @@ impl CharacterBehavior for Data { } // Allows for other states to interrupt this state - if self.static_data.is_interruptible && !data.inputs.ability3.is_pressed() { + if self.static_data.is_interruptible + && !ability_key_is_pressed(data, self.static_data.ability_key) + { handle_interrupt(data, &mut update); match update.character { CharacterState::SpinMelee(_) => {}, @@ -140,7 +144,8 @@ impl CharacterBehavior for Data { }); } else if update.energy.current() >= self.static_data.energy_cost && (self.spins_remaining != 0 - || (self.static_data.is_infinite && data.inputs.secondary.is_pressed())) + || (self.static_data.is_infinite + && ability_key_is_pressed(data, self.static_data.ability_key))) { let new_spins_remaining = if self.static_data.is_infinite { self.spins_remaining