From 4e859e56cb103b40bb5282f3bcf44c319cc4d3d8 Mon Sep 17 00:00:00 2001 From: AnErrupTion Date: Thu, 6 Mar 2025 20:40:53 +0100 Subject: [PATCH] Allow modifying DOOM animation fire colors (closes #239) Signed-off-by: AnErrupTion --- res/config.ini | 9 +++++++++ src/animations/Doom.zig | 43 +++++++++++++++++++++-------------------- src/config/Config.zig | 3 +++ src/main.zig | 2 +- 4 files changed, 35 insertions(+), 22 deletions(-) diff --git a/res/config.ini b/res/config.ini index 3ff7bb3..b6def9a 100644 --- a/res/config.ini +++ b/res/config.ini @@ -101,6 +101,15 @@ console_dev = /dev/console # Available inputs: info_line, session, login, password default_input = login +# DOOM animation top color (low intensity flames) +doom_top_color = 0x00FF0000 + +# DOOM animation middle color (medium intensity flames) +doom_middle_color = 0x00FFFF00 + +# DOOM animation bottom color (high intensity flames) +doom_bottom_color = 0x00FFFFFF + # Error background color id error_bg = 0x00000000 diff --git a/src/animations/Doom.zig b/src/animations/Doom.zig index 94df92c..6b0d46a 100644 --- a/src/animations/Doom.zig +++ b/src/animations/Doom.zig @@ -5,28 +5,14 @@ const utils = @import("../tui/utils.zig"); const Doom = @This(); -pub const STEPS = 13; -pub const FIRE = [_]utils.Cell{ - utils.initCell(' ', 9, 0), - 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 -}; +pub const STEPS = 12; allocator: Allocator, terminal_buffer: *TerminalBuffer, buffer: []u8, +fire: [STEPS + 1]utils.Cell, -pub fn init(allocator: Allocator, terminal_buffer: *TerminalBuffer) !Doom { +pub fn init(allocator: Allocator, terminal_buffer: *TerminalBuffer, top_color: u32, middle_color: u32, bottom_color: u32) !Doom { const buffer = try allocator.alloc(u8, terminal_buffer.width * terminal_buffer.height); initBuffer(buffer, terminal_buffer.width); @@ -34,6 +20,21 @@ pub fn init(allocator: Allocator, terminal_buffer: *TerminalBuffer) !Doom { .allocator = allocator, .terminal_buffer = terminal_buffer, .buffer = buffer, + .fire = [_]utils.Cell{ + utils.initCell(' ', 0x00000000, 0), + utils.initCell(0x2591, top_color, 0), + utils.initCell(0x2592, top_color, 0), + utils.initCell(0x2593, top_color, 0), + utils.initCell(0x2588, top_color, 0), + utils.initCell(0x2591, middle_color, 2), + utils.initCell(0x2592, middle_color, 2), + utils.initCell(0x2593, middle_color, 2), + utils.initCell(0x2588, middle_color, 2), + utils.initCell(0x2591, bottom_color, 4), + utils.initCell(0x2592, bottom_color, 4), + utils.initCell(0x2593, bottom_color, 4), + utils.initCell(0x2588, bottom_color, 4), + }, }; } @@ -62,16 +63,16 @@ pub fn draw(self: Doom) void { if (buffer_source < buffer_dest_offset) continue; var buffer_dest = buffer_source - buffer_dest_offset; - if (buffer_dest > 12) buffer_dest = 0; + if (buffer_dest > STEPS) buffer_dest = 0; self.buffer[dest] = @intCast(buffer_dest); 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]); + utils.putCell(dest_x, dest_y, self.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]); + utils.putCell(source_x, source_y, self.fire[buffer_source]); } } } @@ -82,5 +83,5 @@ fn initBuffer(buffer: []u8, width: usize) void { const slice_end = buffer[length..]; @memset(slice_start, 0); - @memset(slice_end, STEPS - 1); + @memset(slice_end, STEPS); } diff --git a/src/config/Config.zig b/src/config/Config.zig index ec5bd9e..0478173 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -29,6 +29,9 @@ colormix_col2: u32 = 0x000000FF, colormix_col3: u32 = 0x20000000, console_dev: []const u8 = "/dev/console", default_input: Input = .login, +doom_top_color: u32 = 0x00FF0000, +doom_middle_color: u32 = 0x00FFFF00, +doom_bottom_color: u32 = 0x00FFFFFF, error_bg: u32 = 0x00000000, error_fg: u32 = 0x01FF0000, fg: u32 = 0x00FFFFFF, diff --git a/src/main.zig b/src/main.zig index 69830c0..73f439b 100644 --- a/src/main.zig +++ b/src/main.zig @@ -337,7 +337,7 @@ pub fn main() !void { switch (config.animation) { .none => {}, - .doom => doom = try Doom.init(allocator, &buffer), + .doom => doom = try Doom.init(allocator, &buffer, config.doom_top_color, config.doom_middle_color, config.doom_bottom_color), .matrix => matrix = try Matrix.init(allocator, &buffer, config.cmatrix_fg, config.cmatrix_min_codepoint, config.cmatrix_max_codepoint), .colormix => color_mix = ColorMix.init(&buffer, config.colormix_col1, config.colormix_col2, config.colormix_col3), }