[Gameplay] Implement Action Undo / Rewind System#606
Merged
Conversation
## Summary Implements deterministic hover preview showing combat outcomes before committing an action. Color-coded by severity. ## Changes ### New: HoverPreviewManager - scripts/ui/hover_preview_manager.gd: Tooltip panel that follows mouse - Shows damage preview, HP after hit, AP cost when hovering enemies - Shows move cost, elevation bonus, cover info when hovering tiles - Color-coded severity: green (safe), yellow (warning), red (lethal) - Panel keeps itself inside viewport bounds ### CombatRoom integration - Instantiates HoverPreviewManager in UIOverlay during _setup_hud() - _input() detects mouse motion and updates preview via _update_hover_preview() - Checks _enemies_node for entity at hovered tile, falls back to tile info - Only active during PLAYER_TURN; hidden during enemy turn ### Tests - test_hover_preview.gd: 2 cases for severity display and clear behavior ## Testing - 392 tests | 0 errors | 0 failures | 72/72 suites - Headless editor scan: clean Closes #597
## Summary Adds a deterministic undo/rewind system for player actions within a turn. Players can now undo misclicks or re-experiment with tactics. ## Changes ### New: ActionHistory - scripts/core/action_history.gd: LIFO stack of state snapshots - serialize_entity() / restore_entity(): Full entity state capture and restore - Configurable depth limit (default unlimited per turn) - Lightweight RefCounted — no autoload needed ### CombatInput signals - Added action_about_to_execute signal, emitted before attack/move mutations - Emitted in _execute_attack() and _execute_move_to() ### CombatRoom integration - Instantiates ActionHistory during _ready - _push_snapshot() captures player + all enemy states before each action - _undo_last_action() restores most recent snapshot on Ctrl+Z or Backspace - Snapshot captured for: keyboard moves, mouse moves, attacks - History cleared at start of each player turn (fresh stack) - Visual feedback: brief camera shake + toast message on undo ### Tests - test_action_history.gd: 4 cases for serialize round-trip, LIFO stack, empty noop, and depth limit trimming ## Testing - 396 tests | 0 errors | 0 failures | 73/73 suites - Headless editor scan: clean Closes #596
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a deterministic undo/rewind system for player actions within a turn. Players can now undo misclicks or re-experiment with tactics without penalty.
Problem
Players had no way to recover from accidental misclicks. In a tactical roguelike where information is perfect, the inability to undo actions is a major friction point compared to genre leaders like Into the Breach.
Changes
New: ActionHistory
scripts/core/action_history.gd: LIFO stack of full-state snapshotsserialize_entity(): Captures x, y, elevation, facing, hp, ap, moral_flag, state, off, def, spdrestore_entity(): Restores all mutable entity fields deterministicallyset_limit(), default = unlimited per turn)RefCounted— no autoload neededCombatInput signals
action_about_to_execute(action_type: String)signal_execute_attack()before damage application_execute_move_to()before position mutationCombatRoom integration
ActionHistoryin_ready_push_snapshot(): Captures player + all enemy states before each action_undo_last_action(): Restores most recent snapshotCtrl+ZorBackspaceduring player turnSupported Actions
Tests
tests/test_action_history.gd: 4 casesEdge Cases Handled
Testing
Related Issues
Closes #596