Refactor controls (#14)

* Move controls

* Use system sets

* Use control states for controller

* Unite controls

* move collisions part

* Right deadzone as well

* Remove comment
This commit is contained in:
GitGhillie
2025-03-22 20:32:09 +01:00
committed by GitHub
parent e21efb9bdb
commit f6b640d06c
8 changed files with 555 additions and 582 deletions

33
src/control/mod.rs Normal file
View File

@@ -0,0 +1,33 @@
use bevy::prelude::*;
mod collisions;
pub mod controller;
pub mod controls;
#[derive(SystemSet, Debug, Hash, PartialEq, Eq, Clone)]
enum ControllerSet {
CollectInputs,
ApplyControls,
}
#[derive(Resource, Debug, Clone, Copy, Default, PartialEq)]
pub struct ControlState {
pub move_dir: Vec2,
pub look_dir: Vec2,
pub jump: bool,
pub view_mode: bool,
}
#[derive(Resource, Debug, Default)]
pub struct Controls {
pub keyboard_state: ControlState,
pub gamepad_state: Option<ControlState>,
}
pub fn plugin(app: &mut App) {
app.add_plugins(controls::plugin);
app.configure_sets(
Update,
(ControllerSet::CollectInputs, ControllerSet::ApplyControls).chain(),
);
}