Files
wolf_dart/apps/wolf_3d_cli/bin/main.dart
Hans Kokx 3c6a4672f7 Refactor and enhance documentation across the Wolf3D project
- Updated library imports to use the correct package paths for consistency.
- Added detailed documentation comments to various classes and methods, improving code readability and maintainability.
- Refined the GameSelectScreen, SpriteGallery, and VgaGallery classes with clearer descriptions of their functionality.
- Enhanced the CliInput class to better explain the input handling process and its interaction with the engine.
- Improved the SixelRasterizer and Opl2Emulator classes with comprehensive comments on their operations and state management.
- Removed the deprecated wolf_3d.dart file and consolidated its functionality into wolf_3d_flutter.dart for a cleaner architecture.
- Updated the Wolf3dFlutterInput class to clarify its role in merging keyboard and pointer events.
- Enhanced the rendering classes to provide better context on their purpose and usage within the Flutter framework.

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
2026-03-18 10:01:12 +01:00

68 lines
1.8 KiB
Dart

/// CLI entry point for the terminal Wolf3D host.
///
/// This executable locates bundled retail assets, constructs a [WolfEngine]
/// configured for terminal rendering, and then hands control to [CliGameLoop].
library;
import 'dart:io';
import 'package:wolf_3d_cli/cli_game_loop.dart';
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_dart/wolf_3d_input.dart';
/// Restores terminal state before exiting the process with [code].
void exitCleanly(int code) {
stdout.write('\x1b[0m'); // Reset color
stdout.write('\x1b[2J\x1b[H'); // Clear screen
stdout.write('\x1b[?25h'); // SHOW the cursor again
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;
final targetUri = scriptUri.resolve(
'../../../packages/wolf_3d_assets/assets/retail',
);
final targetPath = targetUri.toFilePath();
final availableGames = await WolfensteinLoader.discover(
directoryPath: targetPath,
recursive: true,
);
CliGameLoop? gameLoop;
void stopAndExit(int code) {
gameLoop?.stop();
exitCleanly(code);
}
final engine = WolfEngine(
data: availableGames.values.first,
difficulty: Difficulty.medium,
startingEpisode: 0,
frameBuffer: FrameBuffer(
stdout.terminalColumns,
stdout.terminalLines,
),
input: CliInput(),
onGameWon: () => stopAndExit(0),
);
engine.init();
gameLoop = CliGameLoop(
engine: engine,
onExit: stopAndExit,
);
await gameLoop.start();
}