Refactor audio module to use built-in music and sound effect identifiers

- Introduced BuiltInMusicModule and BuiltInSfxModule to replace RetailMusicModule and RetailSfxModule.
- Updated RetailAssetRegistry and SharewareAssetRegistry to utilize the new built-in modules.
- Removed deprecated MusicKey and SfxKey classes, replacing them with Music and SoundEffect enums for better clarity and maintainability.
- Adjusted music and sound effect resolution methods to align with the new structure.
- Updated audio playback methods in WolfAudio and FlutterAudioAdapter to accept the new Music and SoundEffect types.
- Refactored tests to accommodate changes in audio event handling and ensure compatibility with the new identifiers.

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2026-03-20 17:07:25 +01:00
parent 8cca66e966
commit 10417d26ba
42 changed files with 499 additions and 622 deletions
@@ -13,7 +13,7 @@ class WolfAudio implements EngineAudio {
for (int i = 0; i < 50; i++) {
Future.delayed(Duration(seconds: i * 2), () {
log("[AUDIO] Testing Sound ID: $i");
playSoundEffect(i);
playSoundEffectId(i);
});
}
}
@@ -122,16 +122,21 @@ class WolfAudio implements EngineAudio {
@override
Future<void> playMenuMusic() async {
final data = activeGame;
if (data == null || data.music.length <= 1) return;
await playMusic(data.music[1]);
final trackIndex = data == null
? null
: Music.menuTheme.trackIndexFor(data.version);
if (data == null || trackIndex == null || trackIndex >= data.music.length) {
return;
}
await playMusic(data.music[trackIndex]);
}
@override
Future<void> playLevelMusic(WolfLevel level) async {
Future<void> playLevelMusic(Music music) async {
final data = activeGame;
if (data == null || data.music.isEmpty) return;
final index = level.musicIndex;
final index = music.trackIndexFor(data.version) ?? 0;
if (index < data.music.length) {
await playMusic(data.music[index]);
} else {
@@ -144,14 +149,24 @@ class WolfAudio implements EngineAudio {
// ==========================================
@override
Future<void> playSoundEffect(int sfxId) async {
Future<void> playSoundEffect(SoundEffect effect) async {
final data = activeGame;
if (data == null) return;
await playSoundEffectId(effect.idFor(data.version));
}
@override
Future<void> playSoundEffectId(int sfxId) async {
log("[AUDIO] Playing sfx id $sfxId");
// The original engine uses a specific starting chunk for digitized sounds.
// In many loaders, the 'sounds' list is already just the digitized ones.
// If your list contains EVERYTHING, you need to add the offset (174).
// If it's JUST digitized sounds, sfxId should work directly.
final soundsList = activeGame!.sounds;
final data = activeGame;
if (data == null) return;
final soundsList = data.sounds;
if (sfxId < 0 || sfxId >= soundsList.length) return;
final raw8bitBytes = soundsList[sfxId].bytes;