Refactor state system
This commit is contained in:
+1
-1
@@ -5,7 +5,7 @@ use crate::input::player::InputFrame;
|
||||
use super::player::{FighterInput, BaseInputMap, InputActionState};
|
||||
|
||||
pub fn postprocess_input(input_state: Query<&mut FighterInput>) {
|
||||
for mut player_input in input_state {
|
||||
for _player_input in input_state {
|
||||
}
|
||||
}
|
||||
pub fn preprocess_keyboard_input(key: Res<ButtonInput<KeyCode>>, input_map: Res<BaseInputMap>, mut input_state: Query<&mut FighterInput>) {
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
pub mod player;
|
||||
pub mod logic;
|
||||
pub mod plugin;
|
||||
+10
-4
@@ -1,23 +1,28 @@
|
||||
use std::collections::VecDeque;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use arrayvec::ArrayVec;
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
#[derive(Default, Clone, Debug)]
|
||||
pub struct InputFrame {
|
||||
pub movement: Vec2,
|
||||
pub directional_attack: Vec2
|
||||
}
|
||||
|
||||
#[derive(Component, Default)]
|
||||
#[derive(Component)]
|
||||
pub struct FighterInput {
|
||||
input_buffer: VecDeque<InputFrame>
|
||||
}
|
||||
|
||||
impl Default for FighterInput {
|
||||
fn default() -> Self {
|
||||
Self { input_buffer: vec!(InputFrame::default()).into() }
|
||||
}
|
||||
}
|
||||
|
||||
impl FighterInput {
|
||||
const INPUT_BUFFER_SIZE: usize = 5;
|
||||
pub fn get_last_frame(&self) -> Option<&InputFrame> {
|
||||
self.input_buffer.back()
|
||||
Some(self.input_buffer.back().unwrap())
|
||||
}
|
||||
|
||||
pub fn push_input_frame(&mut self, frame: InputFrame) {
|
||||
@@ -28,6 +33,7 @@ impl FighterInput {
|
||||
}
|
||||
|
||||
pub fn clear_buffer(&mut self) {
|
||||
info!("CLEAR");
|
||||
while self.input_buffer.len() > 1 {
|
||||
self.input_buffer.pop_front();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use bevy::prelude::*;
|
||||
use crate::fighter::*;
|
||||
use crate::input::player::{ControlledBy, Controls, FighterInput};
|
||||
use crate::input::{
|
||||
logic::{postprocess_input, preprocess_keyboard_input}, player::{BaseInputMap, InputMapAction, KeyboardInputMapElement},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user