Skip to content

Commit

Permalink
fix: parent set to null (#576)
Browse files Browse the repository at this point in the history
  • Loading branch information
dragoncoder047 authored Jan 3, 2025
1 parent 1ed7ea5 commit 3a5d44d
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/game/make.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ export function make<T>(comps: CompList<T> = []): GameObj<T> {
_parent.children.splice(index, 1);
}
_parent = p;
p.children.push(this as GameObj);
if (p)
p.children.push(this as GameObj);
},

setParent(p: GameObj, opt: SetParentOpt) {
Expand Down Expand Up @@ -301,15 +302,15 @@ export function make<T>(comps: CompList<T> = []): GameObj<T> {
comp[k]?.();
onCurCompCleanup = null;
}
: comp[<keyof typeof comp> k];
gc.push(this.on(k, <any> func).cancel);
: comp[<keyof typeof comp>k];
gc.push(this.on(k, <any>func).cancel);
}
else {
if (this[k] === undefined) {
// assign comp fields to game obj
Object.defineProperty(this, k, {
get: () => comp[<keyof typeof comp> k],
set: (val) => comp[<keyof typeof comp> k] = val,
get: () => comp[<keyof typeof comp>k],
set: (val) => comp[<keyof typeof comp>k] = val,
configurable: true,
enumerable: true,
});
Expand All @@ -321,9 +322,9 @@ export function make<T>(comps: CompList<T> = []): GameObj<T> {
)?.id;
throw new Error(
`Duplicate component property: "${k}" while adding component "${comp.id}"`
+ (originalCompId
? ` (originally added by "${originalCompId}")`
: ""),
+ (originalCompId
? ` (originally added by "${originalCompId}")`
: ""),
);
}
}
Expand Down

0 comments on commit 3a5d44d

Please sign in to comment.