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:
@@ -6,6 +6,7 @@ library;
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:args/args.dart';
|
||||
import 'package:wolf_3d_cli/cli_game_loop.dart';
|
||||
import 'package:wolf_3d_dart/wolf_3d_audio.dart';
|
||||
import 'package:wolf_3d_dart/wolf_3d_data.dart';
|
||||
@@ -21,28 +22,66 @@ void exitCleanly(int code) {
|
||||
exit(code);
|
||||
}
|
||||
|
||||
/// Launches the CLI renderer against the bundled retail asset set.
|
||||
void main() async {
|
||||
stdout.write("Discovering game data...");
|
||||
// Resolve the asset package relative to this executable so the CLI can run
|
||||
// from the repo without additional configuration.
|
||||
final scriptUri = Platform.script;
|
||||
/// Launches the CLI renderer using discoverable or user-provided game data.
|
||||
void main(List<String> arguments) async {
|
||||
final argParser = ArgParser()
|
||||
..addOption(
|
||||
'data-directory',
|
||||
abbr: 'd',
|
||||
valueHelp: 'path',
|
||||
help: 'Directory containing Wolf3D data files.',
|
||||
)
|
||||
..addFlag(
|
||||
'help',
|
||||
abbr: 'h',
|
||||
negatable: false,
|
||||
help: 'Show usage information.',
|
||||
);
|
||||
|
||||
final targetUri = scriptUri.resolve(
|
||||
'../../../packages/wolf_3d_assets/assets/retail',
|
||||
);
|
||||
final targetPath = targetUri.toFilePath();
|
||||
late final ArgResults parsedArgs;
|
||||
try {
|
||||
parsedArgs = argParser.parse(arguments);
|
||||
} on FormatException catch (e) {
|
||||
stderr.writeln(e.message);
|
||||
stderr.writeln('Usage: wolf_3d_cli [options]');
|
||||
stderr.writeln(argParser.usage);
|
||||
exitCleanly(64);
|
||||
}
|
||||
|
||||
if (parsedArgs.flag('help')) {
|
||||
stdout.writeln('Usage: wolf_3d_cli [options]');
|
||||
stdout.writeln(argParser.usage);
|
||||
exitCleanly(0);
|
||||
}
|
||||
|
||||
final String? rawPath = parsedArgs.option('data-directory');
|
||||
final String? dataDirectory = rawPath != null && rawPath.trim().isNotEmpty
|
||||
? rawPath.trim()
|
||||
: null;
|
||||
|
||||
if (dataDirectory != null) {
|
||||
stdout.write('Discovering game data in "$dataDirectory"...');
|
||||
} else {
|
||||
stdout.write('Discovering game data...');
|
||||
}
|
||||
|
||||
final availableGames = await WolfensteinLoader.discover(
|
||||
directoryPath: targetPath,
|
||||
directoryPath: dataDirectory,
|
||||
recursive: true,
|
||||
);
|
||||
|
||||
if (availableGames.isEmpty) {
|
||||
stderr.writeln('\nNo Wolf3D game files were found at: $targetPath');
|
||||
stderr.writeln(
|
||||
'Please provide valid game data files before starting the CLI host.',
|
||||
);
|
||||
if (dataDirectory == null) {
|
||||
stderr.writeln('\nNo Wolf3D game data was discovered.');
|
||||
stderr.writeln('Provide a game-data directory with one of these flags:');
|
||||
stderr.writeln(' --data-directory <path>');
|
||||
stderr.writeln(' -d <path>');
|
||||
} else {
|
||||
stderr.writeln('\nNo Wolf3D game files were found at: $dataDirectory');
|
||||
stderr.writeln(
|
||||
'Please provide valid game data files before starting the CLI host.',
|
||||
);
|
||||
}
|
||||
exitCleanly(1);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user