pub mod audio; pub mod assets; use crate::ui; use bevy::{asset::Asset, prelude::*}; pub fn ui_active( events: Query<&Handle, Added>>, buttons: Query<(Entity, &ui::TargetAsset)>, mut commands: Commands, ) { events.iter().for_each(|this_handle| { buttons .iter() .find_map(|(entity, ui::TargetAsset { handle })| { if handle == this_handle { Some(entity) } else { None } }) .and_then(|entity| { commands.entity(entity).insert(ui::Active); Some(()) }); }); } pub fn ui_inactive( mut events: RemovedComponents>, targets: Query<(Entity, &ui::TargetAsset), With>, sources: Query<&Handle>, mut commands: Commands, ) { events.iter().for_each(|_| { targets .iter() .find_map(|(entity, ui::TargetAsset { handle })| { (!sources.iter().any(|this_handle| this_handle == handle)).then_some(entity) }) .and_then(|entity| { commands.entity(entity).remove::(); Some(()) }); }); }