From 36605781e8bb82c975217fcdc69fe05239306b11 Mon Sep 17 00:00:00 2001 From: Elijah Voigt Date: Fri, 8 Sep 2023 11:48:53 -0700 Subject: [PATCH] Added quit button, working on level import/export --- assets/output.scn.ron | 21 +++-- bin/editor.rs | 187 ++++++++++++++++++++++++++++++------------ 2 files changed, 149 insertions(+), 59 deletions(-) diff --git a/assets/output.scn.ron b/assets/output.scn.ron index 9442783..8059569 100644 --- a/assets/output.scn.ron +++ b/assets/output.scn.ron @@ -42,12 +42,21 @@ ), )), "editor::LevelRoot": (), - "bevy_hierarchy::components::children::Children": ([ - 198, - ]), }, ), - 198: ( + 2: ( + components: { + "editor::AudioRoot": (), + }, + ), + 191: ( + components: { + "bevy_asset::handle::Handle": ( + id: AssetPathId(((3014684909402542266), (8823233378563626002))), + ), + }, + ), + 200: ( components: { "bevy_render::view::visibility::Visibility": Inherited, "bevy_transform::components::transform::Transform": ( @@ -87,10 +96,6 @@ z: 0.0, ), )), - "bevy_hierarchy::components::parent::Parent": (1), - "bevy_hierarchy::components::children::Children": ([ - 199, - ]), "bevy_asset::handle::Handle": ( id: AssetPathId(((13241355290950327508), (2370051114748836591))), ), diff --git a/bin/editor.rs b/bin/editor.rs index a7d1ebd..62c802f 100644 --- a/bin/editor.rs +++ b/bin/editor.rs @@ -3,6 +3,21 @@ // Editor for creating Monologue Trees levels // // BUGS: +// * When Handle is loaded, the button for TargetAsset should load as well +// * Exported level should preserve active camera +// * Picking new GLTF resets audio without resetting buttons +// * Error with exported scene w/ animation: +// WARN bevy_asset::asset_server: encountered an error while loading an asset: +// no registration found for type +// `alloc::vec::Vec< +// alloc::vec::Vec< +// core::option::Option< +// bevy_ecs::entity::Entity +// >>>` +// at output.scn.ron:723:23 +// This is the `path_cache` field on an Animation +// ... +// Also many other components out of the box just straight up don't work... // // TODO: // * edit textbox with actions @@ -16,6 +31,7 @@ use bevy::{ asset::{Asset, AssetLoader, Assets, ChangeWatcher, LoadContext, LoadedAsset}, audio::PlaybackMode, + core_pipeline::tonemapping::DebandDither, gltf::Gltf, prelude::*, utils::{BoxedFuture, Duration}, @@ -56,11 +72,13 @@ fn main() { }, )) .register_type::() + .register_type::() .init_resource::() .init_resource::() .add_asset::() .init_asset_loader::() .add_systems(Startup, (initialize_ui, init_texts_ui, welcome_message)) + .add_systems(Update, quit.run_if(ui::activated::)) .add_systems( Update, ( @@ -111,7 +129,10 @@ fn main() { level_ui, load_level, export_level.run_if(ui::activated::), - rehydrate_level, + rehydrate_level::, + rehydrate_level::, PlaybackSettings>, + //rehydrate_level::, AnimationPlayer>, + //rehydrate_level::, ), ) .run(); @@ -127,12 +148,17 @@ pub struct TabRoot; #[reflect(Component)] pub struct LevelRoot; +#[derive(Debug, Component, Reflect, Default)] +#[reflect(Component)] +pub struct AudioRoot; + #[derive(Debug, Component)] pub struct EditorCamera; fn initialize_ui(mut commands: Commands) { // Empty entity for populating the level being edited - commands.spawn((SpatialBundle { ..default() }, LevelRoot::default())); + commands.spawn((SpatialBundle { ..default() }, LevelRoot)); + commands.spawn(AudioRoot); commands.spawn(( Camera2dBundle { ..default() }, @@ -372,7 +398,16 @@ fn initialize_ui(mut commands: Commands) { ClearLevel, ui::Sorting(3), ui::Title { - text: "Reset Level".into(), + text: "Clear Level".into(), + ..default() + }, + )); + parent.spawn(( + simple_button.clone(), + QuitAction, + ui::Sorting(3), + ui::Title { + text: "Quit".into(), ..default() }, )); @@ -446,7 +481,7 @@ mod audio { events.iter().for_each(|event| match event { AssetEvent::Created { handle } => { info!("Asset created! {:?}", event); - let id = create_asset_button( + create_asset_button( &widget, &mut commands, ui::TargetAsset { @@ -455,14 +490,6 @@ mod audio { get_asset_name(&server, handle.clone()), None, ); - commands.entity(id).insert(AudioSourceBundle { - source: handle.clone(), - settings: PlaybackSettings { - mode: PlaybackMode::Loop, - paused: true, - ..default() - }, - }); } AssetEvent::Removed { handle } => { info!("Asset removed! {:?}", event); @@ -483,7 +510,7 @@ mod audio { handle: handle.clone(), }, ); - let id = create_asset_button( + create_asset_button( &widget, &mut commands, ui::TargetAsset { @@ -492,30 +519,56 @@ mod audio { get_asset_name(&server, handle.clone()), None, ); - commands.entity(id).insert(AudioSourceBundle { + } + }); + } + + pub fn play_audio( + events: Query<&ui::TargetAsset, (With