Skip to content

Commit

Permalink
Merge pull request #874 from AleziaKurdis/CreateApp_Issue869
Browse files Browse the repository at this point in the history
Fix new Zones appearing as parent of a ghost child
  • Loading branch information
two-one-five committed Nov 28, 2020
2 parents 0157d5f + 343ded8 commit 60e59ab
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
19 changes: 17 additions & 2 deletions scripts/system/create/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,10 @@ var gridTool = new GridTool({
});
gridTool.setVisible(false);

var entityShapeVisualizerSessionName = "SHAPE_VISUALIZER_" + Uuid.generate();

var EntityShapeVisualizer = Script.require('./modules/entityShapeVisualizer.js');
var entityShapeVisualizer = new EntityShapeVisualizer(["Zone"]);
var entityShapeVisualizer = new EntityShapeVisualizer(["Zone"], entityShapeVisualizerSessionName);

var entityListTool = new EntityListTool(shouldUseEditTabletApp);

Expand Down Expand Up @@ -2908,7 +2910,7 @@ function zoneSortOrder(a, b) {
function getParentState(id) {
var state = "NONE";
var properties = Entities.getEntityProperties(id, ["parentID"]);
var children = Entities.getChildrenIDs(id);
var children = getDomainOnlyChildrenIDs(id);
if (properties.parentID !== Uuid.NULL) {
if (children.length > 0) {
state = "PARENT_CHILDREN";
Expand All @@ -2923,4 +2925,17 @@ function getParentState(id) {
return state;
}

function getDomainOnlyChildrenIDs(id) {
var allChildren = Entities.getChildrenIDs(id);
var realChildren = [];
var properties;
for (var i = 0; i < allChildren.length; i++) {
properties = Entities.getEntityProperties(allChildren[i], ["name"]);
if (properties.name !== undefined && properties.name !== entityShapeVisualizerSessionName) {
realChildren.push(allChildren[i]);
}
}
return realChildren;
}

}()); // END LOCAL_SCOPE
10 changes: 5 additions & 5 deletions scripts/system/create/entitySelectionTool/entitySelectionTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -724,12 +724,12 @@ SelectionManager = (function() {
that.addChildrenToSelection = function() {
if (that.hasSelection()) {
for (var i = 0; i < that.selections.length; i++) {
var childrenIDs = Entities.getChildrenIDs(that.selections[i]);
var collectNewChildren;
var childrenIDs = getDomainOnlyChildrenIDs(that.selections[i]);
var collectNewChildren;
var j;
var k = 0;
do {
collectNewChildren = Entities.getChildrenIDs(childrenIDs[k]);
collectNewChildren = getDomainOnlyChildrenIDs(childrenIDs[k]);
if (collectNewChildren.length > 0) {
for (j = 0; j < collectNewChildren.length; j++) {
childrenIDs.push(collectNewChildren[j]);
Expand All @@ -746,7 +746,7 @@ SelectionManager = (function() {
that._update(true, this);
} else {
audioFeedback.rejection();
Window.notifyEditError("You have nothing selected.");
Window.notifyEditError("You have nothing selected.");
}
};

Expand Down Expand Up @@ -832,7 +832,7 @@ SelectionDisplay = (function() {

const BOUNDING_EDGE_OFFSET = 0.5;

const DUPLICATOR_OFFSET = { x: 0.6, y: 0, z: 0.6 };
const DUPLICATOR_OFFSET = { x: 0.6, y: 0, z: 0.6 };

const CTRL_KEY_CODE = 16777249;

Expand Down
13 changes: 8 additions & 5 deletions scripts/system/create/modules/entityShapeVisualizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,14 @@ function deepCopy(v) {
return JSON.parse(JSON.stringify(v));
}

function EntityShape(entityID) {
function EntityShape(entityID, entityShapeVisualizerSessionName) {
this.entityID = entityID;
this.entityShapeVisualizerSessionName = entityShapeVisualizerSessionName;

var propertiesForType = getEntityShapePropertiesForType(Entities.getEntityProperties(entityID, REQUESTED_ENTITY_SHAPE_PROPERTIES));

this.previousPropertiesForType = propertiesForType;

this.initialize(propertiesForType);
}

Expand All @@ -130,6 +132,7 @@ EntityShape.prototype = {
// Create new instance of JS object:
var overlayProperties = deepCopy(properties);

overlayProperties.name = this.entityShapeVisualizerSessionName;
overlayProperties.localPosition = Vec3.ZERO;
overlayProperties.localRotation = Quat.IDENTITY;
overlayProperties.canCastShadows = false;
Expand Down Expand Up @@ -172,11 +175,11 @@ EntityShape.prototype = {
}
};

function EntityShapeVisualizer(visualizedTypes) {
function EntityShapeVisualizer(visualizedTypes, entityShapeVisualizerSessionName) {
this.acceptedEntities = [];
this.ignoredEntities = [];
this.entityShapes = {};

this.entityShapeVisualizerSessionName = entityShapeVisualizerSessionName;
this.visualizedTypes = visualizedTypes;
}

Expand All @@ -185,7 +188,7 @@ EntityShapeVisualizer.prototype = {
if (this.entityShapes[entityID]) {
return;
}
this.entityShapes[entityID] = new EntityShape(entityID);
this.entityShapes[entityID] = new EntityShape(entityID, this.entityShapeVisualizerSessionName);

},
updateEntity: function(entityID) {
Expand Down

0 comments on commit 60e59ab

Please sign in to comment.