fix wrong radio playing on startup
This commit is contained in:
parent
8c7a856717
commit
4e8794338a
42
src/audio.rs
42
src/audio.rs
|
@ -48,12 +48,12 @@ pub struct ZoomTimer(Timer);
|
|||
|
||||
const PATHS: &[(SfxType, Sfx, &str)] = &[
|
||||
(
|
||||
SfxType::BGM,
|
||||
SfxType::Radio,
|
||||
Sfx::BGM,
|
||||
"music/Aleksey Chistilin - Cinematic Cello.ogg",
|
||||
),
|
||||
(
|
||||
SfxType::BGMNoAR,
|
||||
SfxType::Radio,
|
||||
Sfx::BGMActualJupiterRecording,
|
||||
"music/JupiterRecording.ogg",
|
||||
),
|
||||
|
@ -132,8 +132,7 @@ pub fn str2sfx(sfx_label: &str) -> Sfx {
|
|||
}
|
||||
|
||||
pub enum SfxType {
|
||||
BGM,
|
||||
BGMNoAR,
|
||||
Radio,
|
||||
LoopSfx,
|
||||
OneOff,
|
||||
}
|
||||
|
@ -167,7 +166,7 @@ pub fn respawn_sinks(
|
|||
mut commands: Commands,
|
||||
asset_server: Res<AssetServer>,
|
||||
q_audiosinks: Query<Entity, (With<AudioSink>, With<Sfx>)>,
|
||||
mut ew_togglemusic: EventWriter<ToggleMusicEvent>,
|
||||
settings: Res<Settings>,
|
||||
) {
|
||||
for sink in &q_audiosinks {
|
||||
commands.entity(sink).despawn();
|
||||
|
@ -175,27 +174,14 @@ pub fn respawn_sinks(
|
|||
for (sfxtype, sfx, path) in PATHS {
|
||||
let source = asset_server.load(*path);
|
||||
match sfxtype {
|
||||
SfxType::BGM => {
|
||||
SfxType::Radio => {
|
||||
commands.spawn((
|
||||
*sfx,
|
||||
AudioBundle {
|
||||
source,
|
||||
settings: PlaybackSettings {
|
||||
mode: PlaybackMode::Loop,
|
||||
paused: true,
|
||||
..default()
|
||||
},
|
||||
},
|
||||
));
|
||||
}
|
||||
SfxType::BGMNoAR => {
|
||||
commands.spawn((
|
||||
*sfx,
|
||||
AudioBundle {
|
||||
source,
|
||||
settings: PlaybackSettings {
|
||||
mode: PlaybackMode::Loop,
|
||||
paused: true,
|
||||
paused: !settings.is_radio_playing(*sfx).unwrap_or(true),
|
||||
..default()
|
||||
},
|
||||
},
|
||||
|
@ -218,7 +204,6 @@ pub fn respawn_sinks(
|
|||
SfxType::OneOff => (),
|
||||
}
|
||||
}
|
||||
ew_togglemusic.send(ToggleMusicEvent());
|
||||
}
|
||||
|
||||
pub fn play_sfx(
|
||||
|
@ -242,17 +227,12 @@ pub fn play_sfx(
|
|||
|
||||
pub fn toggle_music(q_audiosinks: Query<(&AudioSink, &Sfx)>, settings: Res<var::Settings>) {
|
||||
for (bgm_sink, sfx) in &q_audiosinks {
|
||||
let play = match *sfx {
|
||||
Sfx::BGM => settings.radio_mode == 1,
|
||||
Sfx::BGMActualJupiterRecording => settings.radio_mode == 2,
|
||||
_ => {
|
||||
continue;
|
||||
if let Some(play) = settings.is_radio_playing(*sfx) {
|
||||
if play {
|
||||
bgm_sink.play();
|
||||
} else {
|
||||
bgm_sink.pause();
|
||||
}
|
||||
};
|
||||
if play {
|
||||
bgm_sink.play();
|
||||
} else {
|
||||
bgm_sink.pause();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
12
src/var.rs
12
src/var.rs
|
@ -41,7 +41,7 @@ pub struct Settings {
|
|||
pub alive: bool,
|
||||
pub mute_sfx: bool,
|
||||
pub radio_mode: usize,
|
||||
pub radio_modes: Vec<String>,
|
||||
pub radio_modes: Vec<String>, // see also: settings.is_radio_playing()
|
||||
pub volume_sfx: u8,
|
||||
pub volume_music: u8,
|
||||
pub mouse_sensitivity: f32,
|
||||
|
@ -170,7 +170,7 @@ impl Default for Settings {
|
|||
alive: true,
|
||||
mute_sfx: default_mute_sfx,
|
||||
radio_mode: 1,
|
||||
radio_modes: vec![
|
||||
radio_modes: vec![ // see also: settings.is_radio_playing()
|
||||
"Off".to_string(),
|
||||
"Cinematic".to_string(),
|
||||
"Vibration Sensor Readings".to_string(),
|
||||
|
@ -323,6 +323,14 @@ impl Settings {
|
|||
pub fn in_control(&self) -> bool {
|
||||
return self.alive && !self.menu_active;
|
||||
}
|
||||
|
||||
pub fn is_radio_playing(&self, sfx: audio::Sfx) -> Option<bool> {
|
||||
match sfx {
|
||||
audio::Sfx::BGM => Some(self.radio_mode == 1),
|
||||
audio::Sfx::BGMActualJupiterRecording => Some(self.radio_mode == 2),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Resource, Default, Debug)]
|
||||
|
|
Loading…
Reference in a new issue