Fix crashes caused by non-existent entities.
This commit is contained in:
parent
6d6ff3ae23
commit
3202956719
41
src/sound.rs
41
src/sound.rs
|
@ -6,6 +6,7 @@ use bevy_openal::{Buffer, Context, Sound, SoundState};
|
|||
use rand::random;
|
||||
|
||||
use crate::{
|
||||
commands::RunIfExistsExt,
|
||||
core::{Coordinates, CoreConfig, Player, PointLike},
|
||||
exploration::ExplorationFocused,
|
||||
visibility::{Viewshed, VisibleEntities},
|
||||
|
@ -91,11 +92,14 @@ fn add_footstep_sounds(
|
|||
) {
|
||||
for (entity, footstep) in footsteps.iter() {
|
||||
let buffer = assets.get_handle(footstep.sound);
|
||||
commands.entity(entity).insert(Sound {
|
||||
buffer,
|
||||
state: SoundState::Stopped,
|
||||
gain: footstep.gain,
|
||||
..Default::default()
|
||||
let gain = footstep.gain;
|
||||
commands.run_if_exists(entity, move |mut entity| {
|
||||
entity.insert(Sound {
|
||||
buffer,
|
||||
state: SoundState::Stopped,
|
||||
gain,
|
||||
..Default::default()
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -138,17 +142,24 @@ fn add_sound_icon_sounds(
|
|||
) {
|
||||
for (entity, icon) in icons.iter() {
|
||||
let buffer = assets.get_handle(icon.sound);
|
||||
let gain = icon.gain;
|
||||
let pitch = icon.pitch;
|
||||
let looping = icon.interval.is_none();
|
||||
commands.entity(entity).insert(Sound {
|
||||
buffer,
|
||||
gain: icon.gain,
|
||||
pitch: icon.pitch,
|
||||
looping,
|
||||
state: SoundState::Stopped,
|
||||
reference_distance: icon.reference_distance,
|
||||
max_distance: icon.max_distance,
|
||||
rolloff_factor: icon.rolloff_factor,
|
||||
..Default::default()
|
||||
let reference_distance = icon.reference_distance;
|
||||
let max_distance = icon.max_distance;
|
||||
let rolloff_factor = icon.rolloff_factor;
|
||||
commands.run_if_exists(entity, move |mut entity| {
|
||||
entity.insert(Sound {
|
||||
buffer,
|
||||
gain,
|
||||
pitch,
|
||||
looping,
|
||||
state: SoundState::Stopped,
|
||||
reference_distance,
|
||||
max_distance,
|
||||
rolloff_factor,
|
||||
..Default::default()
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user