chore: Clean up code.
This commit is contained in:
parent
4c02a98eb4
commit
45746803c9
46
src/lib.rs
46
src/lib.rs
|
@ -229,7 +229,9 @@ fn add_source_handle(
|
|||
)>,
|
||||
) {
|
||||
for (mut source, panner_strategy, transform, angular_pan, scalar_pan) in &mut query {
|
||||
if source.handle.is_none() {
|
||||
if source.handle.is_some() {
|
||||
continue;
|
||||
}
|
||||
let panner_strategy = panner_strategy.cloned().unwrap_or_default();
|
||||
let handle: syz::Source = if let Some(transform) = transform {
|
||||
let translation = transform.translation();
|
||||
|
@ -258,6 +260,7 @@ fn add_source_handle(
|
|||
.expect("Failed to create source")
|
||||
.into()
|
||||
} else {
|
||||
println!("Adding new direct source");
|
||||
syz::DirectSource::new(&context)
|
||||
.expect("Failed to create source")
|
||||
.into()
|
||||
|
@ -265,7 +268,6 @@ fn add_source_handle(
|
|||
source.handle = Some(handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn add_generator(
|
||||
context: Res<Context>,
|
||||
|
@ -275,7 +277,9 @@ fn add_generator(
|
|||
parents: Query<&Parent>,
|
||||
) {
|
||||
for (entity, parent, mut sound) in &mut query {
|
||||
if sound.generator.is_none() {
|
||||
if sound.generator.is_some() {
|
||||
continue;
|
||||
}
|
||||
let mut source = if let Ok(s) = sources.get_mut(entity) {
|
||||
Some(s)
|
||||
} else if parent.is_some() {
|
||||
|
@ -307,7 +311,9 @@ fn add_generator(
|
|||
}
|
||||
Audio::Generator(generator) => Some(generator.clone()),
|
||||
};
|
||||
if let Some(generator) = generator {
|
||||
let Some(generator) = generator else {
|
||||
continue;
|
||||
};
|
||||
assert!(sound.gain >= 0.);
|
||||
generator
|
||||
.gain()
|
||||
|
@ -326,8 +332,6 @@ fn add_generator(
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn add_sound_without_source(
|
||||
mut commands: Commands,
|
||||
|
@ -382,13 +386,14 @@ fn change_panner_strategy(
|
|||
check.push(entity);
|
||||
}
|
||||
for entity in check.iter() {
|
||||
if let Ok(mut source) = sources.get_mut(*entity) {
|
||||
let Ok(mut source) = sources.get_mut(*entity) else {
|
||||
continue;
|
||||
};
|
||||
if source.handle.is_some() {
|
||||
source.handle = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn update_source_properties(
|
||||
context: Res<Context>,
|
||||
|
@ -552,7 +557,9 @@ fn update_sound_properties(mut query: Query<&mut Sound>) {
|
|||
} = *sound;
|
||||
assert!(gain >= 0.);
|
||||
assert!(pitch > 0. && pitch <= 2.);
|
||||
if let Some(generator) = sound.generator.as_mut() {
|
||||
let Some(generator) = sound.generator.as_mut() else {
|
||||
continue;
|
||||
};
|
||||
generator.gain().set(gain).expect("Failed to set gain");
|
||||
generator
|
||||
.pitch_bend()
|
||||
|
@ -569,11 +576,12 @@ fn update_sound_properties(mut query: Query<&mut Sound>) {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn update_source_playback_state(query: Query<&Source>) {
|
||||
for source in &query {
|
||||
if let Some(handle) = &source.handle {
|
||||
let Some(handle) = &source.handle else {
|
||||
continue;
|
||||
};
|
||||
if source.paused {
|
||||
handle.pause().expect("Failed to pause");
|
||||
} else {
|
||||
|
@ -581,11 +589,12 @@ fn update_source_playback_state(query: Query<&Source>) {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn update_sound_playback_state(query: Query<&Sound>) {
|
||||
for sound in &query {
|
||||
if let Some(generator) = &sound.generator {
|
||||
let Some(generator) = &sound.generator else {
|
||||
continue;
|
||||
};
|
||||
if sound.paused {
|
||||
generator.pause().expect("Failed to pause");
|
||||
} else {
|
||||
|
@ -593,7 +602,6 @@ fn update_sound_playback_state(query: Query<&Sound>) {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn remove_sound(mut last_buffer: ResMut<LastAudio>, mut removed: RemovedComponents<Sound>) {
|
||||
for entity in removed.read() {
|
||||
|
@ -671,9 +679,13 @@ fn events(
|
|||
mut output: EventWriter<SynthizerEvent>,
|
||||
) {
|
||||
context.get_events().for_each(|event| {
|
||||
if let Ok(event) = event {
|
||||
let Ok(event) = event else {
|
||||
return;
|
||||
};
|
||||
for (entity, sound) in &sounds {
|
||||
if let Some(generator) = &sound.generator {
|
||||
let Some(generator) = &sound.generator else {
|
||||
continue;
|
||||
};
|
||||
if *generator.handle() == event.source {
|
||||
match event.r#type {
|
||||
syz::EventType::Finished => {
|
||||
|
@ -687,8 +699,6 @@ fn events(
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user