Added ability to swap between ASCII and sixel renderers when pressing tab

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2026-03-18 01:02:46 +01:00
parent 58838a1baa
commit 309bf5c699
5 changed files with 194 additions and 36 deletions

View File

@@ -36,12 +36,9 @@ void main() async {
recursive: true,
);
final data = availableGames.values.first;
final input = CliInput();
final cliAudio = CliSilentAudio();
final rasterizer = AsciiRasterizer(isTerminal: true);
final AsciiRasterizer asciiRasterizer = AsciiRasterizer(isTerminal: true);
final SixelRasterizer sixelRasterizer = SixelRasterizer();
Rasterizer rasterizer = sixelRasterizer;
FrameBuffer buffer = FrameBuffer(
stdout.terminalColumns,
@@ -49,11 +46,11 @@ void main() async {
);
final engine = WolfEngine(
data: data,
data: availableGames.values.first,
difficulty: Difficulty.medium,
startingEpisode: 0,
audio: cliAudio,
input: input,
audio: CliSilentAudio(),
input: CliInput(),
onGameWon: () {
exitCleanly(0);
print("YOU WON!");
@@ -67,7 +64,15 @@ void main() async {
exitCleanly(0);
}
input.handleKey(bytes);
if (bytes.contains(9)) {
rasterizer = identical(rasterizer, sixelRasterizer)
? asciiRasterizer
: sixelRasterizer;
stdout.write('\x1b[2J\x1b[H');
return;
}
(engine.input as CliInput).handleKey(bytes);
});
Stopwatch stopwatch = Stopwatch()..start();
@@ -78,13 +83,11 @@ void main() async {
if (stdout.hasTerminal) {
int cols = stdout.terminalColumns;
int rows = stdout.terminalLines;
if (cols < 80 || rows < 24) {
if (!rasterizer.isTerminalSizeSupported(cols, rows)) {
// Clear the screen and print the warning at the top left
stdout.write('\x1b[2J\x1b[H');
stdout.write('\x1b[31m[ ERROR ] TERMINAL TOO SMALL\x1b[0m\n\n');
stdout.write(
'Wolfenstein 3D requires a minimum resolution of 120x40.\n',
);
stdout.write('${rasterizer.terminalSizeRequirement}\n');
stdout.write(
'Current size: \x1b[33m${stdout.terminalColumns}x${stdout.terminalLines}\x1b[0m\n\n',
);
@@ -110,8 +113,7 @@ void main() async {
engine.tick(elapsed);
rasterizer.render(engine, buffer);
rasterizer.finalizeFrame();
stdout.write(rasterizer.toAnsiString());
stdout.write(rasterizer.finalizeFrame());
});
}