TerrainEditHistory

Package: Libraries.Game.Graphics.Worlds · Inherits from: Libraries.Language.Object

A TerrainEditHistory keeps the undo and redo lists for editing a terrain: one TerrainStrokeEdit per stroke. It works like the standard library's EditManager, with one addition: a limit on how much memory the edits may use. Each edit holds copies of whole regions, so a long editing session could otherwise use a lot of memory. When the edits go over the limit, the oldest ones are let go, so they can no longer be undone. The newest edit is always kept. Adding a new edit empties the redo list, as in any editor: once something new is done, what was undone can't be redone. Undo and Redo change the TerrainData. Afterward, call the WorldTerrain's Rebuild to redraw what changed.

Example Code

use Libraries.Game.Graphics.Worlds.TerrainEditHistory
use Libraries.Game.Graphics.Worlds.TerrainStrokeEdit

TerrainEditHistory history
// After each stroke:
history:Add(stroke:End())
// When the user asks to undo:
if history:CanUndo()
output history:Undo():GetUndoName()
end

Actions

Add(Libraries.Game.Graphics.Worlds.TerrainStrokeEdit edit)

This action adds the edit from a finished stroke to the undo list, and empties the redo list. If the edits then use more memory than the limit, the oldest are let go. An undefined edit, from a stroke that changed nothing, is ignored.

Parameters

CanRedo()

This action returns true if there is an edit to redo.

Returns

boolean: True if Redo would do something.

CanUndo()

This action returns true if there is an edit to undo.

Returns

boolean: True if Undo would do something.

Empty()

This action lets go of every edit, so nothing can be undone or redone.

GetMemoryLimit()

This action returns the most memory the edits may use.

Returns

integer: The limit in bytes.

GetMemorySize()

This action returns about how much memory all the edits use.

Returns

integer: The size in bytes.

GetRedoCount()

This action returns how many edits can be redone.

Returns

integer: The number of edits in the redo list.

GetRedoName()

This action returns the name of what Redo would do, such as "Redo raise".

Returns

text: The name, or "Nothing to redo".

GetUndoCount()

This action returns how many edits can be undone.

Returns

integer: The number of edits in the undo list.

GetUndoName()

This action returns the name of what Undo would do, such as "Undo raise".

Returns

text: The name, or "Nothing to undo".

Redo()

This action redoes the most recently undone edit, and moves it back to the undo list.

Returns

Libraries.Game.Graphics.Worlds.TerrainStrokeEdit: The edit that was redone, or undefined if there was nothing to redo.

SetMemoryLimit(integer bytes)

This action sets the most memory the edits may use. If they already use more, the oldest are let go now.

Parameters

  • bytes integer: The limit in bytes. It must be more than 0.

Undo()

This action undoes the newest edit, and moves it to the redo list.

Returns

Libraries.Game.Graphics.Worlds.TerrainStrokeEdit: The edit that was undone, or undefined if there was nothing to undo.

Inherited Actions

3 actions from Libraries.Language.Object