Refactor Undo and SaveLoad from disk.

This commit is contained in:
Oleg Sh
2023-12-03 13:40:50 +02:00
parent fdbff31a13
commit 00f35ebe71
5 changed files with 148 additions and 112 deletions

View File

@@ -0,0 +1,41 @@
// Undo Stack
function UndoStack(maxUndoStackSize) {
this.undoStack = [];
this.maxUndoStackSize = maxUndoStackSize;
}
UndoStack.prototype.PushToStack = function(actionName, dataToSave)
{
var object = {};
object.actionName = actionName;
object.data = dataToSave;
this.undoStack.push(object);
while (this.undoStack.length > this.maxUndoStackSize)
{
this.undoStack.shift();
}
}
UndoStack.prototype.Undo = function()
{
if (this.IsUndoStackEmpty())
return null;
var state = this.undoStack.pop();
return state.data;
}
UndoStack.prototype.ClearUndoStack = function()
{
this.undoStack = [];
}
UndoStack.prototype.IsUndoStackEmpty = function()
{
return (this.undoStack.length <= 0);
}