use bevy_ecs::entity_disabling::Disabled;
use bevy_ecs::prelude::*;
use bevy_enhanced_input::prelude::Actions;
pub(crate) fn disable_context_actions<C: Component>(
trigger: On<Add, Disabled>,
mut commands: Commands,
contexts: Query<&Actions<C>, (With<C>, Allow<Disabled>)>,
) {
let Ok(actions) = contexts.get(trigger.entity) else {
return;
};
for action in actions.iter() {
commands.entity(action).insert(Disabled);
}
}
pub(crate) fn enable_context_actions<C: Component>(
trigger: On<Remove, Disabled>,
mut commands: Commands,
contexts: Query<&Actions<C>, (With<C>, Allow<Disabled>)>,
) {
let Ok(actions) = contexts.get(trigger.entity) else {
return;
};
for action in actions.iter() {
commands.entity(action).remove::<Disabled>();
}
}