use bevy::prelude::*; use bevy::audio::PlaybackMode; #[derive(Component)] pub struct ComponentBGM; #[derive(Component)] pub struct ComponentThrusterSound; #[derive(Resource)] struct SoundBGM(Handle); pub fn setup( mut commands: Commands, asset_server: Res, ) { let bgm = SoundBGM(asset_server.load("tmp/FTL - Faster Than Light (2012) OST - 12 - Void (Explore)-edQw2yYXQJM.ogg")); commands.spawn(( AudioBundle { source: bgm.0.clone(), settings: PlaybackSettings::LOOP, }, ComponentBGM, )); commands.insert_resource(bgm); commands.spawn(( AudioBundle { source: asset_server.load("sounds/wakeup.ogg"), settings: PlaybackSettings::DESPAWN, }, )); commands.spawn(( ComponentThrusterSound, AudioBundle { source: asset_server.load("tmp/loopingthrust-95548.ogg"), settings: PlaybackSettings { mode: PlaybackMode::Loop, paused: true, ..default() }, }, )); } pub fn toggle_bgm( keyboard_input: Res>, bgm_controller: Query<&AudioSink, With>, ) { if keyboard_input.just_pressed(KeyCode::KeyT) { if let Ok(sink) = bgm_controller.get_single() { sink.toggle() } } }