|
|
|
@ -1,10 +1,26 @@
|
|
|
|
// Monologue Trees Editor
|
|
|
|
// Monologue Trees Editor
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Editor for creating Monologue Trees levels
|
|
|
|
// Editor for creating Monologue Trees levels
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// TODO:
|
|
|
|
|
|
|
|
// * Tree Organization: GLTF contains Animations and Scenes
|
|
|
|
|
|
|
|
// * Camera can only select one at a time.
|
|
|
|
|
|
|
|
// * (easy) Load audios like current GLTFs
|
|
|
|
|
|
|
|
// * (easy) Loop audio enable/disable
|
|
|
|
|
|
|
|
// * (easy) Better Colorscheme
|
|
|
|
|
|
|
|
// * (easy) Interactive buttons (hover/click)
|
|
|
|
|
|
|
|
// * (medium) Visual errors for bad GLTFs
|
|
|
|
|
|
|
|
// * (medium) Collapsable containers (Gltfs, Animations, Scenes, Audio Clips, Cameras)
|
|
|
|
|
|
|
|
// * (medium) Spawn clicked scene
|
|
|
|
|
|
|
|
// * (medium) Play clicked animation
|
|
|
|
|
|
|
|
// * (idea) Use enum instead of markers for exclusive UI
|
|
|
|
|
|
|
|
|
|
|
|
use bevy::{
|
|
|
|
use bevy::{
|
|
|
|
|
|
|
|
asset::{AssetPath, Assets},
|
|
|
|
|
|
|
|
gltf::Gltf,
|
|
|
|
input::{keyboard::KeyboardInput, ButtonState},
|
|
|
|
input::{keyboard::KeyboardInput, ButtonState},
|
|
|
|
prelude::*,
|
|
|
|
prelude::*,
|
|
|
|
|
|
|
|
utils::HashSet,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
use monologue_trees::{debug::*, ui::*};
|
|
|
|
use monologue_trees::{debug::*, ui::*};
|
|
|
|
|
|
|
|
|
|
|
|
@ -22,24 +38,43 @@ fn main() {
|
|
|
|
DebugInfoPlugin,
|
|
|
|
DebugInfoPlugin,
|
|
|
|
GameUiPlugin,
|
|
|
|
GameUiPlugin,
|
|
|
|
))
|
|
|
|
))
|
|
|
|
|
|
|
|
.init_resource::<AssetRegistry>()
|
|
|
|
.add_systems(Startup, (initialize_ui,))
|
|
|
|
.add_systems(Startup, (initialize_ui,))
|
|
|
|
.add_systems(
|
|
|
|
.add_systems(
|
|
|
|
Update,
|
|
|
|
Update,
|
|
|
|
(
|
|
|
|
(
|
|
|
|
|
|
|
|
// GLTF Systems
|
|
|
|
load_gltf,
|
|
|
|
load_gltf,
|
|
|
|
unload_gltf,
|
|
|
|
unload_gltf,
|
|
|
|
|
|
|
|
manage_gltf_ui,
|
|
|
|
|
|
|
|
// Scene Systems
|
|
|
|
|
|
|
|
manage_scene_ui,
|
|
|
|
|
|
|
|
spawn_scene,
|
|
|
|
|
|
|
|
// Animation systems
|
|
|
|
|
|
|
|
manage_animation_ui,
|
|
|
|
|
|
|
|
// Camera systems
|
|
|
|
|
|
|
|
manage_camera_ui,
|
|
|
|
|
|
|
|
// Audio Systems
|
|
|
|
load_audio,
|
|
|
|
load_audio,
|
|
|
|
unload_audio,
|
|
|
|
unload_audio,
|
|
|
|
spawn_scene,
|
|
|
|
|
|
|
|
play_audio,
|
|
|
|
play_audio,
|
|
|
|
|
|
|
|
// Level Import/Export systems
|
|
|
|
export_level,
|
|
|
|
export_level,
|
|
|
|
import_level,
|
|
|
|
import_level,
|
|
|
|
|
|
|
|
// Misc/Debug Systems
|
|
|
|
load_bogus,
|
|
|
|
load_bogus,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// A generic referenece used for UI elements to point to assets or entities
|
|
|
|
|
|
|
|
#[derive(Debug, Component)]
|
|
|
|
|
|
|
|
enum UiRef<T> {
|
|
|
|
|
|
|
|
Handle(T),
|
|
|
|
|
|
|
|
Entity(T),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// UI:
|
|
|
|
/// UI:
|
|
|
|
/// * GLTFs
|
|
|
|
/// * GLTFs
|
|
|
|
/// * Scenes
|
|
|
|
/// * Scenes
|
|
|
|
@ -62,16 +97,36 @@ fn initialize_ui(mut commands: Commands) {
|
|
|
|
..default()
|
|
|
|
..default()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.with_children(|parent| {
|
|
|
|
.with_children(|parent| {
|
|
|
|
parent.spawn((GameUiList("GLTFs"), NodeBundle { ..default() }, GltfsUi));
|
|
|
|
parent
|
|
|
|
parent.spawn((GameUiList("Scenes"), NodeBundle { ..default() }, ScenesUi));
|
|
|
|
.spawn((
|
|
|
|
parent.spawn((GameUiList("Cameras"), NodeBundle { ..default() }, CamerasUi));
|
|
|
|
GameUiList,
|
|
|
|
|
|
|
|
Name::new("GLTFs"),
|
|
|
|
|
|
|
|
NodeBundle { ..default() },
|
|
|
|
|
|
|
|
GltfsUi,
|
|
|
|
|
|
|
|
))
|
|
|
|
|
|
|
|
.with_children(|parent| {
|
|
|
|
|
|
|
|
parent.spawn((
|
|
|
|
|
|
|
|
GameUiList,
|
|
|
|
|
|
|
|
Name::new("Scenes"),
|
|
|
|
|
|
|
|
NodeBundle { ..default() },
|
|
|
|
|
|
|
|
ScenesUi,
|
|
|
|
|
|
|
|
));
|
|
|
|
parent.spawn((
|
|
|
|
parent.spawn((
|
|
|
|
GameUiList("Animations"),
|
|
|
|
GameUiList,
|
|
|
|
|
|
|
|
Name::new("Cameras"),
|
|
|
|
|
|
|
|
NodeBundle { ..default() },
|
|
|
|
|
|
|
|
CamerasUi,
|
|
|
|
|
|
|
|
));
|
|
|
|
|
|
|
|
parent.spawn((
|
|
|
|
|
|
|
|
GameUiList,
|
|
|
|
|
|
|
|
Name::new("Animations"),
|
|
|
|
NodeBundle { ..default() },
|
|
|
|
NodeBundle { ..default() },
|
|
|
|
AnimationsUi,
|
|
|
|
AnimationsUi,
|
|
|
|
));
|
|
|
|
));
|
|
|
|
|
|
|
|
});
|
|
|
|
parent.spawn((
|
|
|
|
parent.spawn((
|
|
|
|
GameUiSet("Audio Clips"),
|
|
|
|
GameUiSet,
|
|
|
|
|
|
|
|
Name::new("Audio Clips"),
|
|
|
|
NodeBundle { ..default() },
|
|
|
|
NodeBundle { ..default() },
|
|
|
|
AudioClipsUi,
|
|
|
|
AudioClipsUi,
|
|
|
|
));
|
|
|
|
));
|
|
|
|
@ -92,32 +147,195 @@ fn load_bogus(
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.for_each(|_| {
|
|
|
|
.for_each(|_| {
|
|
|
|
commands
|
|
|
|
commands
|
|
|
|
.spawn((GameUiButton("bogus"), NodeBundle { ..default() }))
|
|
|
|
.spawn((GameUiButton, Name::new("bogus"), NodeBundle { ..default() }))
|
|
|
|
.set_parent(root.single());
|
|
|
|
.set_parent(root.single());
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Resource, Default, Debug)]
|
|
|
|
|
|
|
|
struct AssetRegistry(HashSet<HandleUntyped>);
|
|
|
|
|
|
|
|
|
|
|
|
/// Component marking UI for loaded Gltf assets
|
|
|
|
/// Component marking UI for loaded Gltf assets
|
|
|
|
#[derive(Component)]
|
|
|
|
#[derive(Component)]
|
|
|
|
struct GltfsUi;
|
|
|
|
struct GltfsUi;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Drag+Drop import GLTF to editor
|
|
|
|
|
|
|
|
fn load_gltf(
|
|
|
|
|
|
|
|
mut events: EventReader<FileDragAndDrop>,
|
|
|
|
|
|
|
|
server: Res<AssetServer>,
|
|
|
|
|
|
|
|
mut assets: ResMut<AssetRegistry>,
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
events
|
|
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
|
|
.filter_map(|event| match event {
|
|
|
|
|
|
|
|
FileDragAndDrop::DroppedFile { path_buf, .. } => Some(path_buf),
|
|
|
|
|
|
|
|
_ => None,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.for_each(|path_buf| {
|
|
|
|
|
|
|
|
let path = path_buf.as_path();
|
|
|
|
|
|
|
|
let handle = server.load_untyped(path);
|
|
|
|
|
|
|
|
assets.0.insert(handle);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Helper method to extract the stripped filename given a full asset path
|
|
|
|
|
|
|
|
fn get_fname(asset_path: AssetPath, suffixes: &[&str]) -> String {
|
|
|
|
|
|
|
|
let path = asset_path.path().file_name().expect("Filename");
|
|
|
|
|
|
|
|
let path_str = path.to_str().expect("Asset Path to Str");
|
|
|
|
|
|
|
|
let name_str = suffixes
|
|
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
|
|
.rfold(path_str, |acc, &suffix| acc.trim_end_matches(suffix));
|
|
|
|
|
|
|
|
String::from(name_str)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Sync GLTF assets with UI
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// TODO: Handle failed load events
|
|
|
|
|
|
|
|
/// Options:
|
|
|
|
|
|
|
|
/// * Show Error message, do not add to UI
|
|
|
|
|
|
|
|
/// * Add to UI with visual indicator
|
|
|
|
|
|
|
|
/// This should be a separate async system
|
|
|
|
|
|
|
|
fn manage_gltf_ui(
|
|
|
|
|
|
|
|
mut events: EventReader<AssetEvent<Gltf>>,
|
|
|
|
|
|
|
|
root: Query<Entity, With<GltfsUi>>,
|
|
|
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
|
|
|
server: Res<AssetServer>,
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
events
|
|
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
|
|
.filter_map(|event| match event {
|
|
|
|
|
|
|
|
AssetEvent::Created { handle } => {
|
|
|
|
|
|
|
|
let asset_path = server
|
|
|
|
|
|
|
|
.get_handle_path(handle.clone())
|
|
|
|
|
|
|
|
.expect("Fetch Asset Path");
|
|
|
|
|
|
|
|
let name = get_fname(asset_path, &[".gltf", ".glb"]);
|
|
|
|
|
|
|
|
Some((handle.clone(), String::from(name)))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_ => None,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.for_each(|(handle, name)| {
|
|
|
|
|
|
|
|
commands
|
|
|
|
|
|
|
|
.spawn((
|
|
|
|
|
|
|
|
GameUiButton,
|
|
|
|
|
|
|
|
Name::new(name),
|
|
|
|
|
|
|
|
NodeBundle { ..default() },
|
|
|
|
|
|
|
|
GltfsUi,
|
|
|
|
|
|
|
|
UiRef::Handle(handle.clone()),
|
|
|
|
|
|
|
|
))
|
|
|
|
|
|
|
|
.set_parent(root.single());
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Remove gltf from editor
|
|
|
|
|
|
|
|
fn unload_gltf() {}
|
|
|
|
|
|
|
|
|
|
|
|
/// Component marking UI for Scene assets
|
|
|
|
/// Component marking UI for Scene assets
|
|
|
|
#[derive(Component)]
|
|
|
|
#[derive(Component)]
|
|
|
|
struct ScenesUi;
|
|
|
|
struct ScenesUi;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Sync scene assets with UI
|
|
|
|
|
|
|
|
fn manage_scene_ui(
|
|
|
|
|
|
|
|
mut events: EventReader<AssetEvent<Scene>>,
|
|
|
|
|
|
|
|
root: Query<Entity, With<ScenesUi>>,
|
|
|
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
|
|
|
gltfs: Res<Assets<Gltf>>,
|
|
|
|
|
|
|
|
registry: Res<AssetRegistry>,
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
events
|
|
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
|
|
.filter_map(|event| match event {
|
|
|
|
|
|
|
|
AssetEvent::Created { handle } => {
|
|
|
|
|
|
|
|
let name = registry
|
|
|
|
|
|
|
|
.0
|
|
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
|
|
.find_map(
|
|
|
|
|
|
|
|
|gltf_handle| match gltfs.get(&gltf_handle.clone().typed::<Gltf>()) {
|
|
|
|
|
|
|
|
Some(gltf) => {
|
|
|
|
|
|
|
|
gltf.named_scenes.iter().find_map(|(name, scene_handle)| {
|
|
|
|
|
|
|
|
info!(
|
|
|
|
|
|
|
|
"scene_handle({:?}) == handle({:?})",
|
|
|
|
|
|
|
|
scene_handle, handle
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
(scene_handle == handle).then_some(name)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
None => None,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.expect("Find scene name");
|
|
|
|
|
|
|
|
Some((handle.clone(), String::from(name)))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_ => None,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.for_each(|(handle, name)| {
|
|
|
|
|
|
|
|
commands
|
|
|
|
|
|
|
|
.spawn((
|
|
|
|
|
|
|
|
GameUiButton,
|
|
|
|
|
|
|
|
Name::new(name),
|
|
|
|
|
|
|
|
NodeBundle { ..default() },
|
|
|
|
|
|
|
|
ScenesUi,
|
|
|
|
|
|
|
|
UiRef::Handle(handle.clone()),
|
|
|
|
|
|
|
|
))
|
|
|
|
|
|
|
|
.set_parent(root.single());
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Component marking UI for Camera assets
|
|
|
|
/// Component marking UI for Camera assets
|
|
|
|
#[derive(Component)]
|
|
|
|
#[derive(Component)]
|
|
|
|
struct CamerasUi;
|
|
|
|
struct CamerasUi;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn manage_camera_ui() {}
|
|
|
|
|
|
|
|
|
|
|
|
/// Component marking UI for Animation assets
|
|
|
|
/// Component marking UI for Animation assets
|
|
|
|
#[derive(Component)]
|
|
|
|
#[derive(Component)]
|
|
|
|
struct AnimationsUi;
|
|
|
|
struct AnimationsUi;
|
|
|
|
|
|
|
|
|
|
|
|
/// Drag+Drop import GLTF to editor
|
|
|
|
fn manage_animation_ui(
|
|
|
|
fn load_gltf() {}
|
|
|
|
mut events: EventReader<AssetEvent<AnimationClip>>,
|
|
|
|
|
|
|
|
root: Query<Entity, With<AnimationsUi>>,
|
|
|
|
/// Remove gltf from editor
|
|
|
|
mut commands: Commands,
|
|
|
|
fn unload_gltf() {}
|
|
|
|
gltfs: Res<Assets<Gltf>>,
|
|
|
|
|
|
|
|
registry: Res<AssetRegistry>,
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
events
|
|
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
|
|
.filter_map(|event| match event {
|
|
|
|
|
|
|
|
AssetEvent::Created { handle } => {
|
|
|
|
|
|
|
|
let name =
|
|
|
|
|
|
|
|
registry
|
|
|
|
|
|
|
|
.0
|
|
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
|
|
.find_map(|gltf_handle| {
|
|
|
|
|
|
|
|
match gltfs.get(&gltf_handle.clone().typed::<Gltf>()) {
|
|
|
|
|
|
|
|
Some(gltf) => gltf.named_animations.iter().find_map(
|
|
|
|
|
|
|
|
|(name, animation_handle)| {
|
|
|
|
|
|
|
|
info!(
|
|
|
|
|
|
|
|
"animation_handle({:?}) == handle({:?})",
|
|
|
|
|
|
|
|
animation_handle, handle
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
(animation_handle == handle).then_some(name)
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
None => None,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.expect("Find animation name");
|
|
|
|
|
|
|
|
Some((handle.clone(), String::from(name)))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_ => None,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.for_each(|(handle, name)| {
|
|
|
|
|
|
|
|
commands
|
|
|
|
|
|
|
|
.spawn((
|
|
|
|
|
|
|
|
GameUiButton,
|
|
|
|
|
|
|
|
Name::new(name),
|
|
|
|
|
|
|
|
NodeBundle { ..default() },
|
|
|
|
|
|
|
|
AnimationsUi,
|
|
|
|
|
|
|
|
UiRef::Handle(handle.clone()),
|
|
|
|
|
|
|
|
))
|
|
|
|
|
|
|
|
.set_parent(root.single());
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Component marking UI for Audio Clip assets
|
|
|
|
/// Component marking UI for Audio Clip assets
|
|
|
|
#[derive(Component)]
|
|
|
|
#[derive(Component)]
|
|
|
|
|