feat: Add file selector support and enhance game data directory management
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
@@ -83,6 +83,7 @@ class Wolf3dFlutterEngine extends Wolf3dEngine {
|
||||
/// Initializes the engine by loading available game data.
|
||||
Future<Wolf3dFlutterEngine> init({
|
||||
String? directory,
|
||||
Iterable<String>? additionalDirectories,
|
||||
}) async {
|
||||
await desktop_windowing_support.ensureDesktopWindowingInitialized();
|
||||
await audio.init();
|
||||
@@ -128,21 +129,37 @@ 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 && resolvedDirectory != null) {
|
||||
try {
|
||||
final externalGames = await WolfensteinLoader.discover(
|
||||
directoryPath: resolvedDirectory,
|
||||
recursive: true,
|
||||
);
|
||||
for (var entry in externalGames.entries) {
|
||||
if (!availableGames.any((g) => g.version == entry.key)) {
|
||||
availableGames.add(entry.value);
|
||||
}
|
||||
// On non-web platforms, also scan local filesystem locations for
|
||||
// user-supplied data folders so the host can pick up extra versions.
|
||||
final Set<String> directoriesToScan = <String>{};
|
||||
if (resolvedDirectory != null && resolvedDirectory.isNotEmpty) {
|
||||
directoriesToScan.add(resolvedDirectory);
|
||||
}
|
||||
|
||||
if (additionalDirectories != null) {
|
||||
for (final String directoryPath in additionalDirectories) {
|
||||
final String trimmedPath = directoryPath.trim();
|
||||
if (trimmedPath.isNotEmpty) {
|
||||
directoriesToScan.add(trimmedPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!kIsWeb && directoriesToScan.isNotEmpty) {
|
||||
for (final String directoryPath in directoriesToScan) {
|
||||
try {
|
||||
final externalGames = await WolfensteinLoader.discover(
|
||||
directoryPath: directoryPath,
|
||||
recursive: true,
|
||||
);
|
||||
for (var entry in externalGames.entries) {
|
||||
if (!availableGames.any((g) => g.version == entry.key)) {
|
||||
availableGames.add(entry.value);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint("External discovery failed: $e");
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint("External discovery failed: $e");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user