|
|
|
|
@ -6,8 +6,7 @@ pub struct EditorTimelinePlugin;
|
|
|
|
|
impl Plugin for EditorTimelinePlugin {
|
|
|
|
|
fn build(&self, app: &mut App) {
|
|
|
|
|
app.add_systems(Update, add_timeline_epoch.run_if(ui::activated::<AddEpoch>))
|
|
|
|
|
.add_systems(Update, set_epoch_gltf)
|
|
|
|
|
.add_systems(Update, load_epoch_gltf)
|
|
|
|
|
.add_systems(Update, control_active_epoch)
|
|
|
|
|
.add_systems(Update, set_epoch_scene)
|
|
|
|
|
.add_systems(Update, load_epoch_scene)
|
|
|
|
|
.add_systems(Update, set_epoch_camera)
|
|
|
|
|
@ -29,6 +28,12 @@ impl Plugin for EditorTimelinePlugin {
|
|
|
|
|
#[derive(Debug, Component)]
|
|
|
|
|
pub struct TimelineWidget;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Resource)]
|
|
|
|
|
struct ActiveEpoch {
|
|
|
|
|
id: EpochId,
|
|
|
|
|
entity: Entity,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Add Epoch component, used on a button to trigger a new epoch addition
|
|
|
|
|
#[derive(Debug, Component)]
|
|
|
|
|
pub struct AddEpoch;
|
|
|
|
|
@ -39,12 +44,6 @@ pub struct EpochId {
|
|
|
|
|
id: usize,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Epoch GLTF Component
|
|
|
|
|
#[derive(Debug, Reflect, Component, Clone)]
|
|
|
|
|
pub struct EpochGltf {
|
|
|
|
|
gltf: Handle<Gltf>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Epoch Scene Component
|
|
|
|
|
#[derive(Debug, Reflect, Component, Clone)]
|
|
|
|
|
pub struct EpochScene {
|
|
|
|
|
@ -87,6 +86,18 @@ pub struct EpochAnimations {
|
|
|
|
|
animations: Vec<Handle<AnimationClip>>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn control_active_epoch(
|
|
|
|
|
events: Query<(Entity, &EpochId), Added<ui::Active>>,
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
) {
|
|
|
|
|
events.iter().for_each(|(entity, &ref id)| {
|
|
|
|
|
commands.insert_resource(ActiveEpoch {
|
|
|
|
|
id: id.clone(),
|
|
|
|
|
entity,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// System for adding an epoch to the level's timeline
|
|
|
|
|
/// Triggered when a button with the AddEpoch marker is Active
|
|
|
|
|
fn add_timeline_epoch(
|
|
|
|
|
@ -120,53 +131,33 @@ fn add_timeline_epoch(
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Set the GLTF for the current epoch
|
|
|
|
|
fn set_epoch_gltf(
|
|
|
|
|
events: Query<&ui::TargetAsset<Gltf>, Added<ui::Active>>,
|
|
|
|
|
active_epoch: Query<Entity, (With<ui::Active>, With<EpochId>)>,
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
) {
|
|
|
|
|
// Each time a GLTF is selected in the editor
|
|
|
|
|
events.iter().for_each(|ui::TargetAsset { handle }| {
|
|
|
|
|
// Iterate over all (0 or 1) active epochs
|
|
|
|
|
active_epoch.iter().for_each(|entity| {
|
|
|
|
|
// Set the GLTF (overwrite existing GLTF selections)
|
|
|
|
|
commands.entity(entity).insert(EpochGltf {
|
|
|
|
|
gltf: handle.clone(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// TODO: Unset Scene, Camera, Animations
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn load_epoch_gltf(events: Query<Option<&EpochGltf>, (Added<ui::Active>, With<EpochId>)>) {
|
|
|
|
|
events.iter().for_each(|epoch_gltf| {
|
|
|
|
|
warn!("TODO: Load epoch GLTF!");
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn set_epoch_scene(
|
|
|
|
|
events: Query<&ui::TargetAsset<Scene>, Added<ui::Active>>,
|
|
|
|
|
active_epoch: Query<Entity, (With<ui::Active>, With<EpochId>)>,
|
|
|
|
|
mut events: EventReader<ControlScene>,
|
|
|
|
|
active_epoch: Option<Res<ActiveEpoch>>,
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
) {
|
|
|
|
|
// Each time a Scene is selected in the editor
|
|
|
|
|
events.iter().for_each(|ui::TargetAsset { handle }| {
|
|
|
|
|
// Iterate over all (0 or 1) active epochs
|
|
|
|
|
active_epoch.iter().for_each(|entity| {
|
|
|
|
|
events.iter().for_each(|event| {
|
|
|
|
|
active_epoch.iter().for_each(|active| {
|
|
|
|
|
match event {
|
|
|
|
|
ControlScene::Spawn(handle) => {
|
|
|
|
|
// Set the Scene (overwrite existing Scene selections)
|
|
|
|
|
commands.entity(entity).insert(EpochScene {
|
|
|
|
|
commands.entity(active.entity).insert(EpochScene {
|
|
|
|
|
scene: handle.clone(),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
ControlScene::Despawn(_) => (),
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn load_epoch_scene(events: Query<Option<&EpochScene>, (Added<ui::Active>, With<EpochId>)>) {
|
|
|
|
|
events.iter().for_each(|epoch_scene| {
|
|
|
|
|
fn load_epoch_scene(active_epoch: Option<Res<ActiveEpoch>>) {
|
|
|
|
|
if let Some(active) = active_epoch {
|
|
|
|
|
if active.is_added() || active.is_changed() {
|
|
|
|
|
warn!("TODO: Load epoch Scene!");
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn set_epoch_camera(
|
|
|
|
|
@ -186,10 +177,12 @@ fn set_epoch_camera(
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn load_epoch_camera(events: Query<Option<&EpochCamera>, (Added<ui::Active>, With<EpochId>)>) {
|
|
|
|
|
events.iter().for_each(|epoch_camera| {
|
|
|
|
|
fn load_epoch_camera(active_epoch: Option<Res<ActiveEpoch>>) {
|
|
|
|
|
if let Some(active) = active_epoch {
|
|
|
|
|
if active.is_added() || active.is_changed() {
|
|
|
|
|
warn!("TODO: Load epoch Camera");
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn set_epoch_music(
|
|
|
|
|
@ -209,10 +202,12 @@ fn set_epoch_music(
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn load_epoch_music(events: Query<Option<&EpochMusic>, (Added<ui::Active>, With<EpochId>)>) {
|
|
|
|
|
events.iter().for_each(|epoch_music| {
|
|
|
|
|
fn load_epoch_music(active_epoch: Option<Res<ActiveEpoch>>) {
|
|
|
|
|
if let Some(active) = active_epoch {
|
|
|
|
|
if active.is_added() || active.is_changed() {
|
|
|
|
|
warn!("TODO: Load epoch music!");
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn set_epoch_monologue(
|
|
|
|
|
@ -272,15 +267,17 @@ fn load_epoch_font(
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn set_epoch_sfx(
|
|
|
|
|
events: Query<&ui::TargetAsset<AudioSource>, Added<ui::Active>>,
|
|
|
|
|
mut events: EventReader<ControlAudio>,
|
|
|
|
|
mut active_epoch: Query<(Entity, Option<&mut EpochSfx>), (With<ui::Active>, With<EpochId>)>,
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
) {
|
|
|
|
|
// Each time a Scene is selected in the editor
|
|
|
|
|
events.iter().for_each(|ui::TargetAsset { handle }| {
|
|
|
|
|
events.iter().for_each(|event| {
|
|
|
|
|
// Iterate over all (0 or 1) active epochs
|
|
|
|
|
active_epoch.iter_mut().for_each(|(entity, maybe_sfx)| {
|
|
|
|
|
info!("Adding sfx {:?} to epoch {:?}", maybe_sfx, entity);
|
|
|
|
|
match event {
|
|
|
|
|
ControlAudio::Loop(handle) => {
|
|
|
|
|
debug!("Adding sfx {:?} to epoch {:?}", handle, entity);
|
|
|
|
|
if let Some(mut epoch_sfx) = maybe_sfx {
|
|
|
|
|
epoch_sfx.sfx.push(handle.clone());
|
|
|
|
|
} else {
|
|
|
|
|
@ -289,6 +286,14 @@ fn set_epoch_sfx(
|
|
|
|
|
sfx: vec![handle.clone()],
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ControlAudio::Stop(handle) => {
|
|
|
|
|
if let Some(mut epoch_sfx) = maybe_sfx {
|
|
|
|
|
debug!("Removing sfx {:?} from epoch {:?}", handle, entity);
|
|
|
|
|
epoch_sfx.sfx.retain(|element| element != handle);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|