diff --git a/src/core/region.ts b/src/core/region.ts index ea9f907..5ecd0e0 100644 --- a/src/core/region.ts +++ b/src/core/region.ts @@ -1,3 +1,4 @@ +import {computed, ReadonlySignal, SignalOptions} from "@preact/signals-core"; import {Entity} from "@/utils/entity"; import {Part} from "./part"; import {RNG} from "@/utils/rng"; @@ -15,6 +16,22 @@ export type RegionAxis = { align?: 'start' | 'end' | 'center'; } +export class RegionEntity extends Entity { + public readonly partsMap: ReadonlySignal>>; + + public constructor(id: string, t?: Region, options?: SignalOptions) { + super(id, t, options); + this.partsMap = computed(() => { + const result: Record> = {}; + for (const child of this.value.children) { + const key = child.value.position.join(','); + result[key] = child; + } + return result; + }); + } +} + export function applyAlign(region: Entity) { region.produce(applyAlignCore); }