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