Files
shinespark/src/input/keyboard.rs
T
EIREXE aca3886113
CI / build-and-test (push) Successful in 1m24s
CI / production-build (push) Successful in 11m47s
Rework input buffer to match HDR closer (#79)
## Summary

- Preserve distinct same-action bindings in rollback input frames.
- Add independent command lifetimes with tap and state-scoped hold buffering.
- Detect second shield bindings and consume shield commands for air dodge.
- Fix duplicate keyboard mappings being overwritten.

Reviewed-on: #79
Co-authored-by: Álex Román Núñez <eirexe@eirteam.moe>
2026-10-03 09:20:56 +00:00

49 lines
1.9 KiB
Rust

//! Keyboard backend: samples the keys into a [`FighterInputFrame`].
use bevy::prelude::*;
use crate::input::{BaseInputMap, FighterInputFrame, InputActionState, InputMapAction};
use crate::math::int::FGi32;
pub fn sample_keyboard(key: &ButtonInput<KeyCode>, input_map: &BaseInputMap) -> FighterInputFrame {
let mut input_frame = FighterInputFrame::default();
for keyboard_elment in &input_map.keyboard {
let action_state = if key.just_pressed(keyboard_elment.key) {
InputActionState::JustPressed
} else if key.just_released(keyboard_elment.key) {
InputActionState::JustReleased
} else if key.pressed(keyboard_elment.key) {
InputActionState::Pressed
} else {
InputActionState::Released
};
let action_strength = match action_state {
InputActionState::JustPressed | InputActionState::Pressed => FGi32::ONE,
InputActionState::JustReleased | InputActionState::Released => FGi32::ZERO,
};
match keyboard_elment.action {
InputMapAction::MovementXDir(sign) => {
input_frame.movement.x += (sign) * action_strength
}
InputMapAction::MovementYDir(sign) => {
input_frame.movement.y += (sign) * action_strength
}
InputMapAction::Jump | InputMapAction::Shield | InputMapAction::Attack => {
if let Some(action) = keyboard_elment.action.digital_action() {
input_frame.bindings.set(
action,
keyboard_elment.binding_slot,
action_strength != FGi32::ZERO,
);
}
}
}
}
input_frame.movement = input_frame.movement.normalize_or_zero();
input_frame.directional_attack = input_frame.directional_attack.normalize_or_zero();
input_frame
}