Skip to content

[Gameplay] Implement Action Undo / Rewind System#606

Merged
niyazmft merged 3 commits into
mainfrom
feat/action-undo-rewind-system
Jul 13, 2026
Merged

[Gameplay] Implement Action Undo / Rewind System#606
niyazmft merged 3 commits into
mainfrom
feat/action-undo-rewind-system

Conversation

@niyazmft

Copy link
Copy Markdown
Owner

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 snapshots
  • serialize_entity(): Captures x, y, elevation, facing, hp, ap, moral_flag, state, off, def, spd
  • restore_entity(): Restores all mutable entity fields deterministically
  • Configurable depth limit (set_limit(), default = unlimited per turn)
  • Lightweight RefCounted — no autoload needed

CombatInput signals

  • Added action_about_to_execute(action_type: String) signal
  • Emitted in _execute_attack() before damage application
  • Emitted in _execute_move_to() before position mutation

CombatRoom integration

  • Instantiates ActionHistory in _ready
  • _push_snapshot(): Captures player + all enemy states before each action
  • _undo_last_action(): Restores most recent snapshot
  • Input: Ctrl+Z or Backspace during player turn
  • History cleared at start of each player turn (fresh stack per turn)
  • Visual feedback: brief camera shake + toast message on undo

Supported Actions

Action Undoable?
Keyboard move (WASD/Arrows) ✅ Yes
Mouse move (click target tile) ✅ Yes
Attack (targeted + confirmed) ✅ Yes
End turn ❌ No (irreversible)
Enemy actions ❌ No (not player actions)

Tests

  • tests/test_action_history.gd: 4 cases
    • Serialize / restore round-trip
    • LIFO stack ordering
    • Empty undo is graceful no-op
    • Depth limit trims old snapshots

Edge Cases Handled

Scenario Behavior
Undo with empty history Silent no-op, no crash
Undo during enemy turn Ignored (input blocked)
Undo after turn ended Not possible (stack cleared)
Enemy killed then undone Enemy HP restored; enemy "resurrected" in place

Testing

  • 396 tests | 0 errors | 0 failures | 73/73 suites
  • Headless editor scan: clean

Related Issues

Closes #596

niyazmft added 3 commits July 12, 2026 23:31
## 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
@niyazmft
niyazmft merged commit 3d7e0d2 into main Jul 13, 2026
5 checks passed
@niyazmft
niyazmft deleted the feat/action-undo-rewind-system branch July 13, 2026 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Gameplay] Implement Action Undo / Rewind System (GAME-UX-1)

1 participant