# 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.
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.
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 |
# 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 |
# 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 |
# 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 |
# 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.
# 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) |
# static constructor(maxSizeopt)
Creates a new RezUndoManager.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
maxSize |
number
|
<optional> |
16 | Maximum number of change records to keep |