use std::time::Duration;
use bevy::prelude::{Reflect, Resource, Vec2};
use bevy::utils::HashMap;
use crate::input_action::InputAction;
use crate::phantom::{Continuous, DualAxis, IAWrp, Pulse, SingleAxis};
use crate::processed::bound_action::BoundAction;
use crate::processed::stateful::{axis_dual, axis_single, continuous, pulse};
#[derive(Debug, Default, Resource, Reflect, Clone)]
pub struct Ineffable {
pub(crate) _contexts: HashMap<String, InputContext>,
pub(crate) groups: HashMap<String, ProcessedBindingGroup>,
}
type ProcessedBindingGroup = Vec<BoundAction>;
type InputContext = Vec<String>;
impl Ineffable {
pub fn direction_2d<I: InputAction>(&self, action: IAWrp<I, DualAxis>) -> Vec2 {
axis_dual::bound_action(self, action)
.map(|bound| bound.value)
.unwrap_or_default()
}
pub fn direction_1d<I: InputAction>(&self, action: IAWrp<I, SingleAxis>) -> f32 {
axis_single::bound_action(self, action)
.map(|bound| bound.value)
.unwrap_or_default()
}
pub fn is_active<I: InputAction>(&self, action: IAWrp<I, Continuous>) -> bool {
continuous::bound_action(self, action).is_some_and(|binding| binding.active)
}
pub fn just_activated<I: InputAction>(&self, action: IAWrp<I, Continuous>) -> bool {
continuous::bound_action(self, action)
.is_some_and(|binding| binding.active && !binding.active_previous_tick)
}
pub fn just_deactivated<I: InputAction>(&self, action: IAWrp<I, Continuous>) -> bool {
continuous::bound_action(self, action)
.is_some_and(|binding| !binding.active && binding.active_previous_tick)
}
pub fn charge_time<I: InputAction>(&self, action: IAWrp<I, Continuous>) -> Option<Duration> {
continuous::bound_action(self, action).and_then(|binding| binding.charging_duration())
}
pub fn just_pulsed<I: InputAction>(&self, action: IAWrp<I, Pulse>) -> bool {
pulse::bound_action(self, action).is_some_and(|binding| binding.just_pulsed)
}
}