style: run cargo fmt
This commit is contained in:
@@ -27,7 +27,10 @@ pub trait ActionInner:
|
||||
{
|
||||
}
|
||||
|
||||
pub trait GameStateInner: 'static + std::marker::Sync + std::marker::Send + States + Default + std::fmt::Debug {}
|
||||
pub trait GameStateInner:
|
||||
'static + std::marker::Sync + std::marker::Send + States + Default + std::fmt::Debug
|
||||
{
|
||||
}
|
||||
|
||||
pub trait InputsContainerInner<A: Action>:
|
||||
'static + std::marker::Sync + std::marker::Send + Resource + Default + std::fmt::Debug
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
pub mod resource;
|
||||
pub mod plugin;
|
||||
pub mod contract;
|
||||
pub mod plugin;
|
||||
pub mod resource;
|
||||
mod util;
|
||||
|
||||
pub use util::*;
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
use bevy_app::{Plugin, App, Update};
|
||||
use bevy_ecs::{system::{Res, ResMut}, schedule::State};
|
||||
use bevy_input::{Input, keyboard::KeyCode, mouse::MouseButton};
|
||||
use bevy_app::{App, Plugin, Update};
|
||||
use bevy_ecs::{
|
||||
schedule::State,
|
||||
system::{Res, ResMut},
|
||||
};
|
||||
use bevy_input::{keyboard::KeyCode, mouse::MouseButton, Input};
|
||||
|
||||
use crate::{resource::*, contract::{Action, GameState, InputsContainer}};
|
||||
use crate::{
|
||||
contract::{Action, GameState, InputsContainer},
|
||||
resource::*,
|
||||
};
|
||||
|
||||
pub struct ControlsPlugin<A, Ic, Gs> {
|
||||
_action: std::marker::PhantomData<A>,
|
||||
@@ -20,13 +26,10 @@ impl<A, Ic, Gs> Default for ControlsPlugin<A, Ic, Gs> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<
|
||||
A: Action,
|
||||
Ic: InputsContainer<A>,
|
||||
Gs: GameState
|
||||
> Plugin for ControlsPlugin<A, Ic, Gs> {
|
||||
impl<A: Action, Ic: InputsContainer<A>, Gs: GameState> Plugin for ControlsPlugin<A, Ic, Gs> {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.init_resource::<Controls<A, Gs>>()
|
||||
app
|
||||
.init_resource::<Controls<A, Gs>>()
|
||||
.init_resource::<Ic>()
|
||||
.add_state::<Gs>()
|
||||
.add_systems(Update, Self::save_input);
|
||||
@@ -34,14 +37,9 @@ impl<
|
||||
#[cfg(feature = "reflect")]
|
||||
app.register_type::<Controls<A, Gs>>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl<
|
||||
A: Action,
|
||||
Ic: InputsContainer<A>,
|
||||
Gs: GameState
|
||||
> ControlsPlugin<A, Ic, Gs> {
|
||||
impl<A: Action, Ic: InputsContainer<A>, Gs: GameState> ControlsPlugin<A, Ic, Gs> {
|
||||
/// Process all hard inputs and bindings to update [`PlayerInputs`]
|
||||
fn save_input(
|
||||
keyboard_input: Res<Input<KeyCode>>,
|
||||
@@ -76,24 +74,19 @@ impl<
|
||||
}
|
||||
inputs.forced_set(*action, false); // FIXME: this is happening on every pass so too frequently
|
||||
}
|
||||
InputType::Mouse(input) => {
|
||||
match input {
|
||||
InputType::Mouse(input) => match input {
|
||||
MouseInput::Axis(_axis) => {
|
||||
todo!();
|
||||
}
|
||||
MouseInput::Button(button) => {
|
||||
if !mouse_input
|
||||
.get_pressed()
|
||||
.any(|b| b == button)
|
||||
{
|
||||
if !mouse_input.get_pressed().any(|b| b == button) {
|
||||
continue 'bindings_loop;
|
||||
}
|
||||
}
|
||||
MouseInput::Wheel(_axis) => {
|
||||
todo!();
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
ButtonCombination::Chord(buttons) => {
|
||||
// If any button in chord is not pressed we skip this `binding`
|
||||
@@ -104,24 +97,19 @@ impl<
|
||||
continue 'bindings_loop;
|
||||
}
|
||||
}
|
||||
InputType::Mouse(input) => {
|
||||
match input {
|
||||
InputType::Mouse(input) => match input {
|
||||
MouseInput::Axis(_axis) => {
|
||||
todo!();
|
||||
}
|
||||
MouseInput::Button(button) => {
|
||||
if !mouse_input
|
||||
.get_pressed()
|
||||
.any(|b| b == button)
|
||||
{
|
||||
if !mouse_input.get_pressed().any(|b| b == button) {
|
||||
continue 'bindings_loop;
|
||||
}
|
||||
}
|
||||
MouseInput::Wheel(_axis) => {
|
||||
todo!();
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,7 +127,6 @@ impl<
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// #[cfg(test)]
|
||||
// mod performance_test {
|
||||
// use crate::{ util::test::{enable_loggings, measure_time, Times}, resource::PlayerInputs};
|
||||
|
||||
@@ -16,7 +16,10 @@ use strum::IntoEnumIterator;
|
||||
#[cfg(feature = "reflect")]
|
||||
use {bevy_ecs::prelude::ReflectResource, bevy_reflect::Reflect};
|
||||
|
||||
use crate::{common_traits_conditions, contract::{Action, GameState}};
|
||||
use crate::{
|
||||
common_traits_conditions,
|
||||
contract::{Action, GameState},
|
||||
};
|
||||
|
||||
/// Validate that all enum variants are in the hash map
|
||||
pub fn validate_hash_map<K, V>(hash_map: &HashMap<K, V>) -> bool
|
||||
@@ -530,7 +533,8 @@ impl<A: Action, Gs: GameState> Controls<A, Gs> {
|
||||
pub fn force_push(&mut self, action: A, binding: Binding<Gs>) {
|
||||
// TODO: warning if config is not exist yet
|
||||
// TODO: interface for [`ActivationOptions`]
|
||||
self.0
|
||||
self
|
||||
.0
|
||||
.entry(action)
|
||||
.or_insert_with(BindingConfig::default)
|
||||
.bindings
|
||||
@@ -541,7 +545,8 @@ impl<A: Action, Gs: GameState> Controls<A, Gs> {
|
||||
pub fn push(&mut self, action: A, binding: Binding<Gs>) {
|
||||
// TODO: warning if config is not exist yet
|
||||
// TODO: interface for [`ActivationOptions`]
|
||||
self.0
|
||||
self
|
||||
.0
|
||||
.entry(action)
|
||||
.or_insert_with(BindingConfig::default)
|
||||
.bindings
|
||||
@@ -551,7 +556,8 @@ impl<A: Action, Gs: GameState> Controls<A, Gs> {
|
||||
/// Remove all bindings for action
|
||||
pub fn remove(&mut self, action: A) {
|
||||
// TODO: warning if config is not exist yet
|
||||
self.0
|
||||
self
|
||||
.0
|
||||
.entry(action)
|
||||
.or_insert_with(BindingConfig::default)
|
||||
.bindings
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
tab_spaces = 2
|
||||
Reference in New Issue
Block a user