Add option check.

This commit is contained in:
Nolan Darilek 2022-05-31 10:17:16 -05:00
parent 1022037efe
commit a26cf344d6

View File

@ -101,31 +101,35 @@ fn update<S>(
for visible in viewers.iter() {
for (icon_entity, mut icon, visibility, parent, mut sound) in icons.iter_mut() {
let entity = if visibility.is_some() {
icon_entity
Some(icon_entity)
} else if parent.is_some() {
Some(**parent.unwrap())
} else {
**parent.unwrap()
None
};
if visible.contains(&entity) {
let looping = sound.looping;
if looping {
sound.state = SoundState::Playing;
} else if let Some(interval) = icon.interval.as_mut() {
interval.tick(time.delta());
if interval.finished() {
if let Some(entity) = entity {
if visible.contains(&entity) {
let looping = sound.looping;
if looping {
sound.state = SoundState::Playing;
interval.reset();
} else if let Some(interval) = icon.interval.as_mut() {
interval.tick(time.delta());
if interval.finished() {
sound.state = SoundState::Playing;
interval.reset();
}
}
let buffer = buffers.get_handle(icon.sound);
sound.looping = icon.interval.is_none();
if sound.buffer != buffer {
sound.buffer = buffer;
}
sound.gain = icon.gain;
sound.pitch = icon.pitch;
sound.reference_distance = icon.reference_distance;
sound.max_distance = icon.max_distance;
sound.rolloff_factor = icon.rolloff_factor;
}
let buffer = buffers.get_handle(icon.sound);
sound.looping = icon.interval.is_none();
if sound.buffer != buffer {
sound.buffer = buffer;
}
sound.gain = icon.gain;
sound.pitch = icon.pitch;
sound.reference_distance = icon.reference_distance;
sound.max_distance = icon.max_distance;
sound.rolloff_factor = icon.rolloff_factor;
} else {
sound.state = SoundState::Stopped;
}