bevy_yoleck/
picking_helpers.rs

1use bevy::prelude::*;
2use uuid::Uuid;
3
4use crate::exclusive_systems::YoleckExclusiveSystemDirective;
5use crate::prelude::*;
6
7/// Transforms an entity to its UUID. Meant to be used with [Yoleck's exclusive edit
8/// systems](crate::exclusive_systems::YoleckExclusiveSystemsQueue) and with Bevy's system piping.
9///
10/// It accepts and returns an `Option` because it is meant to be used with
11/// [`vpeol_read_click_on_entity`](crate::vpeol::vpeol_read_click_on_entity).
12pub fn yoleck_map_entity_to_uuid(
13    In(entity): In<Option<Entity>>,
14    uuid_query: Query<&YoleckEntityUuid>,
15) -> Option<Uuid> {
16    Some(uuid_query.get(entity?).ok()?.get())
17}
18
19/// Pipe an [exclusive system](crate::exclusive_systems::YoleckExclusiveSystemsQueue) into this
20/// system to make it cancellable by either pressing the Escape key or clicking on a button in the
21/// UI.
22pub fn yoleck_exclusive_system_cancellable(
23    In(directive): In<YoleckExclusiveSystemDirective>,
24    mut ui: ResMut<YoleckUi>,
25    keyboard: Res<ButtonInput<KeyCode>>,
26) -> YoleckExclusiveSystemDirective {
27    if matches!(directive, YoleckExclusiveSystemDirective::Finished) {
28        return directive;
29    }
30
31    if keyboard.just_released(KeyCode::Escape) || ui.button("Abort Entity Selection").clicked() {
32        return YoleckExclusiveSystemDirective::Finished;
33    }
34
35    directive
36}