Class

RezUndoManager

RezUndoManager()

Constructor

# new RezUndoManager()

Manages undo functionality by tracking changes to game state.

The undo manager records changes made during each turn/action and allows reverting to previous states. It tracks:

  • Attribute changes on game elements
  • Newly created elements
  • Removed elements
  • View state changes

Changes are grouped into "change records" that represent a single undoable action. When undo is triggered, all changes in the most recent record are reverted together.

The manager maintains a fixed-size history (default 16 records) to limit memory usage. Older records are automatically discarded when the limit is reached.

Note: The undo manager automatically ignores changes made during an undo operation to prevent infinite loops.

View Source rez_undo_manager.js, line 5

Example
// Undo is typically triggered via game events
if($game.undoManager.canUndo) {
  $game.undoManager.undo();
}

Members

boolean

# canUndo

Whether an undo operation is possible.

Returns false if currently performing an undo or if history is empty.

View Source rez_undo_manager.js, line 69

Array | null

# curChange

The current (most recent) change record, or null if empty.

View Source rez_undo_manager.js, line 85

number

# historySize

The number of change records in history.

View Source rez_undo_manager.js, line 77

boolean

# performingUndo

Whether an undo operation is currently in progress.

View Source rez_undo_manager.js, line 93

Methods

# recordAttributeChange(elemId, attrName, oldValue)

Records an attribute change on an element.

When undone, the attribute will be restored to its old value.

Parameters:
Name Type Description
elemId string

The ID of the element

attrName string

The name of the changed attribute

oldValue *

The previous value of the attribute

View Source rez_undo_manager.js, line 170

# recordNewElement(elemId)

Records the creation of a new element.

When undone, the element will be unmapped (removed from the game).

Parameters:
Name Type Description
elemId string

The ID of the newly created element

View Source rez_undo_manager.js, line 124

# recordRemoveElement(elem)

Records the removal of an element.

When undone, the element will be restored to the game.

Parameters:
Name Type Description
elem Object

The element being removed

View Source rez_undo_manager.js, line 152

# recordViewChange(view)

Records a view state change.

When undone, the view will be restored to its previous state.

Parameters:
Name Type Description
view RezView

A copy of the view state to restore

View Source rez_undo_manager.js, line 188

# reset()

Resets the undo manager, clearing all history.

View Source rez_undo_manager.js, line 57

# startChange()

Starts a new change record.

Call this at the beginning of each undoable action. All subsequent recorded changes will be grouped into this record until the next call to startChange().

If the history is full, the oldest record is discarded. Does nothing if an undo operation is in progress.

View Source rez_undo_manager.js, line 107

# undo(manualUndoopt)

Undoes the most recent change record.

Reverts all changes in the record in reverse order. Sets a flag to prevent recording changes made during the undo.

Parameters:
Name Type Attributes Default Description
manualUndo boolean <optional>
false

If true, doesn't discard the current change record (used when undo is triggered manually rather than by an event)

View Source rez_undo_manager.js, line 206

# static constructor(maxSizeopt)

Creates a new RezUndoManager.

Parameters:
Name Type Attributes Default Description
maxSize number <optional>
16

Maximum number of change records to keep

View Source rez_undo_manager.js, line 42