Fix Doom & Matrix animation + bug in migrator

Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
AnErrupTion 2025-03-06 15:27:38 +01:00
parent 55abc4d7f1
commit 6cb102257c
No known key found for this signature in database
3 changed files with 30 additions and 30 deletions

View File

@ -3,26 +3,23 @@ const Allocator = std.mem.Allocator;
const TerminalBuffer = @import("../tui/TerminalBuffer.zig");
const utils = @import("../tui/utils.zig");
const interop = @import("../interop.zig");
const termbox = interop.termbox;
const Doom = @This();
pub const STEPS = 13;
pub const FIRE = [_]utils.Cell{
utils.initCell(' ', 9, 0),
utils.initCell(0x2591, 2, 0), // Red
utils.initCell(0x2592, 2, 0), // Red
utils.initCell(0x2593, 2, 0), // Red
utils.initCell(0x2588, 2, 0), // Red
utils.initCell(0x2591, 4, 2), // Yellow
utils.initCell(0x2592, 4, 2), // Yellow
utils.initCell(0x2593, 4, 2), // Yellow
utils.initCell(0x2588, 4, 2), // Yellow
utils.initCell(0x2591, 8, 4), // White
utils.initCell(0x2592, 8, 4), // White
utils.initCell(0x2593, 8, 4), // White
utils.initCell(0x2588, 8, 4), // White
utils.initCell(0x2591, 0x00FF0000, 0), // Red
utils.initCell(0x2592, 0x00FF0000, 0), // Red
utils.initCell(0x2593, 0x00FF0000, 0), // Red
utils.initCell(0x2588, 0x00FF0000, 0), // Red
utils.initCell(0x2591, 0x00FFFF00, 2), // Yellow
utils.initCell(0x2592, 0x00FFFF00, 2), // Yellow
utils.initCell(0x2593, 0x00FFFF00, 2), // Yellow
utils.initCell(0x2588, 0x00FFFF00, 2), // Yellow
utils.initCell(0x2591, 0x00FFFFFF, 4), // White
utils.initCell(0x2592, 0x00FFFFFF, 4), // White
utils.initCell(0x2593, 0x00FFFFFF, 4), // White
utils.initCell(0x2588, 0x00FFFFFF, 4), // White
};
allocator: Allocator,
@ -68,8 +65,13 @@ pub fn draw(self: Doom) void {
if (buffer_dest > 12) buffer_dest = 0;
self.buffer[dest] = @intCast(buffer_dest);
self.terminal_buffer.buffer[dest] = toTermboxCell(FIRE[buffer_dest]);
self.terminal_buffer.buffer[source] = toTermboxCell(FIRE[buffer_source]);
const dest_y = dest / self.terminal_buffer.width;
const dest_x = dest % self.terminal_buffer.width;
utils.putCell(dest_x, dest_y, FIRE[buffer_dest]);
const source_y = source / self.terminal_buffer.width;
const source_x = source % self.terminal_buffer.width;
utils.putCell(source_x, source_y, FIRE[buffer_source]);
}
}
}
@ -82,11 +84,3 @@ fn initBuffer(buffer: []u8, width: usize) void {
@memset(slice_start, 0);
@memset(slice_end, STEPS - 1);
}
fn toTermboxCell(cell: utils.Cell) termbox.tb_cell {
return .{
.ch = cell.ch,
.fg = cell.fg,
.bg = cell.bg,
};
}

View File

@ -2,6 +2,7 @@ const std = @import("std");
const Allocator = std.mem.Allocator;
const Random = std.Random;
const TerminalBuffer = @import("../tui/TerminalBuffer.zig");
const utils = @import("../tui/utils.zig");
const interop = @import("../interop.zig");
const termbox = interop.termbox;
@ -151,12 +152,12 @@ pub fn draw(self: *Matrix) void {
var fg = self.fg_ini;
if (dot.value == -1 or dot.value == ' ') {
_ = termbox.tb_set_cell(@intCast(x), @intCast(y - 1), ' ', fg, termbox.TB_DEFAULT);
utils.putCell(x, y - 1, .{ .ch = ' ', .fg = fg, .bg = termbox.TB_DEFAULT });
continue;
}
if (dot.is_head) fg = @intCast(termbox.TB_WHITE | termbox.TB_BOLD);
_ = termbox.tb_set_cell(@intCast(x), @intCast(y - 1), @intCast(dot.value), fg, termbox.TB_DEFAULT);
if (dot.is_head) fg = @intCast(0x00FFFFFF | termbox.TB_BOLD); // White and bold
utils.putCell(x, y - 1, .{ .ch = @intCast(dot.value), .fg = fg, .bg = termbox.TB_DEFAULT });
}
}
}

View File

@ -31,6 +31,7 @@ const removed_properties = [_][]const u8{
};
var temporary_allocator = std.heap.page_allocator;
var buffer = std.mem.zeroes([10 * color_properties.len]u8);
pub var maybe_animate: ?bool = null;
pub var maybe_save_file: ?[]const u8 = null;
@ -177,7 +178,12 @@ fn mapColor(color: u16) ![]const u8 {
const color_no_styling = color & 0x00FF;
const styling_only = color & 0xFF00;
if (color_no_styling > termbox.TB_WHITE or styling_only > 0x8000) { // TB_DIM in 16-bit mode
return error.InvalidColor;
}
var new_color: u32 = switch (color_no_styling) {
termbox.TB_DEFAULT => termbox.TB_DEFAULT,
termbox.TB_BLACK => termbox.TB_HI_BLACK,
termbox.TB_RED => 0x00FF0000,
termbox.TB_GREEN => 0x0000FF00,
@ -186,7 +192,7 @@ fn mapColor(color: u16) ![]const u8 {
termbox.TB_MAGENTA => 0x00FF00FF,
termbox.TB_CYAN => 0x0000FFFF,
termbox.TB_WHITE => 0x00FFFFFF,
else => termbox.TB_DEFAULT,
else => unreachable,
};
// Only applying styling if color isn't black and styling isn't also black
@ -195,6 +201,5 @@ fn mapColor(color: u16) ![]const u8 {
new_color |= @as(u32, @intCast(styling_only)) << 16;
}
var buffer = std.mem.zeroes([10]u8);
return try std.fmt.bufPrint(&buffer, "0x{X}", .{new_color});
}