Load menu and level audio dynamically
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
@@ -9,6 +9,8 @@ class WolfAudio {
|
||||
AudioSource? _currentMusicSource;
|
||||
SoundHandle? _currentMusicHandle;
|
||||
|
||||
WolfensteinData? activeGame;
|
||||
|
||||
/// Initializes the SoLoud audio engine.
|
||||
Future<void> init() async {
|
||||
if (_isInitialized) return;
|
||||
@@ -89,4 +91,30 @@ class WolfAudio {
|
||||
SoLoud.instance.setPause(_currentMusicHandle!, false);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> playMenuMusic() async {
|
||||
final data = activeGame;
|
||||
// We can't play if data isn't set or doesn't have enough tracks
|
||||
if (data == null || data.music.length <= 1) return;
|
||||
|
||||
// Track 1 is the menu theme in both Shareware and Retail
|
||||
await playMusic(data.music[1]);
|
||||
}
|
||||
|
||||
/// Plays the specific track assigned to a WolfLevel.
|
||||
Future<void> playLevelMusic(WolfLevel level) async {
|
||||
final data = activeGame;
|
||||
if (data == null || data.music.isEmpty) return;
|
||||
|
||||
final index = level.musicIndex;
|
||||
|
||||
if (index < data.music.length) {
|
||||
// 3. FIXED THIS: Call your playMusic method
|
||||
await playMusic(data.music[index]);
|
||||
} else {
|
||||
print(
|
||||
"WolfAudio: Warning - Track index $index out of bounds for level ${level.name}.",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user