61 lines
1.5 KiB
Dart
61 lines
1.5 KiB
Dart
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';
|
|
|
|
// Helper to gracefully exit and restore the terminal
|
|
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);
|
|
}
|
|
|
|
void main() async {
|
|
stdout.write("Discovering game data...");
|
|
// 1. Get the absolute URI of where this exact script lives
|
|
final scriptUri = Platform.script;
|
|
|
|
// 2. Resolve the path mathematically.
|
|
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,
|
|
);
|
|
|
|
gameLoop.start();
|
|
}
|