diff --git a/src/game/make.ts b/src/game/make.ts index 526b3078..faa69d10 100644 --- a/src/game/make.ts +++ b/src/game/make.ts @@ -74,7 +74,8 @@ export function make(comps: CompList = []): GameObj { _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) { @@ -301,15 +302,15 @@ export function make(comps: CompList = []): GameObj { comp[k]?.(); onCurCompCleanup = null; } - : comp[ k]; - gc.push(this.on(k, func).cancel); + : comp[k]; + gc.push(this.on(k, func).cancel); } else { if (this[k] === undefined) { // assign comp fields to game obj Object.defineProperty(this, k, { - get: () => comp[ k], - set: (val) => comp[ k] = val, + get: () => comp[k], + set: (val) => comp[k] = val, configurable: true, enumerable: true, }); @@ -321,9 +322,9 @@ export function make(comps: CompList = []): GameObj { )?.id; throw new Error( `Duplicate component property: "${k}" while adding component "${comp.id}"` - + (originalCompId - ? ` (originally added by "${originalCompId}")` - : ""), + + (originalCompId + ? ` (originally added by "${originalCompId}")` + : ""), ); } }