mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-24 00:54:26 +02:00
Merge pull request #14806 from thoys/fix/create/mismatchingEntityHostTypeChildren
MS20893 [CreateApp] Ignore children of mismatching entityHostTypes
This commit is contained in:
commit
9c8e21ec6b
2 changed files with 68 additions and 27 deletions
|
@ -1608,23 +1608,35 @@ function sortSelectedEntities(selected) {
|
||||||
return sortedEntities;
|
return sortedEntities;
|
||||||
}
|
}
|
||||||
|
|
||||||
function recursiveDelete(entities, childrenList, deletedIDs) {
|
function recursiveDelete(entities, childrenList, deletedIDs, entityHostType) {
|
||||||
|
var wantDebug = false;
|
||||||
var entitiesLength = entities.length;
|
var entitiesLength = entities.length;
|
||||||
for (var i = 0; i < entitiesLength; i++) {
|
var initialPropertySets = Entities.getMultipleEntityProperties(entities);
|
||||||
|
var entityHostTypes = Entities.getMultipleEntityProperties(entities, 'entityHostType');
|
||||||
|
for (var i = 0; i < entitiesLength; ++i) {
|
||||||
var entityID = entities[i];
|
var entityID = entities[i];
|
||||||
|
|
||||||
|
if (entityHostTypes[i].entityHostType !== entityHostType) {
|
||||||
|
if (wantDebug) {
|
||||||
|
console.log("Skipping deletion of entity " + entityID + " with conflicting entityHostType: " +
|
||||||
|
entityHostTypes[i].entityHostType);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
var children = Entities.getChildrenIDs(entityID);
|
var children = Entities.getChildrenIDs(entityID);
|
||||||
var grandchildrenList = [];
|
var grandchildrenList = [];
|
||||||
recursiveDelete(children, grandchildrenList, deletedIDs);
|
recursiveDelete(children, grandchildrenList, deletedIDs, entityHostType);
|
||||||
var initialProperties = Entities.getEntityProperties(entityID);
|
|
||||||
childrenList.push({
|
childrenList.push({
|
||||||
entityID: entityID,
|
entityID: entityID,
|
||||||
properties: initialProperties,
|
properties: initialPropertySets[i],
|
||||||
children: grandchildrenList
|
children: grandchildrenList
|
||||||
});
|
});
|
||||||
deletedIDs.push(entityID);
|
deletedIDs.push(entityID);
|
||||||
Entities.deleteEntity(entityID);
|
Entities.deleteEntity(entityID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function unparentSelectedEntities() {
|
function unparentSelectedEntities() {
|
||||||
if (SelectionManager.hasSelection()) {
|
if (SelectionManager.hasSelection()) {
|
||||||
var selectedEntities = selectionManager.selections;
|
var selectedEntities = selectionManager.selections;
|
||||||
|
@ -1694,13 +1706,17 @@ function deleteSelectedEntities() {
|
||||||
SelectionManager.saveProperties();
|
SelectionManager.saveProperties();
|
||||||
var savedProperties = [];
|
var savedProperties = [];
|
||||||
var newSortedSelection = sortSelectedEntities(selectionManager.selections);
|
var newSortedSelection = sortSelectedEntities(selectionManager.selections);
|
||||||
for (var i = 0; i < newSortedSelection.length; i++) {
|
var entityHostTypes = Entities.getMultipleEntityProperties(newSortedSelection, 'entityHostType');
|
||||||
|
for (var i = 0; i < newSortedSelection.length; ++i) {
|
||||||
var entityID = newSortedSelection[i];
|
var entityID = newSortedSelection[i];
|
||||||
var initialProperties = SelectionManager.savedProperties[entityID];
|
var initialProperties = SelectionManager.savedProperties[entityID];
|
||||||
if (!initialProperties.locked) {
|
if (initialProperties.locked ||
|
||||||
|
(initialProperties.avatarEntity && initialProperties.owningAvatarID !== MyAvatar.sessionUUID)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
var children = Entities.getChildrenIDs(entityID);
|
var children = Entities.getChildrenIDs(entityID);
|
||||||
var childList = [];
|
var childList = [];
|
||||||
recursiveDelete(children, childList, deletedIDs);
|
recursiveDelete(children, childList, deletedIDs, entityHostTypes[i].entityHostType);
|
||||||
savedProperties.push({
|
savedProperties.push({
|
||||||
entityID: entityID,
|
entityID: entityID,
|
||||||
properties: initialProperties,
|
properties: initialProperties,
|
||||||
|
@ -1709,7 +1725,6 @@ function deleteSelectedEntities() {
|
||||||
deletedIDs.push(entityID);
|
deletedIDs.push(entityID);
|
||||||
Entities.deleteEntity(entityID);
|
Entities.deleteEntity(entityID);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (savedProperties.length > 0) {
|
if (savedProperties.length > 0) {
|
||||||
SelectionManager.clearSelections(this);
|
SelectionManager.clearSelections(this);
|
||||||
|
|
|
@ -193,14 +193,25 @@ SelectionManager = (function() {
|
||||||
that._update(true, caller);
|
that._update(true, caller);
|
||||||
};
|
};
|
||||||
|
|
||||||
that.addChildrenEntities = function(parentEntityID, entityList) {
|
that.addChildrenEntities = function(parentEntityID, entityList, entityHostType) {
|
||||||
|
var wantDebug = false;
|
||||||
var children = Entities.getChildrenIDs(parentEntityID);
|
var children = Entities.getChildrenIDs(parentEntityID);
|
||||||
|
var entityHostTypes = Entities.getMultipleEntityProperties(children, 'entityHostType');
|
||||||
for (var i = 0; i < children.length; i++) {
|
for (var i = 0; i < children.length; i++) {
|
||||||
var childID = children[i];
|
var childID = children[i];
|
||||||
|
|
||||||
|
if (entityHostTypes[i].entityHostType !== entityHostType) {
|
||||||
|
if (wantDebug) {
|
||||||
|
console.log("Skipping addition of entity " + childID + " with conflicting entityHostType: " +
|
||||||
|
entityHostTypes[i].entityHostType);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (entityList.indexOf(childID) < 0) {
|
if (entityList.indexOf(childID) < 0) {
|
||||||
entityList.push(childID);
|
entityList.push(childID);
|
||||||
}
|
}
|
||||||
that.addChildrenEntities(childID, entityList);
|
that.addChildrenEntities(childID, entityList, entityHostType);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -250,12 +261,15 @@ SelectionManager = (function() {
|
||||||
SelectionManager.saveProperties();
|
SelectionManager.saveProperties();
|
||||||
|
|
||||||
// build list of entities to duplicate by including any unselected children of selected parent entities
|
// build list of entities to duplicate by including any unselected children of selected parent entities
|
||||||
Object.keys(that.savedProperties).forEach(function(originalEntityID) {
|
var originalEntityIDs = Object.keys(that.savedProperties);
|
||||||
if (entitiesToDuplicate.indexOf(originalEntityID) < 0) {
|
var entityHostTypes = Entities.getMultipleEntityProperties(originalEntityIDs, 'entityHostType');
|
||||||
|
for (var i = 0; i < originalEntityIDs.length; i++) {
|
||||||
|
var originalEntityID = originalEntityIDs[i];
|
||||||
|
if (entitiesToDuplicate.indexOf(originalEntityID) === -1) {
|
||||||
entitiesToDuplicate.push(originalEntityID);
|
entitiesToDuplicate.push(originalEntityID);
|
||||||
}
|
}
|
||||||
that.addChildrenEntities(originalEntityID, entitiesToDuplicate);
|
that.addChildrenEntities(originalEntityID, entitiesToDuplicate, entityHostTypes[i].entityHostType);
|
||||||
});
|
}
|
||||||
|
|
||||||
// duplicate entities from above and store their original to new entity mappings and children needing re-parenting
|
// duplicate entities from above and store their original to new entity mappings and children needing re-parenting
|
||||||
for (var i = 0; i < entitiesToDuplicate.length; i++) {
|
for (var i = 0; i < entitiesToDuplicate.length; i++) {
|
||||||
|
@ -319,7 +333,7 @@ SelectionManager = (function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create the entities in entityProperties, maintaining parent-child relationships.
|
// Create the entities in entityProperties, maintaining parent-child relationships.
|
||||||
// @param entityPropertites {array} - Array of entity property objects
|
// @param entityProperties {array} - Array of entity property objects
|
||||||
that.createEntities = function(entityProperties) {
|
that.createEntities = function(entityProperties) {
|
||||||
var entitiesToCreate = [];
|
var entitiesToCreate = [];
|
||||||
var createdEntityIDs = [];
|
var createdEntityIDs = [];
|
||||||
|
@ -362,15 +376,27 @@ SelectionManager = (function() {
|
||||||
|
|
||||||
that.copySelectedEntities = function() {
|
that.copySelectedEntities = function() {
|
||||||
var entityProperties = Entities.getMultipleEntityProperties(that.selections);
|
var entityProperties = Entities.getMultipleEntityProperties(that.selections);
|
||||||
|
var entityHostTypes = Entities.getMultipleEntityProperties(that.selections, 'entityHostType');
|
||||||
var entities = {};
|
var entities = {};
|
||||||
entityProperties.forEach(function(props) {
|
entityProperties.forEach(function(props) {
|
||||||
entities[props.id] = props;
|
entities[props.id] = props;
|
||||||
});
|
});
|
||||||
|
|
||||||
function appendChildren(entityID, entities) {
|
function appendChildren(entityID, entities, entityHostType) {
|
||||||
|
var wantDebug = false;
|
||||||
var childrenIDs = Entities.getChildrenIDs(entityID);
|
var childrenIDs = Entities.getChildrenIDs(entityID);
|
||||||
|
var entityHostTypes = Entities.getMultipleEntityProperties(childrenIDs, 'entityHostType');
|
||||||
for (var i = 0; i < childrenIDs.length; ++i) {
|
for (var i = 0; i < childrenIDs.length; ++i) {
|
||||||
var id = childrenIDs[i];
|
var id = childrenIDs[i];
|
||||||
|
|
||||||
|
if (entityHostTypes[i].entityHostType !== entityHostType) {
|
||||||
|
if (wantDebug) {
|
||||||
|
console.warn("Skipping deletion of entity " + id + " with conflicting entityHostType: " +
|
||||||
|
entityHostTypes[i].entityHostType);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!(id in entities)) {
|
if (!(id in entities)) {
|
||||||
entities[id] = Entities.getEntityProperties(id);
|
entities[id] = Entities.getEntityProperties(id);
|
||||||
appendChildren(id, entities);
|
appendChildren(id, entities);
|
||||||
|
@ -380,7 +406,7 @@ SelectionManager = (function() {
|
||||||
|
|
||||||
var len = entityProperties.length;
|
var len = entityProperties.length;
|
||||||
for (var i = 0; i < len; ++i) {
|
for (var i = 0; i < len; ++i) {
|
||||||
appendChildren(entityProperties[i].id, entities);
|
appendChildren(entityProperties[i].id, entities, entityHostTypes[i].entityHostType);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var id in entities) {
|
for (var id in entities) {
|
||||||
|
|
Loading…
Reference in a new issue