Skip to content

Commit

Permalink
Play animation-related SFX
Browse files Browse the repository at this point in the history
  • Loading branch information
Dove6 committed Aug 23, 2024
1 parent ff2727b commit dc25165
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 84 deletions.
30 changes: 25 additions & 5 deletions pixlib/src/plugins/sounds_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ fn assign_pool(
) {
let mut bgm_assigned = false;
let mut sound_counter = 0;
let animation_sfx_counter = 0;
let mut animation_sfx_counter = 0;
let mut iter = query.iter_mut();
// info!("Current scene: {:?}", runner.get_current_scene());
if let Some(current_scene) = runner.get_current_scene() {
Expand All @@ -243,6 +243,19 @@ fn assign_pool(
sound_counter += 1;
}
}
for script in runner.scripts.borrow().iter() {
for object in
script.objects.borrow().iter().filter(|o| {
Into::<Option<&classes::Animation>>::into(&*o.content.borrow()).is_some()
})
{
**iter.next().unwrap() = Some(SoundSource::AnimationSfx {
script_path: script.path.clone(),
object_name: object.name.clone(),
});
animation_sfx_counter += 1;
}
}
pool_query.single_mut().state = PoolState::Assigned;
info!(
"Assigned {} background music, {} sounds and {} animation SFX",
Expand Down Expand Up @@ -305,18 +318,22 @@ fn update_sounds(
SoundEvent::SoundResumed(source) => source,
SoundEvent::SoundStopped(source) => source,
};
if reloaded_sources.contains(evt_source) {
if reloaded_sources.contains(evt_source)
&& !matches!(&evt.event, SoundEvent::SoundLoaded { .. })
{
continue;
}
evt.mark_as_processed();
// info!("Read sound event: {}", evt.0);
info!("Read sound event: {}", evt.event);
let mut any_marker_matched = false;
for (marker, mut ident, mut handle, mut state) in query.iter_mut() {
let Some(snd_source) = &**marker else {
continue;
};
if evt_source != snd_source {
continue;
}
any_marker_matched = true;
// info!("Matched the sounds pool element");
match &evt.event {
SoundEvent::SoundLoaded { sound_data, .. } => {
Expand All @@ -338,7 +355,7 @@ fn update_sounds(
ident.0 = Some(sound_data.hash);
state.position = Some(0.0);
reloaded_sources.insert(evt_source.clone());
// info!("Updated data for sound {:?}", snd_source);
info!("Updated data for sound {:?}", snd_source);
}
}
_ => {
Expand All @@ -351,7 +368,7 @@ fn update_sounds(
match &evt.event {
SoundEvent::SoundStarted(_) => {
instance.resume(EASING);
// info!("Started sound {:?}", snd_source);
info!("Started sound {:?}", snd_source);
}
SoundEvent::SoundPaused(_) => {
instance.pause(EASING);
Expand All @@ -372,5 +389,8 @@ fn update_sounds(
}
};
}
if !any_marker_matched {
error!("No marker matched for event {}", evt.event);
}
}
}
Loading

0 comments on commit dc25165

Please sign in to comment.