If any source components exist on a sound without a source, assume the source should be created there and skip ancestry checks.

This commit is contained in:
Nolan Darilek 2022-09-05 13:36:36 -05:00
parent fe63521737
commit ed38b30843

View File

@ -294,19 +294,56 @@ fn add_generator(
fn add_sound_without_source( fn add_sound_without_source(
mut commands: Commands, mut commands: Commands,
query: Query<Entity, (Added<Sound>, Without<Source>)>, query: Query<
(
Entity,
Option<&PannerStrategy>,
Option<&AngularPan>,
Option<&ScalarPan>,
Option<&DistanceModel>,
Option<&DistanceRef>,
Option<&DistanceMax>,
Option<&Rolloff>,
Option<&ClosenessBoost>,
Option<&ClosenessBoostDistance>,
),
(Added<Sound>, Without<Source>),
>,
parents: Query<&Parent>, parents: Query<&Parent>,
sources: Query<&Source>, sources: Query<&Source>,
) { ) {
for entity in &query { for (
entity,
panner_strategy,
scalar_pan,
angular_pan,
distance_model,
distance_ref,
distance_max,
rolloff,
closeness_boost,
closeness_boost_distance,
) in &query
{
let mut has_source = false; let mut has_source = false;
let mut target = entity; let mut target = entity;
while let Ok(parent) = parents.get(target) { if panner_strategy.is_none()
if sources.get(**parent).is_ok() { && angular_pan.is_none()
has_source = true; && scalar_pan.is_none()
break; && distance_model.is_none()
&& distance_ref.is_none()
&& distance_max.is_none()
&& rolloff.is_none()
&& closeness_boost.is_none()
&& closeness_boost_distance.is_none()
{
while let Ok(parent) = parents.get(target) {
if sources.get(**parent).is_ok() {
has_source = true;
break;
}
target = **parent;
} }
target = **parent;
} }
if !has_source { if !has_source {
commands.entity(entity).insert(Source::default()); commands.entity(entity).insert(Source::default());