docs: simplest example
This commit is contained in:
+3
-2
@@ -23,13 +23,14 @@ pub trait ActionInner:
|
||||
+ IntoEnumIterator
|
||||
+ Clone
|
||||
+ Copy
|
||||
+ std::fmt::Debug
|
||||
{
|
||||
}
|
||||
|
||||
pub trait GameStateInner: 'static + std::marker::Sync + std::marker::Send + States + Default {}
|
||||
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
|
||||
'static + std::marker::Sync + std::marker::Send + Resource + Default + std::fmt::Debug
|
||||
{
|
||||
/// The method returning an iterator over references to the PlayerInputs.
|
||||
/// Note: the use of 'a for both the method's lifetime and the returned Iterator's lifetime.
|
||||
|
||||
@@ -63,9 +63,13 @@ impl<
|
||||
}
|
||||
}
|
||||
|
||||
log::trace!("action {:?} in condition", action);
|
||||
|
||||
match &binding.input {
|
||||
ButtonCombination::Single(button) => match button {
|
||||
InputType::Keyboard(key) => {
|
||||
log::trace!("presed?: {:?}", keyboard_input.pressed(*key));
|
||||
log::trace!("active");
|
||||
inputs.forced_set(*action, keyboard_input.pressed(*key));
|
||||
}
|
||||
InputType::Mouse(input) => {
|
||||
@@ -117,6 +121,7 @@ impl<
|
||||
}
|
||||
}
|
||||
|
||||
log::trace!("active");
|
||||
// TODO: should be [`Chord`](ButtonCombination::Chord) only [`Boolean`](InputValue::Boolean) type
|
||||
inputs.forced_set(*action, true);
|
||||
}
|
||||
|
||||
+19
-3
@@ -112,6 +112,7 @@ impl<A: Action> PlayerInputs<A> {
|
||||
panic!("This input is not boolean")
|
||||
}
|
||||
|
||||
// TODO this is must be binding option for non axis inputs
|
||||
/// Returns `true` if current `InputValue` has become `InputValue::Boolean(true)` in this frame
|
||||
/// If input has not same type as `InputValue` on previous frame return `Error()`
|
||||
pub fn get_just_pressed(&self, action: A) -> Result<bool, Box<dyn error::Error>> {
|
||||
@@ -238,7 +239,7 @@ common_traits_conditions! {
|
||||
Tap,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ActivationOptions {
|
||||
/// Manner in which input is registered
|
||||
pub mode: ActivationMode,
|
||||
@@ -388,7 +389,7 @@ impl InputValue {
|
||||
}
|
||||
|
||||
common_traits_conditions! {
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Bindings<Gs: GameState> {
|
||||
/// List of bindings for action
|
||||
#[cfg_attr(feature = "serialize", serde(bound(deserialize = "")))]
|
||||
@@ -415,6 +416,10 @@ impl<Gs: GameState> Bindings<Gs> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn force_push(&mut self, binding: Binding<Gs>) {
|
||||
self.list.push(binding);
|
||||
}
|
||||
|
||||
pub fn push(&mut self, binding: Binding<Gs>) {
|
||||
if self.options == OptionsMode::Immutable {
|
||||
warn!("You try to push binding to immutable bindings");
|
||||
@@ -468,7 +473,7 @@ impl<Gs: GameState> Bindings<Gs> {
|
||||
common_traits_conditions! {
|
||||
/// Contains all bindings for action
|
||||
/// and different activation options
|
||||
#[derive(Default, Clone)]
|
||||
#[derive(Default, Clone, Debug)]
|
||||
pub struct BindingConfig<Gs: GameState> {
|
||||
#[cfg_attr(feature = "serialize", serde(bound(deserialize = "")))]
|
||||
pub bindings: Bindings<Gs>,
|
||||
@@ -517,6 +522,17 @@ impl<A: Action, Gs: GameState> Controls<A, Gs> {
|
||||
self.0.get(&action)
|
||||
}
|
||||
|
||||
/// Forced push new binding for action
|
||||
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
|
||||
.entry(action)
|
||||
.or_insert_with(BindingConfig::default)
|
||||
.bindings
|
||||
.force_push(binding);
|
||||
}
|
||||
|
||||
/// Push new binding for action
|
||||
pub fn push(&mut self, action: A, binding: Binding<Gs>) {
|
||||
// TODO: warning if config is not exist yet
|
||||
|
||||
Reference in New Issue
Block a user