mirror of
https://github.com/overte-org/overte.git
synced 2025-04-15 08:26:36 +02:00
Merge pull request #13686 from huffman/fix/undo-create-entity
Fix added entities not being undoable in Create
This commit is contained in:
commit
f02e91806c
1 changed files with 43 additions and 22 deletions
|
@ -316,10 +316,10 @@ var toolBar = (function () {
|
||||||
direction = Vec3.multiplyQbyV(direction, Vec3.UNIT_Z);
|
direction = Vec3.multiplyQbyV(direction, Vec3.UNIT_Z);
|
||||||
// Align entity with Avatar orientation.
|
// Align entity with Avatar orientation.
|
||||||
properties.rotation = MyAvatar.orientation;
|
properties.rotation = MyAvatar.orientation;
|
||||||
|
|
||||||
var PRE_ADJUST_ENTITY_TYPES = ["Box", "Sphere", "Shape", "Text", "Web", "Material"];
|
var PRE_ADJUST_ENTITY_TYPES = ["Box", "Sphere", "Shape", "Text", "Web", "Material"];
|
||||||
if (PRE_ADJUST_ENTITY_TYPES.indexOf(properties.type) !== -1) {
|
if (PRE_ADJUST_ENTITY_TYPES.indexOf(properties.type) !== -1) {
|
||||||
|
|
||||||
// Adjust position of entity per bounding box prior to creating it.
|
// Adjust position of entity per bounding box prior to creating it.
|
||||||
var registration = properties.registration;
|
var registration = properties.registration;
|
||||||
if (registration === undefined) {
|
if (registration === undefined) {
|
||||||
|
@ -352,7 +352,12 @@ var toolBar = (function () {
|
||||||
properties.userData = JSON.stringify({ grabbableKey: { grabbable: false } });
|
properties.userData = JSON.stringify({ grabbableKey: { grabbable: false } });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SelectionManager.saveProperties();
|
||||||
entityID = Entities.addEntity(properties);
|
entityID = Entities.addEntity(properties);
|
||||||
|
pushCommandForSelections([{
|
||||||
|
entityID: entityID,
|
||||||
|
properties: properties
|
||||||
|
}], [], true);
|
||||||
|
|
||||||
if (properties.type === "ParticleEffect") {
|
if (properties.type === "ParticleEffect") {
|
||||||
selectParticleEntity(entityID);
|
selectParticleEntity(entityID);
|
||||||
|
@ -1592,7 +1597,7 @@ function deleteSelectedEntities() {
|
||||||
Entities.deleteEntity(entityID);
|
Entities.deleteEntity(entityID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (savedProperties.length > 0) {
|
if (savedProperties.length > 0) {
|
||||||
SelectionManager.clearSelections();
|
SelectionManager.clearSelections();
|
||||||
pushCommandForSelections([], savedProperties);
|
pushCommandForSelections([], savedProperties);
|
||||||
|
@ -1882,12 +1887,14 @@ Controller.keyReleaseEvent.connect(keyReleaseEvent);
|
||||||
Controller.keyPressEvent.connect(keyPressEvent);
|
Controller.keyPressEvent.connect(keyPressEvent);
|
||||||
|
|
||||||
function recursiveAdd(newParentID, parentData) {
|
function recursiveAdd(newParentID, parentData) {
|
||||||
var children = parentData.children;
|
if (parentData.children !== undefined) {
|
||||||
for (var i = 0; i < children.length; i++) {
|
var children = parentData.children;
|
||||||
var childProperties = children[i].properties;
|
for (var i = 0; i < children.length; i++) {
|
||||||
childProperties.parentID = newParentID;
|
var childProperties = children[i].properties;
|
||||||
var newChildID = Entities.addEntity(childProperties);
|
childProperties.parentID = newParentID;
|
||||||
recursiveAdd(newChildID, children[i]);
|
var newChildID = Entities.addEntity(childProperties);
|
||||||
|
recursiveAdd(newChildID, children[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1897,16 +1904,22 @@ function recursiveAdd(newParentID, parentData) {
|
||||||
var DELETED_ENTITY_MAP = {};
|
var DELETED_ENTITY_MAP = {};
|
||||||
|
|
||||||
function applyEntityProperties(data) {
|
function applyEntityProperties(data) {
|
||||||
var properties = data.setProperties;
|
var editEntities = data.editEntities;
|
||||||
var selectedEntityIDs = [];
|
var selectedEntityIDs = [];
|
||||||
|
var selectEdits = data.createEntities.length == 0 || !data.selectCreated;
|
||||||
var i, entityID;
|
var i, entityID;
|
||||||
for (i = 0; i < properties.length; i++) {
|
for (i = 0; i < editEntities.length; i++) {
|
||||||
entityID = properties[i].entityID;
|
var entityID = editEntities[i].entityID;
|
||||||
if (DELETED_ENTITY_MAP[entityID] !== undefined) {
|
if (DELETED_ENTITY_MAP[entityID] !== undefined) {
|
||||||
entityID = DELETED_ENTITY_MAP[entityID];
|
entityID = DELETED_ENTITY_MAP[entityID];
|
||||||
}
|
}
|
||||||
Entities.editEntity(entityID, properties[i].properties);
|
var entityProperties = editEntities[i].properties;
|
||||||
selectedEntityIDs.push(entityID);
|
if (entityProperties !== null) {
|
||||||
|
Entities.editEntity(entityID, entityProperties);
|
||||||
|
}
|
||||||
|
if (selectEdits) {
|
||||||
|
selectedEntityIDs.push(entityID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (i = 0; i < data.createEntities.length; i++) {
|
for (i = 0; i < data.createEntities.length; i++) {
|
||||||
entityID = data.createEntities[i].entityID;
|
entityID = data.createEntities[i].entityID;
|
||||||
|
@ -1935,31 +1948,39 @@ function applyEntityProperties(data) {
|
||||||
|
|
||||||
// For currently selected entities, push a command to the UndoStack that uses the current entity properties for the
|
// For currently selected entities, push a command to the UndoStack that uses the current entity properties for the
|
||||||
// redo command, and the saved properties for the undo command. Also, include create and delete entity data.
|
// redo command, and the saved properties for the undo command. Also, include create and delete entity data.
|
||||||
function pushCommandForSelections(createdEntityData, deletedEntityData) {
|
function pushCommandForSelections(createdEntityData, deletedEntityData, doNotSaveEditProperties) {
|
||||||
|
doNotSaveEditProperties = false;
|
||||||
var undoData = {
|
var undoData = {
|
||||||
setProperties: [],
|
editEntities: [],
|
||||||
createEntities: deletedEntityData || [],
|
createEntities: deletedEntityData || [],
|
||||||
deleteEntities: createdEntityData || [],
|
deleteEntities: createdEntityData || [],
|
||||||
selectCreated: true
|
selectCreated: true
|
||||||
};
|
};
|
||||||
var redoData = {
|
var redoData = {
|
||||||
setProperties: [],
|
editEntities: [],
|
||||||
createEntities: createdEntityData || [],
|
createEntities: createdEntityData || [],
|
||||||
deleteEntities: deletedEntityData || [],
|
deleteEntities: deletedEntityData || [],
|
||||||
selectCreated: false
|
selectCreated: true
|
||||||
};
|
};
|
||||||
for (var i = 0; i < SelectionManager.selections.length; i++) {
|
for (var i = 0; i < SelectionManager.selections.length; i++) {
|
||||||
var entityID = SelectionManager.selections[i];
|
var entityID = SelectionManager.selections[i];
|
||||||
var initialProperties = SelectionManager.savedProperties[entityID];
|
var initialProperties = SelectionManager.savedProperties[entityID];
|
||||||
var currentProperties = Entities.getEntityProperties(entityID);
|
var currentProperties = null;
|
||||||
if (!initialProperties) {
|
if (!initialProperties) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
undoData.setProperties.push({
|
|
||||||
|
if (doNotSaveEditProperties) {
|
||||||
|
initialProperties = null;
|
||||||
|
} else {
|
||||||
|
currentProperties = Entities.getEntityProperties(entityID);
|
||||||
|
}
|
||||||
|
|
||||||
|
undoData.editEntities.push({
|
||||||
entityID: entityID,
|
entityID: entityID,
|
||||||
properties: initialProperties
|
properties: initialProperties
|
||||||
});
|
});
|
||||||
redoData.setProperties.push({
|
redoData.editEntities.push({
|
||||||
entityID: entityID,
|
entityID: entityID,
|
||||||
properties: currentProperties
|
properties: currentProperties
|
||||||
});
|
});
|
||||||
|
@ -2231,7 +2252,7 @@ var PropertiesTool = function (opts) {
|
||||||
updateSelections(true);
|
updateSelections(true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
createToolsWindow.webEventReceived.addListener(this, onWebEventReceived);
|
createToolsWindow.webEventReceived.addListener(this, onWebEventReceived);
|
||||||
|
|
||||||
webView.webEventReceived.connect(onWebEventReceived);
|
webView.webEventReceived.connect(onWebEventReceived);
|
||||||
|
|
Loading…
Reference in a new issue