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
@@ -7,13 +7,17 @@ import 'package:wolf_3d_dart/wolf_3d_data.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/audio/wolf3d_platform_audio.dart';
import 'package:wolf_3d_flutter/managers/desktop_windowing_support.dart'
as desktop_windowing_support;
import 'package:wolf_3d_flutter/managers/game_data_directory_persistence.dart';
import 'package:wolf_3d_flutter/wolf_3d_input_flutter.dart';
export 'package:wolf_3d_dart/wolf_3d_audio.dart' show DebugMusicPlayer;
export 'audio/wolf3d_platform_audio.dart' show Wolf3dPlatformAudio;
export 'managers/desktop_windowing_support.dart' show supportsDesktopWindowing;
export 'managers/game_app_lifecycle_manager.dart' show GameAppLifecycleManager;
export 'managers/game_data_directory_persistence.dart'
show DefaultGameDataDirectoryPersistence;
export 'managers/game_display_manager.dart' show GameDisplayManager;
export 'managers/game_persistence_manager.dart' show GamePersistenceManager;
export 'managers/game_renderer_mode_manager.dart'
@@ -44,12 +48,26 @@ export 'widgets/wolf_menu_shell.dart' show WolfMenuShell;
class Wolf3dFlutterEngine extends Wolf3dEngine {
/// Creates an empty facade that must be initialized with [init].
Wolf3dFlutterEngine({
bool debug = false,
EngineAudio? audioBackend,
Wolf3dFlutterInput? inputBackend,
}) : super(
DefaultGameDataDirectoryPersistence? dataDirectoryPersistence,
}) : dataDirectoryPersistence =
dataDirectoryPersistence ?? DefaultGameDataDirectoryPersistence(),
super(
audio: audioBackend ?? Wolf3dPlatformAudio(),
input: inputBackend ?? Wolf3dFlutterInput(),
);
) {
if (debug) {
enableDebug();
}
}
/// Persists and restores the preferred external game-data directory.
final DefaultGameDataDirectoryPersistence dataDirectoryPersistence;
/// Last configured/loaded external game-data directory path.
String? configuredDataDirectory;
/// Shared Flutter input adapter reused by gameplay screens.
@override
@@ -63,18 +81,24 @@ class Wolf3dFlutterEngine extends Wolf3dEngine {
}
/// Initializes the engine by loading available game data.
///
/// Set [debug] to `true` to explicitly enable host-level debug affordances.
Future<Wolf3dFlutterEngine> init({
String? directory,
bool debug = false,
}) async {
if (debug) {
enableDebug();
}
await desktop_windowing_support.ensureDesktopWindowingInitialized();
await audio.init();
availableGames.clear();
final String? requestedDirectory = directory?.trim();
final String? resolvedDirectory =
requestedDirectory != null && requestedDirectory.isNotEmpty
? requestedDirectory
: await dataDirectoryPersistence.loadDataDirectory();
configuredDataDirectory = resolvedDirectory;
if (requestedDirectory != null && requestedDirectory.isNotEmpty) {
await dataDirectoryPersistence.saveDataDirectory(requestedDirectory);
}
// Bundled assets let the GUI work out of the box on supported platforms.
final versionsToTry = [
(version: GameVersion.retail, path: 'retail'),
@@ -106,10 +130,10 @@ class Wolf3dFlutterEngine extends Wolf3dEngine {
// On non-web platforms, also scan the local filesystem for user-supplied
// data folders so the host can pick up extra versions automatically.
if (!kIsWeb) {
if (!kIsWeb && resolvedDirectory != null) {
try {
final externalGames = await WolfensteinLoader.discover(
directoryPath: directory,
directoryPath: resolvedDirectory,
recursive: true,
);
for (var entry in externalGames.entries) {
@@ -135,9 +159,3 @@ class Wolf3dFlutterEngine extends Wolf3dEngine {
}
}
}
/// Backward-compatible alias for the previous Flutter host facade name.
typedef Wolf3dFlutter = Wolf3dFlutterEngine;
/// Backward-compatible alias for the legacy Flutter host facade name.
typedef Wolf3d = Wolf3dFlutterEngine;