mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 01:43:53 +02:00
Fix undo not coping with cloning with both hands simultaneously
This commit is contained in:
parent
b526ec0d93
commit
21d286b422
3 changed files with 23 additions and 30 deletions
|
@ -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 }] }
|
||||
);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue