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

View File

@@ -46,74 +46,6 @@ class _AudioGalleryState extends State<AudioGallery> {
return 2;
}
static const List<SfxKey> _knownSfxKeys = [
SfxKey.openDoor,
SfxKey.closeDoor,
SfxKey.pushWall,
SfxKey.knifeAttack,
SfxKey.pistolFire,
SfxKey.machineGunFire,
SfxKey.chainGunFire,
SfxKey.enemyFire,
SfxKey.getMachineGun,
SfxKey.getAmmo,
SfxKey.getChainGun,
SfxKey.healthSmall,
SfxKey.healthLarge,
SfxKey.treasure1,
SfxKey.treasure2,
SfxKey.treasure3,
SfxKey.treasure4,
SfxKey.extraLife,
SfxKey.guardHalt,
SfxKey.dogBark,
SfxKey.dogDeath,
SfxKey.dogAttack,
SfxKey.deathScream1,
SfxKey.deathScream2,
SfxKey.deathScream3,
SfxKey.ssAlert,
SfxKey.ssDeath,
SfxKey.bossActive,
SfxKey.hansGrosseDeath,
SfxKey.schabbs,
SfxKey.schabbsDeath,
SfxKey.hitlerGreeting,
SfxKey.hitlerDeath,
SfxKey.mechaSteps,
SfxKey.ottoAlert,
SfxKey.gretelDeath,
SfxKey.levelComplete,
SfxKey.endBonus1,
SfxKey.endBonus2,
SfxKey.noBonus,
SfxKey.percent100,
];
static const List<MusicKey> _knownMusicKeys = [
MusicKey.menuTheme,
MusicKey.level01,
MusicKey.level02,
MusicKey.level03,
MusicKey.level04,
MusicKey.level05,
MusicKey.level06,
MusicKey.level07,
MusicKey.level08,
MusicKey.level09,
MusicKey.level10,
MusicKey.level11,
MusicKey.level12,
MusicKey.level13,
MusicKey.level14,
MusicKey.level15,
MusicKey.level16,
MusicKey.level17,
MusicKey.level18,
MusicKey.level19,
MusicKey.level20,
];
@override
void initState() {
super.initState();
@@ -130,14 +62,14 @@ class _AudioGalleryState extends State<AudioGallery> {
Map<int, List<String>> _buildSfxAliases() {
final Map<int, Set<String>> aliasesById = {};
for (final key in _knownSfxKeys) {
for (final key in SoundEffect.values) {
final ref = _selectedGame.registry.sfx.resolve(key);
if (ref == null) {
continue;
}
aliasesById
.putIfAbsent(ref.slotIndex, () => <String>{})
.add(_readableKeyName(key.toString(), 'SfxKey('));
.add(_readableKeyName(key.name));
}
return aliasesById.map(
@@ -147,14 +79,14 @@ class _AudioGalleryState extends State<AudioGallery> {
Map<int, List<String>> _buildMusicAliases() {
final Map<int, Set<String>> aliasesById = {};
for (final key in _knownMusicKeys) {
for (final key in Music.values) {
final route = _selectedGame.registry.music.resolve(key);
if (route == null) {
continue;
}
aliasesById
.putIfAbsent(route.trackIndex, () => <String>{})
.add(_readableKeyName(key.toString(), 'MusicKey('));
.add(_readableKeyName(key.name));
}
return aliasesById.map(
@@ -162,15 +94,12 @@ class _AudioGalleryState extends State<AudioGallery> {
);
}
String _readableKeyName(String raw, String prefix) {
final String trimmed = raw.startsWith(prefix) && raw.endsWith(')')
? raw.substring(prefix.length, raw.length - 1)
: raw;
if (trimmed.isEmpty) {
String _readableKeyName(String raw) {
if (raw.isEmpty) {
return raw;
}
return trimmed.replaceAllMapped(
return raw.replaceAllMapped(
RegExp(r'([a-z0-9])([A-Z])'),
(match) => '${match.group(1)} ${match.group(2)}',
);
@@ -203,7 +132,7 @@ class _AudioGalleryState extends State<AudioGallery> {
}
void _playSfx(int id) {
widget.wolf3d.audio.playSoundEffect(id);
widget.wolf3d.audio.playSoundEffectId(id);
}
Future<void> _toggleMusic(int trackIndex) async {