initial editor mode
This commit is contained in:
+33
-16
@@ -6,6 +6,7 @@ use kiln_core::game::GameState;
|
||||
use crate::animation::Animation;
|
||||
use crate::log::LogState;
|
||||
use crate::menu::{MenuItem, MenuCloseAnimation, MenuOpenAnimation, MenuState};
|
||||
use crate::mode::{Mode, PendingMode};
|
||||
use crate::scroll_overlay::{ScrollCloseAnimation, ScrollOpenAnimation, ScrollOverlayState};
|
||||
use crate::transition::TransitionAnimation;
|
||||
|
||||
@@ -29,6 +30,11 @@ pub(crate) struct Ui {
|
||||
/// Set by a menu action to signal that the game loop should exit after the
|
||||
/// close animation finishes.
|
||||
pub(crate) should_quit: bool,
|
||||
/// Path to the world file, kept so the editor / play-reload can reload it.
|
||||
pub(crate) world_path: String,
|
||||
/// Set by a menu action to request a Play↔Edit switch; applied by the run loop
|
||||
/// (which owns [`world_path`](Ui::world_path) and can run the world reload).
|
||||
pub(crate) pending_mode: Option<PendingMode>,
|
||||
}
|
||||
|
||||
impl Default for Ui {
|
||||
@@ -40,6 +46,8 @@ impl Default for Ui {
|
||||
active_animation: None,
|
||||
menu: None,
|
||||
should_quit: false,
|
||||
world_path: String::new(),
|
||||
pending_mode: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,35 +80,44 @@ impl Ui {
|
||||
self.active_animation = Some(Box::new(MenuCloseAnimation::new(items)));
|
||||
}
|
||||
|
||||
/// Advances all time-driven UI state by `dt` and drives the game tick.
|
||||
/// Advances all time-driven UI state by `dt` and drives the active mode.
|
||||
///
|
||||
/// While any animation is running, `game.tick` is suppressed. When an
|
||||
/// While any animation is running, the mode's own tick is suppressed. When an
|
||||
/// animation finishes, [`input_mode_after`](Animation::input_mode_after) is
|
||||
/// consulted: returning to [`Board`](crate::input::InputMode::Board) mode
|
||||
/// eagerly calls [`handle_scroll`](GameState::handle_scroll) to clear any
|
||||
/// pending scroll, and clears [`menu`](Ui::menu) so the closed overlay is not
|
||||
/// rendered on the next frame.
|
||||
pub(crate) fn tick(&mut self, dt: Duration, game: &mut GameState) {
|
||||
/// eagerly calls [`handle_scroll`](GameState::handle_scroll) on the play game to
|
||||
/// clear any pending scroll, and clears [`menu`](Ui::menu) so the closed overlay
|
||||
/// is not rendered for an extra frame.
|
||||
///
|
||||
/// In [`Mode::Edit`] only the editor's cursor blink advances — the game never
|
||||
/// ticks while editing.
|
||||
pub(crate) fn tick(&mut self, dt: Duration, mode: &mut Mode) {
|
||||
// Advance the active animation; on completion, dispatch any mode-change effect.
|
||||
if let Some(ref mut anim) = self.active_animation {
|
||||
if anim.update(dt.as_secs_f32()) {
|
||||
let mode = anim.input_mode_after();
|
||||
let after = anim.input_mode_after();
|
||||
self.active_animation = None;
|
||||
// Returning to Board mode: eagerly clear scroll and menu state so
|
||||
// neither renders as open for one extra frame before the game tick.
|
||||
if matches!(mode, crate::input::InputMode::Board) {
|
||||
game.handle_scroll();
|
||||
// neither renders as open for one extra frame before the next tick.
|
||||
if matches!(after, crate::input::InputMode::Board) {
|
||||
if let Mode::Play(game) = mode { game.handle_scroll(); }
|
||||
self.menu = None;
|
||||
}
|
||||
}
|
||||
return; // no game tick during any animation (even when just ended)
|
||||
return; // no mode tick during any animation (even when just ended)
|
||||
}
|
||||
|
||||
// Normal path: tick the game, then check if a scroll appeared.
|
||||
game.tick(dt);
|
||||
if let Some(scroll) = &game.active_scroll {
|
||||
let lines = scroll.lines.clone();
|
||||
self.active_animation = Some(Box::new(ScrollOpenAnimation::new(lines)));
|
||||
match mode {
|
||||
// Play: tick the game, then check whether a scroll overlay appeared.
|
||||
Mode::Play(game) => {
|
||||
game.tick(dt);
|
||||
if let Some(scroll) = &game.active_scroll {
|
||||
let lines = scroll.lines.clone();
|
||||
self.active_animation = Some(Box::new(ScrollOpenAnimation::new(lines)));
|
||||
}
|
||||
}
|
||||
// Edit: only the cursor blink advances; the game does not exist here.
|
||||
Mode::Edit(editor) => editor.tick(dt.as_secs_f32()),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user