Platformer with Level Editor
import QtQuick 2.0
import Felgo 3.0
Item {
id: undoHandler
property var undoArray: []
property int pointer: -1
onPointerChanged: console.debug("undo pointer: "+pointer)
function createUndoObject(properties) {
var component = Qt.createComponent("../undo/UndoObject.qml")
var undoObject = component.createObject(gameScene, properties)
return undoObject
}
function push(undoObjectList) {
if(undoArray.length > pointer + 1)
undoArray.splice(pointer+1, undoArray.length)
undoArray.push(undoObjectList)
pointer++
}
function undo() {
if(undoArray[pointer]) {
for(var i=0; i<undoArray[pointer].length; i++) {
undoArray[pointer][i].undo()
}
pointer--
}
else {
console.debug("nothing to undo")
}
}
function redo() {
if(undoArray[pointer+1]) {
for(var i=0; i<undoArray[pointer+1].length; i++) {
undoArray[pointer+1][i].redo()
}
pointer++
}
else {
console.debug("nothing to redo")
}
}
function printArray() {
console.debug("print undoArray")
for(var i=0; i< undoArray.length; i++) {
for(var j=0; j<undoArray[i].length; j++) {
console.debug(i+"-"+j+": "+undoArray[i][j].target+", "+undoArray[i][j].action+", "+undoArray[i][j].otherPosition+", "+undoArray[i][j].currentPosition)
}
}
}
function reset() {
undoArray = []
pointer = -1