transition

This commit is contained in:
2026-06-13 18:43:29 -05:00
parent 6818f0545a
commit 299570bec8
6 changed files with 254 additions and 20 deletions
+31 -6
View File
@@ -4,20 +4,45 @@ use kiln_core::game::{GameState, ScrollLine};
use crate::scroll_overlay::ScrollAnimState;
use crate::ui::Ui;
/// Moves the player and, if the move crosses a portal, captures both board Rcs
/// and stores them in [`Ui::pending_transition`] for the next draw call.
fn try_move_with_transition(game: &mut GameState, ui: &mut Ui, dir: Direction) {
let old_rc = game.board_rc();
let old_name = game.current_board_name().to_string();
game.try_move(dir);
if game.current_board_name() != old_name {
// Portal crossed: queue transition; consume the engine-side signal.
ui.pending_transition = Some((old_rc, game.board_rc()));
game.board_transition = None;
}
}
/// Which input mode the front-end is currently in.
pub enum InputMode {
/// Normal gameplay: arrow keys move the player, `l` toggles the log.
/// The `bool` is whether the log panel is open (affects PageUp/Down and mouse).
Board(bool),
Board,
/// A scroll overlay is active; all input is captured for scroll navigation.
Scroll,
/// A board-wipe animation is running; all events are silently discarded.
Transition,
/// The wipe just finished; game is frozen until the player presses any key.
Frozen,
}
/// Determines the current input mode from game and UI state.
pub(crate) fn current_input_mode(game: &GameState, ui: &Ui) -> InputMode {
// Transition takes highest priority (pending or animating).
if ui.transition.is_some() || ui.pending_transition.is_some() {
return InputMode::Transition;
}
// Post-wipe freeze: show the new board but don't tick or move until a key is pressed.
if ui.post_transition_wait {
return InputMode::Frozen;
}
let scroll_active = game.active_scroll.is_some()
&& !matches!(ui.overlay.anim, Some(ScrollAnimState::Closing(_) | ScrollAnimState::Done));
if scroll_active { InputMode::Scroll } else { InputMode::Board(ui.log.open) }
if scroll_active { InputMode::Scroll } else { InputMode::Board }
}
/// Handles an input event in [`InputMode::Board`]. Returns `true` if the player quit.
@@ -25,10 +50,10 @@ pub(crate) fn handle_board_input(event: Event, log_open: bool, terminal_h: u16,
match event {
Event::Key(key) => match key.code {
KeyCode::Char('q') | KeyCode::Esc => return true,
KeyCode::Up => game.try_move(Direction::North),
KeyCode::Down => game.try_move(Direction::South),
KeyCode::Left => game.try_move(Direction::West),
KeyCode::Right => game.try_move(Direction::East),
KeyCode::Up => try_move_with_transition(game, ui, Direction::North),
KeyCode::Down => try_move_with_transition(game, ui, Direction::South),
KeyCode::Left => try_move_with_transition(game, ui, Direction::West),
KeyCode::Right => try_move_with_transition(game, ui, Direction::East),
KeyCode::Char('l') => ui.log.toggle(),
KeyCode::PageUp if log_open => ui.log.scroll_by(-5, game.log.len()),
KeyCode::PageDown if log_open => ui.log.scroll_by(5, game.log.len()),