You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.3 KiB
Rust

pub mod audio;
pub mod assets;
use crate::ui;
use bevy::{asset::Asset, prelude::*};
pub fn ui_active<T: Asset>(
events: Query<&Handle<T>, Added<Handle<T>>>,
buttons: Query<(Entity, &ui::TargetAsset<T>)>,
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<T: Asset>(
mut events: RemovedComponents<Handle<T>>,
targets: Query<(Entity, &ui::TargetAsset<T>), With<ui::Active>>,
sources: Query<&Handle<T>>,
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::<ui::Active>();
Some(())
});
});
}