Skip to content

Commit

Permalink
fixed it for real
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaoticLeah committed Dec 26, 2023
1 parent 6f86807 commit 07d98fb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
8 changes: 6 additions & 2 deletions scripts/Objects/Object.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ export class GameObject {
}
}

addChild(child) {
this.getProperties().childrenObjectIds.push(child);
addChild(childId) {
this.getProperties().childrenObjectIds.push(childId);
}

hasChild(childId) {
return this.getProperties().childrenObjectIds.includes(childId)
}

addChildAtIndex(child, index) {
Expand Down
5 changes: 4 additions & 1 deletion scripts/Objects/ObjectManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ export function addObject(object, parentObjectId) {
parentObjectId = "root";
}
object.getProperties().parentObjectId = parentObjectId.toString();
if (parentObjectId != "none")
const parentIsDefined = getObject(parentObjectId) != undefined
const alreadyHasChild = parentIsDefined && getObject(parentObjectId).hasChild(object.getProperties().id)
if (parentObjectId != "none" && parentIsDefined && !alreadyHasChild)
getObject(parentObjectId).addChild(object.getProperties().id);

objects.set(object.getProperties().id, object);
return true;
} catch (err) {
Expand Down
5 changes: 1 addition & 4 deletions scripts/Objects/ObjectsTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,10 @@ function walkEveryBranch(id, depth, callback) {
*/
function getOrderedObjectArray() {
let nodes = []

// Walk every branch and print the childrenObjectIds
walkEveryBranch("root", 0, (node) => {
node.depth --
if(node.id != "root" && ![...nodes, {id: -1}].some(function(lnode) {
return lnode.id == node.id
}))
if(node.id != "root")
nodes.push(node)
});
return nodes
Expand Down

0 comments on commit 07d98fb

Please sign in to comment.