Retihnking this epoch stuff...

main
Elijah Voigt 2 years ago
parent b91561d4fc
commit 53a390320f

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

Loading…
Cancel
Save