bevy_controls 1.0.0

Bevy controls library
Documentation
use bevy::ecs::system::Query;

use crate::button::button_control::ButtonControl;

pub trait ButtonActionReader<TAction> {
    fn read_action(&mut self, action: TAction) -> bool;
    fn action_just_pressed(&mut self, action: TAction) -> bool;
}

impl<TContext: Sync + Send + 'static, TAction: Sync + Send + 'static + PartialEq>
    ButtonActionReader<TAction> for Query<'_, '_, &mut ButtonControl<TContext, TAction>>
{
    fn read_action(&mut self, action: TAction) -> bool {
        let Some(mut control) = self.iter_mut().find(|c| c.action == action) else {
            return false;
        };

        control.read()
    }

    fn action_just_pressed(&mut self, action: TAction) -> bool {
        let Some(mut control) = self.iter_mut().find(|c| c.action == action) else {
            return false;
        };

        control.just_pressed()
    }
}