feat: Enhance CLI and GUI to support configurable game data directory persistence

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2026-03-23 19:19:50 +01:00
parent 5ef59d9980
commit 569a3386a8
14 changed files with 402 additions and 66 deletions
@@ -0,0 +1,99 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:wolf_3d_dart/wolf_3d_data_types.dart';
import 'package:wolf_3d_dart/wolf_3d_engine.dart';
import 'package:wolf_3d_flutter/wolf_3d_flutter.dart';
class _NoopAudio implements EngineAudio {
@override
WolfensteinData? activeGame;
@override
Future<void> debugSoundTest() async {}
@override
Future<void> init() async {}
@override
void playLevelMusic(Music music) {}
@override
void playMenuMusic() {}
@override
void playSoundEffect(SoundEffect effect) {}
@override
void playSoundEffectId(int sfxId) {}
@override
Future<void> stopAllAudio() async {}
@override
void stopMusic() {}
@override
void dispose() {}
}
void main() {
group('DefaultGameDataDirectoryPersistence', () {
test('saves and loads configured directory', () async {
final tempDir = await Directory.systemTemp.createTemp(
'wolf3d-data-config-',
);
addTearDown(() async {
if (await tempDir.exists()) {
await tempDir.delete(recursive: true);
}
});
final persistence = DefaultGameDataDirectoryPersistence(
filePath: '${tempDir.path}/data_source.json',
);
await persistence.saveDataDirectory('/tmp/wolf-data');
final loaded = await persistence.loadDataDirectory();
expect(loaded, '/tmp/wolf-data');
});
test('clears persisted path when saving null', () async {
final tempDir = await Directory.systemTemp.createTemp(
'wolf3d-data-config-',
);
addTearDown(() async {
if (await tempDir.exists()) {
await tempDir.delete(recursive: true);
}
});
final path = '${tempDir.path}/data_source.json';
final persistence = DefaultGameDataDirectoryPersistence(filePath: path);
await persistence.saveDataDirectory('/tmp/wolf-data');
await persistence.saveDataDirectory(null);
expect(await File(path).exists(), isFalse);
expect(await persistence.loadDataDirectory(), isNull);
});
});
testWidgets('Wolf3dApp forwards configured directory to no-data screen', (
tester,
) async {
final wolf3d = Wolf3dFlutterEngine(audioBackend: _NoopAudio())
..configuredDataDirectory = '/tmp/wolf-data';
await tester.pumpWidget(
MaterialApp(
home: Wolf3dApp(engine: wolf3d),
),
);
expect(find.textContaining('Configured data directory:'), findsOneWidget);
expect(find.textContaining('/tmp/wolf-data'), findsOneWidget);
});
}
@@ -55,10 +55,13 @@ void main() {
expect(wolf3d.isDebugEnabled, isTrue);
});
test('init(debug: true) enables debug mode', () async {
final wolf3d = Wolf3dFlutterEngine(audioBackend: _NoopAudio());
test('constructor(debug: true) enables debug mode', () async {
final wolf3d = Wolf3dFlutterEngine(
audioBackend: _NoopAudio(),
debug: true,
);
await wolf3d.init(debug: true);
await wolf3d.init();
expect(wolf3d.isDebugEnabled, isTrue);
});