mirror of
https://github.com/ninjamuffin99/Funkin.git
synced 2024-09-12 05:07:06 +00:00
undo of movements
This commit is contained in:
parent
1f91c3bdef
commit
58cede8706
|
@ -11,6 +11,7 @@ class SprStage extends FlxSprite
|
||||||
public var mousePressing:Bool = false;
|
public var mousePressing:Bool = false;
|
||||||
|
|
||||||
public var mouseOffset:FlxPoint = FlxPoint.get(0, 0);
|
public var mouseOffset:FlxPoint = FlxPoint.get(0, 0);
|
||||||
|
public var oldPos:FlxPoint = FlxPoint.get(0, 0);
|
||||||
|
|
||||||
public function new(?x:Float = 0, ?y:Float = 0, dragShitFunc:SprStage->Void)
|
public function new(?x:Float = 0, ?y:Float = 0, dragShitFunc:SprStage->Void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -221,6 +221,14 @@ class StageBuilderState extends MusicBeatState
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (curTool == GRABBING && FlxG.mouse.justReleased)
|
||||||
|
{
|
||||||
|
moveSprPos([
|
||||||
|
curSelectedSpr.x - curSelectedSpr.oldPos.x,
|
||||||
|
curSelectedSpr.y - curSelectedSpr.oldPos.y
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
if (FlxG.keys.justPressed.Z && actionQueue.length > 0)
|
if (FlxG.keys.justPressed.Z && actionQueue.length > 0)
|
||||||
{
|
{
|
||||||
trace('UNDO - QUEUE LENGTH: ' + actionQueue.length);
|
trace('UNDO - QUEUE LENGTH: ' + actionQueue.length);
|
||||||
|
@ -250,16 +258,21 @@ class StageBuilderState extends MusicBeatState
|
||||||
}
|
}
|
||||||
|
|
||||||
function changeCurSelected(spr:SprStage)
|
function changeCurSelected(spr:SprStage)
|
||||||
|
{
|
||||||
|
undoRedoCheck(changeCurSelected, curSelectedSpr);
|
||||||
|
curSelectedSpr = spr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// base check to see if its in a state of undo or redo
|
||||||
|
function undoRedoCheck(daFunc:Dynamic->Void, daValue:Dynamic)
|
||||||
{
|
{
|
||||||
if (!isUndoRedo)
|
if (!isUndoRedo)
|
||||||
{
|
{
|
||||||
actionQueue.push(changeCurSelected);
|
actionQueue.push(daFunc);
|
||||||
posQueue.push(curSelectedSpr);
|
posQueue.push(daValue);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
isUndoRedo = false;
|
isUndoRedo = false;
|
||||||
|
|
||||||
curSelectedSpr = spr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function sprDragShitFunc(spr:SprStage)
|
function sprDragShitFunc(spr:SprStage)
|
||||||
|
@ -272,10 +285,30 @@ class StageBuilderState extends MusicBeatState
|
||||||
if (spr.isSelected())
|
if (spr.isSelected())
|
||||||
changeTool(GRABBING);
|
changeTool(GRABBING);
|
||||||
spr.mouseOffset.set(FlxG.mouse.x - spr.x, FlxG.mouse.y - spr.y);
|
spr.mouseOffset.set(FlxG.mouse.x - spr.x, FlxG.mouse.y - spr.y);
|
||||||
|
spr.oldPos.set(spr.x, spr.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
// make function for changing cur selection
|
// make function for changing cur selection
|
||||||
function moveSprPos(xDiff:Float, yDiff:Float) {}
|
function moveSprPos(dumbArray:Array<Dynamic>)
|
||||||
|
{
|
||||||
|
var xDiff:Float = dumbArray[0];
|
||||||
|
var yDiff:Float = dumbArray[1];
|
||||||
|
var forceMove:Bool = dumbArray[2];
|
||||||
|
|
||||||
|
// if (forceMove == null)
|
||||||
|
// forceMove = false;
|
||||||
|
|
||||||
|
trace(xDiff);
|
||||||
|
trace(yDiff);
|
||||||
|
|
||||||
|
if (forceMove)
|
||||||
|
{
|
||||||
|
curSelectedSpr.x += xDiff;
|
||||||
|
curSelectedSpr.y += yDiff;
|
||||||
|
}
|
||||||
|
|
||||||
|
undoRedoCheck(moveSprPos, [-xDiff, -yDiff, true]);
|
||||||
|
}
|
||||||
|
|
||||||
var isUndoRedo:Bool = false;
|
var isUndoRedo:Bool = false;
|
||||||
var actionQueue:Array<Dynamic->Void> = [];
|
var actionQueue:Array<Dynamic->Void> = [];
|
||||||
|
@ -291,14 +324,7 @@ class StageBuilderState extends MusicBeatState
|
||||||
// NOTE: fix to account if only one layer is in?
|
// NOTE: fix to account if only one layer is in?
|
||||||
|
|
||||||
sortSprGrp();
|
sortSprGrp();
|
||||||
|
undoRedoCheck(moveLayer, layerMovement * -1);
|
||||||
if (!isUndoRedo)
|
|
||||||
{
|
|
||||||
actionQueue.push(moveLayer);
|
|
||||||
posQueue.push(layerMovement * -1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
isUndoRedo = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var isShaking:Bool = false;
|
var isShaking:Bool = false;
|
||||||
|
|
Loading…
Reference in a new issue