From 21d286b4220111c0ff07f4932acfa1bf9d1c1b4b Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 6 Oct 2017 10:04:14 +1300 Subject: [PATCH] Fix undo not coping with cloning with both hands simultaneously --- scripts/shapes/modules/createPalette.js | 1 + scripts/shapes/modules/history.js | 24 ++++++++++----------- scripts/shapes/modules/selection.js | 28 +++++++++---------------- 3 files changed, 23 insertions(+), 30 deletions(-) diff --git a/scripts/shapes/modules/createPalette.js b/scripts/shapes/modules/createPalette.js index 694705cb2f..0eea8379d6 100644 --- a/scripts/shapes/modules/createPalette.js +++ b/scripts/shapes/modules/createPalette.js @@ -405,6 +405,7 @@ CreatePalette = function (side, leftInputs, rightInputs, uiCommandCallback) { entityID = Entities.addEntity(properties); if (entityID !== Uuid.NULL) { History.prePush( + otherSide, { deleteEntities: [{ entityID: entityID }] }, { createEntities: [{ entityID: entityID, properties: properties }] } ); diff --git a/scripts/shapes/modules/history.js b/scripts/shapes/modules/history.js index 7065a3c52b..4b84a5699d 100644 --- a/scripts/shapes/modules/history.js +++ b/scripts/shapes/modules/history.js @@ -47,8 +47,8 @@ History = (function () { ], MAX_HISTORY_ITEMS = 1000, undoPosition = -1, // The next history item to undo; the next history item to redo = undoIndex + 1. - undoData = {}, - redoData = {}; + undoData = [{}, {}], + redoData = [{}, {}]; function doKick(entityID) { var properties, @@ -73,16 +73,16 @@ History = (function () { }, KICK_DELAY); } - function prePush(undo, redo) { - // Stores undo and redo data to include in the next history entry. - undoData = undo; - redoData = redo; + function prePush(side, undo, redo) { + // Stores undo and redo data to include in the next history entry generated for the side. + undoData[side] = undo; + redoData[side] = redo; } - function push(undo, redo) { + function push(side, undo, redo) { // Add a history entry. - undoData = Object.merge(undoData, undo); - redoData = Object.merge(redoData, redo); + undoData[side] = Object.merge(undoData[side], undo); + redoData[side] = Object.merge(redoData[side], redo); // Wipe any redo history after current undo position. if (undoPosition < history.length - 1) { @@ -95,11 +95,11 @@ History = (function () { undoPosition = history.length - 1; } - history.push({ undoData: undoData, redoData: redoData }); + history.push({ undoData: undoData[side], redoData: redoData[side] }); undoPosition++; - undoData = {}; - redoData = {}; + undoData[side] = {}; + redoData[side] = {}; } function updateEntityIDs(oldEntityID, newEntityID) { diff --git a/scripts/shapes/modules/selection.js b/scripts/shapes/modules/selection.js index afa0da5fd2..5720e0bee0 100644 --- a/scripts/shapes/modules/selection.js +++ b/scripts/shapes/modules/selection.js @@ -282,6 +282,7 @@ SelectionManager = function (side) { && (!Vec3.equal(startPosition, rootPosition) || !Quat.equal(startOrientation, rootOrientation))) { // Positions and orientations can be identical if change grabbing hands when finish scaling. History.push( + side, { setProperties: [ { entityID: rootEntityID, properties: { position: startPosition, rotation: startOrientation } } @@ -331,6 +332,7 @@ SelectionManager = function (side) { if (Vec3.distance(startPosition, rootPosition) >= MIN_HISTORY_MOVE_DISTANCE || Quat.rotationBetween(startOrientation, rootOrientation) >= MIN_HISTORY_ROTATE_ANGLE) { History.push( + side, { setProperties: [ { entityID: rootEntityID, properties: { position: startPosition, rotation: startOrientation } } @@ -426,10 +428,7 @@ SelectionManager = function (side) { } // Add history entry. - History.push( - { setProperties: undoData }, - { setProperties: redoData } - ); + History.push(side, { setProperties: undoData }, { setProperties: redoData }); // Update grab start data for its undo. startPosition = rootPosition; @@ -445,6 +444,7 @@ SelectionManager = function (side) { if (Vec3.distance(startPosition, rootPosition) >= MIN_HISTORY_MOVE_DISTANCE || Quat.rotationBetween(startOrientation, rootOrientation) >= MIN_HISTORY_ROTATE_ANGLE) { History.push( + side, { setProperties: [ { entityID: rootEntityID, properties: { position: startPosition, rotation: startOrientation } } @@ -542,10 +542,7 @@ SelectionManager = function (side) { } // Add history entry. - History.push( - { setProperties: undoData }, - { setProperties: redoData } - ); + History.push(side, { setProperties: undoData }, { setProperties: redoData }); // Update grab start data for its undo. startPosition = rootPosition; @@ -593,10 +590,7 @@ SelectionManager = function (side) { rootEntityID = selection[0].id; // Add history entry. - History.prePush( - { deleteEntities: undoData }, - { createEntities: redoData } - ); + History.prePush(side, { deleteEntities: undoData }, { createEntities: redoData }); } function applyColor(color, isApplyToAll) { @@ -621,7 +615,7 @@ SelectionManager = function (side) { } } if (undoData.length > 0) { - History.push({ setProperties: undoData }, { setProperties: redoData }); + History.push(side, { setProperties: undoData }, { setProperties: redoData }); } } else { properties = Entities.getEntityProperties(intersectedEntityID, ["type", "color"]); @@ -630,6 +624,7 @@ SelectionManager = function (side) { color: color }); History.push( + side, { setProperties: [{ entityID: intersectedEntityID, properties: { color: properties.color } }] }, { setProperties: [{ entityID: intersectedEntityID, properties: { color: color } }] } ); @@ -740,10 +735,7 @@ SelectionManager = function (side) { }); // Add history entry. - History.push( - { setProperties: undoData }, - { setProperties: redoData } - ); + History.push(side, { setProperties: undoData }, { setProperties: redoData }); // Kick off physics if necessary. if (physicsProperties.dynamic) { @@ -759,7 +751,7 @@ SelectionManager = function (side) { function deleteEntities() { if (rootEntityID) { - History.push({ createEntities: selectionProperties }, { deleteEntities: [{ entityID: rootEntityID }] }); + History.push(side, { createEntities: selectionProperties }, { deleteEntities: [{ entityID: rootEntityID }] }); Entities.deleteEntity(rootEntityID); // Children are automatically deleted. clear(); }