Skip to content

Commit

Permalink
Fix fix not actually fixing bug
Browse files Browse the repository at this point in the history
  • Loading branch information
janhohenheim committed Feb 20, 2023
1 parent 6bf893a commit c0e2d01
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 26 deletions.
26 changes: 1 addition & 25 deletions src/file_system_interaction/audio.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::file_system_interaction::asset_loading::AudioAssets;
use crate::util::log_error::log_errors;
use crate::GameState;
use anyhow::{Context, Result};
use bevy::prelude::*;
use bevy_kira_audio::prelude::{Audio, *};

Expand All @@ -12,11 +10,7 @@ pub struct InternalAudioPlugin;
impl Plugin for InternalAudioPlugin {
fn build(&self, app: &mut App) {
app.add_plugin(AudioPlugin)
.add_system_set(SystemSet::on_exit(GameState::Loading).with_system(init_audio))
.add_system_set(
SystemSet::on_update(GameState::Playing)
.with_system(pause_audio_when_time_is_paused.pipe(log_errors)),
);
.add_system_set(SystemSet::on_exit(GameState::Loading).with_system(init_audio));
}
}

Expand All @@ -34,21 +28,3 @@ fn init_audio(mut commands: Commands, audio_assets: Res<AudioAssets>, audio: Res
.handle();
commands.insert_resource(AudioHandles { walking: handle });
}

fn pause_audio_when_time_is_paused(
time: Res<Time>,
audio_handles: Res<AudioHandles>,
mut audio_instances: ResMut<Assets<AudioInstance>>,
) -> Result<()> {
if !time.is_paused() {
return Ok(());
}
let handles = [&audio_handles.walking];
for handle in handles {
let audio_instance = audio_instances
.get_mut(handle)
.context("Failed to get audio instance from handle")?;
audio_instance.pause(default());
}
Ok(())
}
3 changes: 2 additions & 1 deletion src/player_control/player_embodiment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ fn rotate_to_speaker(
}

fn control_walking_sound(
time: Res<Time>,
character_query: Query<(&Velocity, &Transform, &Grounded), With<Player>>,
audio: Res<AudioHandles>,
mut audio_instances: ResMut<Assets<AudioInstance>>,
Expand All @@ -197,7 +198,7 @@ fn control_walking_sound(
.horizontal
.is_approx_zero();
let is_moving_on_ground = has_horizontal_movement && grounded.0;
if is_moving_on_ground {
if is_moving_on_ground && !time.is_paused() {
audio_instance.resume(default());
} else {
audio_instance.pause(default());
Expand Down

0 comments on commit c0e2d01

Please sign in to comment.