This commit is contained in:
2026-06-15 10:42:21 -05:00
parent 32aef1ea08
commit 439fc44106
6 changed files with 445 additions and 74 deletions
+17 -14
View File
@@ -10,6 +10,8 @@
mod animation;
mod cp437;
mod log;
mod menu;
mod overlay;
mod render;
mod scroll_overlay;
mod term;
@@ -36,8 +38,9 @@ use std::process::ExitCode;
use std::time::{Duration, Instant};
use term::TerminalCaps;
use crate::animation::{AnimationLayer, AnimWidget};
use crate::input::{current_input_mode, handle_board_input, handle_scroll_input, InputMode};
use crate::input::{current_input_mode, handle_board_input, handle_menu_input, handle_scroll_input, InputMode};
use crate::log::{log_preview_line, LogWidget};
use crate::menu::MenuWidget;
use crate::scroll_overlay::ScrollOverlayWidget;
use crate::speech::SpeechBubblesWidget;
use crate::ui::Ui;
@@ -75,10 +78,7 @@ fn main() -> ExitCode {
let _ = term::push_kitty_flags();
}
// Seed the log: the terminal-capabilities badge plus a couple of test
// messages (temporary, just to exercise the panel).
// Note these will appear in reverse order, latest on top
game.log(LogLine::raw("Press 'q' to exit."));
game.log(LogLine::raw("[esc] for menu"));
game.log(LogLine::raw("Welcome to kiln - ").append(caps.status_logline()));
// Now that the board is fully loaded and the terminal is ready, run each
@@ -134,10 +134,9 @@ fn run(
let terminal_h = terminal.size()?.height;
match current_input_mode(game, ui) {
InputMode::Board | InputMode::Frozen => {
if handle_board_input(event, ui.log.open, terminal_h, game, ui) {
return Ok(());
}
handle_board_input(event, ui.log.open, terminal_h, game, ui);
}
InputMode::Menu => handle_menu_input(event, game, ui),
InputMode::Scroll => handle_scroll_input(event, game, ui),
// Animation running — discard all events.
InputMode::Animating => {}
@@ -152,13 +151,18 @@ fn run(
last_tick = Instant::now();
ui.tick(dt, game);
}
// A menu action may have set should_quit; exit once any close animation finishes.
if ui.should_quit && ui.active_animation.is_none() {
return Ok(());
}
}
}
/// Render a single frame: the board in a bordered block, and — when open — a log
/// panel across the bottom. When the panel is closed the latest log message is
/// previewed in the board's bottom-left border after a `[l]og:` label.
/// A scroll overlay or overlay animation is drawn on top of everything when active.
/// Overlays (menu, scroll, animations) are drawn on top of everything.
fn draw(frame: &mut Frame, game: &GameState, ui: &mut Ui) {
// Borrow the board for the duration of the frame (no script runs during draw).
let board = &game.board();
@@ -186,18 +190,17 @@ fn draw(frame: &mut Frame, game: &GameState, ui: &mut Ui) {
draw_board_area(frame, inner, game, ui);
}
// Draw overlay animations (scroll open/close) or the fully-open scroll overlay.
// Suppressed during a board-layer animation (transition wipe); enter_board()
// already cleared active_scroll so there's nothing to show anyway.
// Overlay layer: animation > menu > scroll (mutually exclusive at runtime).
let is_overlay_anim = ui.active_animation.as_ref()
.map(|a| matches!(a.layer(), AnimationLayer::Overlay))
.unwrap_or(false);
let area = frame.area();
if is_overlay_anim {
let area = frame.area();
frame.render_widget(AnimWidget(ui.active_animation.as_ref().unwrap().as_ref()), area);
} else if let Some(menu) = ui.menu.as_mut() {
frame.render_stateful_widget(MenuWidget, area, menu);
} else if let Some(scroll) = &game.active_scroll {
let area = frame.area();
frame.render_stateful_widget(ScrollOverlayWidget::new(&scroll.lines), area, &mut ui.overlay);
}
}