No longer concern ourselves with transforms when dynamically creating sources.

This commit is contained in:
Nolan Darilek 2022-09-05 10:37:35 -05:00
parent 7906d93277
commit 72c63af910

View File

@ -294,44 +294,22 @@ fn add_generator(
fn add_sound_without_source( fn add_sound_without_source(
mut commands: Commands, mut commands: Commands,
query: Query< query: Query<Entity, (Added<Sound>, Without<Source>)>,
(Entity, Option<&Parent>, Option<&GlobalTransform>),
(Added<Sound>, Without<Source>),
>,
parents: Query<&Parent>, parents: Query<&Parent>,
sources: Query<&Source>, sources: Query<&Source>,
transforms: Query<&GlobalTransform>,
) { ) {
for (entity, parent, transform) in &query { for entity in &query {
let should_check_for_transform = transform.is_none(); let mut has_source = false;
let mut has_transform = false; let mut target = entity;
let source = if let Some(parent) = parent { while let Ok(parent) = parents.get(target) {
if should_check_for_transform { if sources.get(**parent).is_ok() {
has_transform = transforms.get(**parent).is_ok(); has_source = true;
} break;
let mut target = None;
let mut parent: Option<&Parent> = Some(parent);
while let Some(p) = parent {
if should_check_for_transform && !has_transform {
has_transform = transforms.get(**p).is_ok();
}
if sources.get(**p).is_ok() {
target = Some(**p);
break;
}
parent = parents.get(**p).ok();
}
target.map(|v| sources.get(v).unwrap())
} else {
None
};
if source.is_none() {
let id = commands.entity(entity).insert(Source::default()).id();
if has_transform {
commands
.entity(id)
.insert_bundle(TransformBundle::default());
} }
target = **parent;
}
if !has_source {
commands.entity(entity).insert(Source::default());
} }
} }
} }