diff --git a/src/audio.rs b/src/audio.rs index b95259a..18c5026 100644 --- a/src/audio.rs +++ b/src/audio.rs @@ -1,19 +1,31 @@ use bevy::prelude::*; use bevy::audio::PlaybackMode; +//const ASSET_CLICK: &str = "tmp/analog-appliance-button-10-185285.mp3.ogg"; +//const ASSET_CLICK: &str = "tmp/analog-appliance-button-1-185276.ogg"; +//const ASSET_CLICK: &str = "tmp/click-button-140881.mp3.ogg"; +//const ASSET_CLICK: &str = "tmp/keyboard-chblue-146642.mp3.ogg"; +const ASSET_CLICK: &str = "tmp/keyboard-chcl-146641.mp3.ogg"; +//const ASSET_CLICK: &str = "tmp/typosonic-typing-192811.mp3.ogg"; +const ASSET_SWITCH: &str = "tmp/typosonic-typing-192811-crop.ogg"; + pub struct AudioPlugin; impl Plugin for AudioPlugin { fn build(&self, app: &mut App) { app.add_systems(Startup, setup); app.add_systems(Update, toggle_bgm); - app.add_systems(PostUpdate, play_click); + app.add_systems(PostUpdate, play_sfx); app.add_event::(); + app.add_event::(); } } #[derive(Event)] pub struct AudioClickEvent(); +#[derive(Event)] +pub struct AudioSwitchEvent(); + #[derive(Component)] pub struct ComponentBGM; @@ -26,6 +38,9 @@ struct SoundBGM(Handle); #[derive(Resource)] pub struct SoundClick(Handle); +#[derive(Resource)] +pub struct SoundSwitch(Handle); + pub fn setup( mut commands: Commands, asset_server: Res, @@ -56,31 +71,41 @@ pub fn setup( }, }, )); - let click_sound_handle = asset_server.load("tmp/analog-appliance-button-1-185276.ogg"); - commands.insert_resource(SoundClick(click_sound_handle)); + commands.insert_resource(SoundClick(asset_server.load(ASSET_CLICK))); + commands.insert_resource(SoundSwitch(asset_server.load(ASSET_SWITCH))); } pub fn toggle_bgm( keyboard_input: Res>, bgm_controller: Query<&AudioSink, With>, + mut evwriter: EventWriter, ) { if keyboard_input.just_pressed(KeyCode::KeyT) { if let Ok(sink) = bgm_controller.get_single() { - sink.toggle() + sink.toggle(); + evwriter.send(AudioClickEvent()); } } } -pub fn play_click( +pub fn play_sfx( mut commands: Commands, - mut events: EventReader, - sound: Res, + mut events_click: EventReader, + mut events_switch: EventReader, + sound_click: Res, + sound_switch: Res, ) { - if !events.is_empty() { - events.clear(); + if !events_click.is_empty() { + events_click.clear(); commands.spawn(AudioBundle { - source: sound.0.clone(), - // auto-despawn the entity when playback finishes + source: sound_click.0.clone(), + settings: PlaybackSettings::DESPAWN, + }); + } + if !events_switch.is_empty() { + events_switch.clear(); + commands.spawn(AudioBundle { + source: sound_switch.0.clone(), settings: PlaybackSettings::DESPAWN, }); } diff --git a/src/hud.rs b/src/hud.rs index ce8129b..dd039dd 100644 --- a/src/hud.rs +++ b/src/hud.rs @@ -215,7 +215,7 @@ fn handle_input( keyboard_input: Res>, settings: Res, mut query: Query<&mut Visibility, With>, - mut ev_click: EventWriter, + mut evwriter: EventWriter, ) { if keyboard_input.just_pressed(settings.key_togglehud) { for mut vis in &mut query { @@ -224,7 +224,7 @@ fn handle_input( } else { *vis = Visibility::Inherited; } - ev_click.send(audio::AudioClickEvent()); + evwriter.send(audio::AudioSwitchEvent()); } } } diff --git a/src/settings.rs b/src/settings.rs index f590317..6834637 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -22,7 +22,7 @@ impl Default for Settings { font_size_hud: 32.0, font_size_conversations: 32.0, key_togglehud: KeyCode::Tab, - hud_active: true, + hud_active: false, } } } diff --git a/src/world.rs b/src/world.rs index 494cdc0..92d7a56 100644 --- a/src/world.rs +++ b/src/world.rs @@ -151,7 +151,7 @@ pub fn setup( EulerRot::ZYX, 0.0, PI / 1.0, - -PI / 5.0, + -PI / 7.0, )), cascade_shadow_config: CascadeShadowConfigBuilder { first_cascade_far_bound: 7.0,