Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Generally speaking, you should have a Stack of IMapChange, where IMapChange looks something like this:</p> <pre><code>public interface IMapChange { //Performs the change on a TileMap Boolean PerformChange(TileMap map); //Reverts the change on a TileMap Boolean RevertChange(TileMap map); } </code></pre> <p>You should have a method that is called to make changes:</p> <pre><code>public void SetTile(Vector2 position, int tileId) { Tile oldTile = Map.GetTile(position); Tile newTile = new Tile(position, tileId); MapChange change = new MapChange(oldTile, newTile); //Only push to cahngestacks if successfull if (change.PerformChange(Map)) { ChangeStack.Push(change); //We don't want you to be able to "redo" anymore if you do something new. RedoStack.Clear(); } } public void RemoveTile(Vector2 position) { Tile oldTile = Map.GetTile(position); Tile newTile = null; MapChange change = new MapChange(oldTile, newTile); //Only push to changestacks if successfull if (change.PerformChange(Map)) { ChangeStack.Push(change); //We don't want you to be able to "redo" anymore if you do something new. RedoStack.Clear(); } } </code></pre> <p>Undo can look like this:</p> <pre><code>public void Undo() { var lastChange = ChangeStack.Pop(); //Try to revert. If revert fails, put the change back in the stack if (!lastChange.RevertChange(Map)) ChangeStack.Push(lastChange); else RedoStack.Push(lastChange); } </code></pre> <p>and undo like this:</p> <pre><code>public void Redo() { var lastChange = RedoStack.Pop(); //Try to perform. If successfull, put back in ChangeStack if (lastChange.PerformChange(Map)) ChangeStack.Push(lastChange); else RedoStack.Push(lastChange); } </code></pre> <p>PerformChange and RevertChange are basicly:</p> <p>Perform:<br> - if oldTile is not null, try to remove it from map.<br> - insert newTile into map. </p> <p>Revert:<br> - if newTile is not null, tro to remove it from map<br> - insert oldTile into map. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload