Fetch InputAttr from controller

This commit is contained in:
Joshua Barretto 2021-03-21 19:11:44 +00:00
parent b45df7fe10
commit 003e76113f
6 changed files with 24 additions and 52 deletions

View File

@ -1,6 +1,6 @@
use crate::{
combat::{Attack, AttackDamage, AttackEffect, CombatBuff, CombatEffect, CombatRequirement},
comp::{tool::ToolKind, CharacterState, InputAttr, Melee, StateUpdate},
comp::{tool::ToolKind, CharacterState, Melee, StateUpdate},
states::{
behavior::{CharacterBehavior, JoinData},
utils::*,
@ -189,10 +189,5 @@ impl CharacterBehavior for Data {
}
fn reset_state(data: &Data, join: &JoinData, update: &mut StateUpdate) {
handle_input(
join,
update,
data.static_data.ability_info.input,
InputAttr::default(),
);
handle_input(join, update, data.static_data.ability_info.input);
}

View File

@ -1,7 +1,5 @@
use crate::{
comp::{
Body, CharacterState, Gravity, InputAttr, LightEmitter, ProjectileConstructor, StateUpdate,
},
comp::{Body, CharacterState, Gravity, LightEmitter, ProjectileConstructor, StateUpdate},
event::ServerEvent,
states::{
behavior::{CharacterBehavior, JoinData},
@ -127,10 +125,5 @@ impl CharacterBehavior for Data {
}
fn reset_state(data: &Data, join: &JoinData, update: &mut StateUpdate) {
handle_input(
join,
update,
data.static_data.ability_info.input,
InputAttr::default(),
);
handle_input(join, update, data.static_data.ability_info.input);
}

View File

@ -1,5 +1,5 @@
use crate::{
comp::{CharacterState, InputAttr, StateUpdate},
comp::{CharacterState, StateUpdate},
states::{
behavior::{CharacterBehavior, JoinData},
utils::*,
@ -59,10 +59,5 @@ impl CharacterBehavior for Data {
}
fn reset_state(data: &Data, join: &JoinData, update: &mut StateUpdate) {
handle_input(
join,
update,
data.static_data.ability_info.input,
InputAttr::default(),
);
handle_input(join, update, data.static_data.ability_info.input);
}

View File

@ -1,6 +1,6 @@
use crate::{
combat::{Attack, AttackDamage, AttackEffect, CombatBuff, CombatEffect, CombatRequirement},
comp::{tool::ToolKind, CharacterState, InputAttr, Melee, StateUpdate},
comp::{tool::ToolKind, CharacterState, Melee, StateUpdate},
states::{
behavior::{CharacterBehavior, JoinData},
utils::*,
@ -296,12 +296,7 @@ impl CharacterBehavior for Data {
}
fn reset_state(data: &Data, join: &JoinData, update: &mut StateUpdate) {
handle_input(
join,
update,
data.static_data.ability_info.input,
InputAttr::default(),
);
handle_input(join, update, data.static_data.ability_info.input);
if let CharacterState::ComboMelee(c) = &mut update.character {
c.stage = (data.stage % data.static_data.num_stages) + 1;

View File

@ -1,5 +1,5 @@
use crate::{
comp::{CharacterState, InputAttr, InputKind, StateUpdate},
comp::{CharacterState, InputKind, StateUpdate},
states::{
behavior::{CharacterBehavior, JoinData},
utils::*,
@ -116,7 +116,7 @@ impl CharacterBehavior for Data {
// Done
if let Some((input, stage)) = self.was_combo {
if input_is_pressed(data, input) {
handle_input(data, &mut update, input, InputAttr::default());
handle_input(data, &mut update, input);
// If other states are introduced that progress through stages, add them
// here
if let CharacterState::ComboMelee(c) = &mut update.character {

View File

@ -462,12 +462,7 @@ pub fn handle_jump(data: &JoinData, update: &mut StateUpdate) {
}
}
fn handle_ability(
data: &JoinData,
update: &mut StateUpdate,
input: InputKind,
input_attr: InputAttr,
) {
fn handle_ability(data: &JoinData, update: &mut StateUpdate, input: InputKind) {
let hands = |equip_slot| match data.inventory.equipped(equip_slot).map(|i| i.kind()) {
Some(ItemKind::Tool(tool)) => Some(tool.hands),
_ => None,
@ -521,7 +516,11 @@ fn handle_ability(
data,
matches!(equip_slot, EquipSlot::Offhand),
input,
input_attr,
data.controller
.queued_inputs
.get(&input)
.cloned()
.unwrap_or_default(),
),
)
.into();
@ -530,25 +529,20 @@ fn handle_ability(
}
pub fn handle_ability_input(data: &JoinData, update: &mut StateUpdate) {
if let Some((input, input_attr)) = data
if let Some(input) = data
.controller
.queued_inputs
.iter()
.find(|(i, _)| i.is_ability())
.keys()
.find(|i| i.is_ability())
{
handle_ability(data, update, *input, input_attr.clone());
handle_ability(data, update, *input);
}
}
pub fn handle_input(
data: &JoinData,
update: &mut StateUpdate,
input: InputKind,
input_attr: InputAttr,
) {
pub fn handle_input(data: &JoinData, update: &mut StateUpdate, input: InputKind) {
match input {
InputKind::Primary | InputKind::Secondary | InputKind::Ability(_) => {
handle_ability(data, update, input, input_attr)
handle_ability(data, update, input)
},
InputKind::Roll => handle_dodge_input(data, update),
InputKind::Jump => handle_jump(data, update),
@ -558,8 +552,8 @@ pub fn handle_input(
pub fn attempt_input(data: &JoinData, update: &mut StateUpdate) {
// TODO: look into using first() when it becomes stable
if let Some((input, input_attr)) = data.controller.queued_inputs.iter().next() {
handle_input(data, update, *input, input_attr.clone());
if let Some(input) = data.controller.queued_inputs.keys().next() {
handle_input(data, update, *input);
}
}