Load menu and level audio dynamically

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2026-03-15 14:54:57 +01:00
parent 6eb903cbaa
commit a75ade8b33
8 changed files with 67 additions and 6 deletions

View File

@@ -4,6 +4,20 @@ import 'dart:typed_data';
import 'package:wolf_3d_data_types/wolf_3d_data_types.dart';
abstract class WLParser {
// --- Original Song Lookup Tables ---
static const List<int> _sharewareMusicMap = [
2, 3, 4, 5, 2, 3, 4, 5, 6, 7, // Episode 1
];
static const List<int> _retailMusicMap = [
2, 3, 4, 5, 2, 3, 4, 5, 6, 7, // Ep 1
8, 9, 10, 11, 8, 9, 11, 10, 6, 12, // Ep 2
13, 14, 15, 16, 13, 14, 15, 16, 17, 18, // Ep 3
2, 3, 4, 5, 2, 3, 4, 5, 6, 7, // Ep 4
8, 9, 10, 11, 8, 9, 11, 10, 6, 12, // Ep 5
13, 14, 15, 16, 13, 14, 15, 16, 17, 19, // Ep 6
];
/// Asynchronously discovers the game version and loads all necessary files.
/// Provide a [fileFetcher] callback (e.g., Flutter's rootBundle.load) that
/// takes a filename and returns its ByteData.
@@ -229,6 +243,10 @@ abstract class WLParser {
bool isShareware = true,
}) {
List<WolfLevel> levels = [];
// 1. Select the correct map based on the version
final activeMusicMap = isShareware ? _sharewareMusicMap : _retailMusicMap;
int rlewTag = mapHead.getUint16(0, Endian.little);
for (int i = 0; i < 100; i++) {
@@ -279,11 +297,20 @@ abstract class WLParser {
objectGrid.add(objectRow);
}
// Determine music track index.
// We use 'i' because it represents the absolute map slot (e.g. Map 12).
// If a map exists past the bounds of our lookup table (custom maps),
// we wrap around safely.
int trackIndex = (i < activeMusicMap.length)
? activeMusicMap[i]
: activeMusicMap[i % activeMusicMap.length];
levels.add(
WolfLevel(
name: name,
wallGrid: wallGrid,
objectGrid: objectGrid,
musicIndex: trackIndex,
),
);
}