diff --git a/src/game/layers.tsx b/src/game/layers.tsx index 0698c0a..2a7bc45 100644 --- a/src/game/layers.tsx +++ b/src/game/layers.tsx @@ -89,15 +89,19 @@ export type GenericLayer = Replace< } >; -export function createLayer(optionsFunc: () => T): Layer { +export function createLayer( + optionsFunc: (() => T) & ThisType +): Layer { return createLazyProxy(() => { - const layer = optionsFunc() as T & Partial; + const layer = {} as T & Partial; const emitter = (layer.emitter = createNanoEvents()); layer.on = emitter.on.bind(emitter); layer.emit = emitter.emit.bind(emitter); layer.minimized = persistent(false); + Object.assign(layer, optionsFunc.call(layer)); + processComputable(layer as T, "color"); processComputable(layer as T, "display"); processComputable(layer as T, "name");