Music player in the sound settings: pick any calm track or automatic
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
51b7bb4804
commit
4ef7672008
22 files changed
+108
-4
No files matched your search
+15
-3
@@ -481,7 +481,8 @@ impl MusicDirector {
|
||||
t
|
||||
}
|
||||
|
||||
fn update(&mut self, g: &Game, title: bool, cam: (f32, f32)) {
|
||||
// `chosen`: a track picked in the music player; it replaces the calm music
|
||||
fn update(&mut self, g: &Game, title: bool, cam: (f32, f32), chosen: Option<usize>) {
|
||||
use audio::Category as C;
|
||||
let alive = |f: &dyn Fn(&game::Ent) -> bool| g.ents.iter().any(|e| e.alive && f(e));
|
||||
let near_room = |k: map::Kind| {
|
||||
@@ -535,8 +536,19 @@ impl MusicDirector {
|
||||
C::Build | C::Torture | C::Temple if above => C::Surface,
|
||||
w => w,
|
||||
};
|
||||
let calm = matches!(want, C::Build | C::Title | C::Surface | C::Torture | C::Temple);
|
||||
if let (true, Some(t)) = (calm, chosen) {
|
||||
if audio::current_track() != Some(t) {
|
||||
let fade = if self.current.map_or(false, |c| matches!(c, C::Victory | C::Defeat)) { 1.0 } else { 2.5 };
|
||||
audio::play_music(t, fade);
|
||||
}
|
||||
self.current = Some(want);
|
||||
return;
|
||||
}
|
||||
let rotate = matches!(want, C::Build | C::Title | C::Surface) && self.current == Some(want) && audio::music_loops() >= 2;
|
||||
if self.current != Some(want) || rotate || audio::current_track().is_none() {
|
||||
// after the chosen track was let go, the director picks again
|
||||
let foreign = chosen.is_none() && audio::current_track().map_or(false, |t| crate::tracks::TRACKS.get(t).map_or(false, |x| x.1 != want)) && calm && self.current == Some(want);
|
||||
if self.current != Some(want) || rotate || foreign || audio::current_track().is_none() {
|
||||
let before = self.current;
|
||||
self.current = Some(want);
|
||||
let t = self.pick(want);
|
||||
@@ -2005,7 +2017,7 @@ app.pending_briefing = briefing_of(&campaign, i);
|
||||
| Some(Page::Match { from_title: true })
|
||||
| Some(Page::Achievements { from_title: true })
|
||||
);
|
||||
music.update(&app.game, on_title, (app.cam.rx, app.cam.rz));
|
||||
music.update(&app.game, on_title, (app.cam.rx, app.cam.rz), audio::track_by_id(&app.settings.music_track));
|
||||
// ---------------- achievements: count the game, unlock, store and share the profile
|
||||
{
|
||||
let ctx = achievements::Context { coop: app.coop, editor_test: app.editor_testing };
|
||||
|
||||
Reference in new issue
Block a user