bevy_controls 1.1.0

Bevy controls library
Documentation
use bevy::prelude::*;

use crate::accumulative::accumulative_input::AccumulativeInputs;

#[derive(Component, Clone, Debug, Reflect)]
pub struct AccumulativeControl<TContext, TAction> {
    pub action: TAction,
    pub contexts: Vec<TContext>,
    pub(crate) value: f32,
    pub(crate) gamepad_value: f32,
    pub mappings: Vec<AccumulativeInputs>,
}

impl<TContext, TAction> AccumulativeControl<TContext, TAction> {
    pub fn new(
        action: TAction,
        contexts: Vec<TContext>,
        mappings: Vec<AccumulativeInputs>,
    ) -> Self {
        Self {
            action,
            contexts,
            mappings,
            value: 0.,
            gamepad_value: 0.,
        }
    }

    pub fn read_delta(&mut self) -> f32 {
        let value = self.value;
        self.value = 0.;
        value
    }

    pub(crate) fn add_input(&mut self, value: f32) {
        self.value += value;
    }

    pub(crate) fn set_gamepade_input(&mut self, value: f32) {
        self.gamepad_value = value;
    }

    pub(crate) fn update_value(&mut self) {
        self.value += self.gamepad_value;
    }
}