From b91561d4fc9c06ade9ec11264df4d7455bca06e2 Mon Sep 17 00:00:00 2001 From: Elijah Voigt Date: Sun, 24 Sep 2023 17:12:27 -0700 Subject: [PATCH] Make systems private, audio stop all button --- src/editor/animation.rs | 14 ++++---- src/editor/assets.rs | 6 ++-- src/editor/audio.rs | 77 +++++++++++++++++++++++++++++++---------- src/editor/camera.rs | 12 +++---- src/editor/font.rs | 16 ++++----- src/editor/gltf.rs | 2 -- src/editor/level.rs | 16 ++++----- src/editor/lighting.rs | 6 ++-- src/editor/mod.rs | 5 ++- src/editor/monologue.rs | 19 +++++----- src/editor/quit.rs | 2 +- src/editor/scene.rs | 8 ++--- src/editor/timeline.rs | 38 ++++++++++---------- 13 files changed, 127 insertions(+), 94 deletions(-) delete mode 100644 src/editor/gltf.rs diff --git a/src/editor/animation.rs b/src/editor/animation.rs index 25995b3..43e3169 100644 --- a/src/editor/animation.rs +++ b/src/editor/animation.rs @@ -8,8 +8,6 @@ impl Plugin for EditorAnimationPlugin { app.add_event::() .add_systems(Update, sync_asset_buttons::) .add_systems(Update, sync_remove_asset_buttons::) - .add_systems(Update, set_epoch_animations) - .add_systems(Update, load_epoch_animations) .add_systems(Update, init_animations_ui) .add_systems(Update, remove_animations_ui) .add_systems(Update, add_animations_ui) @@ -26,7 +24,7 @@ pub struct AnimationWidget; #[derive(Debug, Component)] pub struct AnimationPlayAll; -pub fn init_animations_ui(events: Query>, mut commands: Commands) { +fn init_animations_ui(events: Query>, mut commands: Commands) { events.iter().for_each(|entity| { commands.entity(entity).with_children(|parent| { parent.spawn(( @@ -52,7 +50,7 @@ pub fn init_animations_ui(events: Query>, mut com /// When a new scene is loaded, add any newly compatible animations /// TODO: Add target entity(s) too -pub fn add_animations_ui( +fn add_animations_ui( player_spawned: Query<&Name, Added>, widget: Query>, mut commands: Commands, @@ -82,7 +80,7 @@ pub fn add_animations_ui( } // When a scene is de-selected, remove any outdated animation options -pub fn remove_animations_ui( +fn remove_animations_ui( mut removed_players: RemovedComponents>, current: Query<(Entity, &ui::TargetAsset)>, clips: Res>, @@ -121,7 +119,7 @@ pub enum ControlAnimation { Pause(Handle), } -pub fn play_animation( +fn play_animation( mut events: EventReader, mut targets: Query<(&mut AnimationPlayer, &Name), With>, clips: Res>, @@ -152,7 +150,7 @@ pub fn play_animation( }); } -pub fn play_all_animations( +fn play_all_animations( events: Query< (Entity, &Interaction, Option<&ui::Active>), (With, Changed), @@ -207,7 +205,7 @@ fn ui_control_animations( }); } -pub fn ui_active_animation( +fn ui_active_animation( mut events: EventReader, targets: Query<(Entity, &ui::TargetAsset)>, mut commands: Commands, diff --git a/src/editor/assets.rs b/src/editor/assets.rs index c6ab48e..6724b38 100644 --- a/src/editor/assets.rs +++ b/src/editor/assets.rs @@ -18,7 +18,7 @@ pub struct AssetRegistry(pub Vec); #[derive(Debug, Component)] pub struct ReloadAssets; -pub fn reload_assets( +fn reload_assets( server: Res, mut registry: ResMut, mut writer: EventWriter, @@ -164,7 +164,7 @@ pub fn sync_remove_asset_buttons( .find_map(|this_asset_entity| asset_entities.get(this_asset_entity).ok()) .into_iter() .for_each(|this_handle| { - info!("Syncing removal of {:?}", this_handle); + debug!("Syncing removal of {:?}", this_handle); buttons .iter() .find_map(|(entity, ui::TargetAsset { handle })| { @@ -180,7 +180,7 @@ pub fn sync_remove_asset_buttons( #[derive(Debug, Component)] pub struct ClearAssets; -pub fn clear_assets( +fn clear_assets( asset_holders: Query< Entity, Or<( diff --git a/src/editor/audio.rs b/src/editor/audio.rs index fee5dba..be2324e 100644 --- a/src/editor/audio.rs +++ b/src/editor/audio.rs @@ -10,12 +10,14 @@ impl Plugin for EditorAudioPlugin { fn build(&self, app: &mut App) { app.register_type::() .add_event::() + .add_systems(Update, init_audio_ui) .add_systems(Update, ui_active::) .add_systems(Update, ui_inactive::) .add_systems(Update, sync_asset_buttons::) .add_systems(Update, sync_remove_asset_buttons::) .add_systems(Update, audio_ui) .add_systems(Update, ui_control_audio) + .add_systems(Update, stop_all_audio) .add_systems(Update, control_audio); } } @@ -27,7 +29,34 @@ pub struct AudioRoot; #[derive(Debug, Component, Default)] pub struct AudioWidget; -pub fn audio_ui( +#[derive(Debug, Component)] +struct AudioStopAll; + +fn init_audio_ui(events: Query>, mut commands: Commands) { + events.iter().for_each(|entity| { + commands.entity(entity).with_children(|parent| { + parent.spawn(( + AudioStopAll, + ButtonBundle { + style: Style { + border: UiRect::all(Val::Px(1.0)), + margin: UiRect::all(Val::Px(1.0)), + padding: UiRect::all(Val::Px(1.0)), + ..default() + }, + border_color: Color::BLACK.into(), + ..default() + }, + ui::Title { + text: "Stop All".into(), + ..default() + }, + )); + }); + }) +} + +fn audio_ui( mut events: EventReader>, mut commands: Commands, widget: Query>, @@ -36,7 +65,7 @@ pub fn audio_ui( ) { events.iter().for_each(|event| match event { AssetEvent::Created { handle } => { - info!("Asset created! {:?}", event); + debug!("Audio asset created! {:?}", event); create_asset_button( &widget, &mut commands, @@ -48,7 +77,7 @@ pub fn audio_ui( ); } AssetEvent::Removed { handle } => { - info!("Asset removed! {:?}", event); + debug!("Asset removed! {:?}", event); destroy_asset_button( ¤t, &mut commands, @@ -58,7 +87,7 @@ pub fn audio_ui( ); } AssetEvent::Modified { handle } => { - info!("Asset modified! {:?}", event); + debug!("Asset modified! {:?}", event); destroy_asset_button( ¤t, &mut commands, @@ -85,7 +114,7 @@ pub enum ControlAudio { Stop(Handle), } -pub fn control_audio( +fn control_audio( mut events: EventReader, root: Query>, mut commands: Commands, @@ -93,7 +122,7 @@ pub fn control_audio( ) { events.iter().for_each(|event| match event { ControlAudio::Loop(handle) => { - info!("Looping audio {:?}", handle); + debug!("Looping audio {:?}", handle); let root = if let Ok(entity) = root.get_single() { entity } else { @@ -108,30 +137,24 @@ pub fn control_audio( ..default() }, }); - info!("Done spawning"); + debug!("Done spawning {:?}", handle); }); } ControlAudio::Stop(handle) => { - info!("Stopping audio {:?}", handle); sources .iter() - .find_map(|(entity, source_handle)| { - if source_handle == handle { - Some(entity) - } else { - None - } - }) - .iter() - .for_each(|&entity| { + .find_map(|(entity, source_handle)| (source_handle == handle).then_some(entity)) + .into_iter() + .for_each(|entity| { + debug!("Stopping audio {:?}", handle); commands.entity(entity).despawn_recursive(); - info!("Done despawning"); + debug!("Done despawning {:?}", handle); }); } }); } -pub fn ui_control_audio( +fn ui_control_audio( events: Query< ( &Interaction, @@ -155,3 +178,19 @@ pub fn ui_control_audio( None => writer.send(ControlAudio::Loop(handle.clone())), }); } + +fn stop_all_audio( + events: Query<&Interaction, With>, + targets: Query<&ui::TargetAsset>, + mut writer: EventWriter, +) { + events + .into_iter() + .filter(|&interaction| *interaction == Interaction::Pressed) + .into_iter() + .for_each(|_| { + targets.iter().for_each(|ui::TargetAsset { handle }| { + writer.send(ControlAudio::Stop(handle.clone())); + }); + }); +} diff --git a/src/editor/camera.rs b/src/editor/camera.rs index 09bf18f..7459b6f 100644 --- a/src/editor/camera.rs +++ b/src/editor/camera.rs @@ -19,7 +19,7 @@ pub struct EditorCamera; #[derive(Debug, Component, Default)] pub struct CameraWidget; -pub fn cameras_ui( +fn cameras_ui( mut added: Query<(Entity, &mut Camera, &Name), Added>, mut removed: RemovedComponents, editor_camera: Query>, @@ -28,11 +28,11 @@ pub fn cameras_ui( mut commands: Commands, ) { removed.iter().for_each(|entity| { - info!("Destroy button for {:?}", entity); + debug!("Destroy button for {:?}", entity); destroy_entity_button(¤t, &mut commands, &ui::TargetEntity { entity }); }); added.iter_mut().for_each(|(entity, mut camera, name)| { - info!("Camera added {:?} {:?}", entity, name); + debug!("Camera added {:?} {:?}", entity, name); create_entity_button( &widget, &mut commands, @@ -44,7 +44,7 @@ pub fn cameras_ui( } /// Set the camera active component based on button clicks -pub fn control_active_camera( +fn control_active_camera( events: Query<(Entity, &Camera), Changed>, buttons: Query<(Entity, &ui::TargetEntity)>, mut commands: Commands, @@ -67,7 +67,7 @@ pub fn control_active_camera( }); } -pub fn ui_control_active_camera( +fn ui_control_active_camera( events: Query< (&Interaction, &ui::TargetEntity, Option<&ui::Active>), (With