refactor: add region entity

This commit is contained in:
hypercross 2026-04-02 16:32:26 +08:00
parent 2581a8e0e6
commit b1a6619ae3
1 changed files with 17 additions and 0 deletions

View File

@ -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<Region> {
public readonly partsMap: ReadonlySignal<Record<string, Entity<Part>>>;
public constructor(id: string, t?: Region, options?: SignalOptions<Region>) {
super(id, t, options);
this.partsMap = computed(() => {
const result: Record<string, Entity<Part>> = {};
for (const child of this.value.children) {
const key = child.value.position.join(',');
result[key] = child;
}
return result;
});
}
}
export function applyAlign(region: Entity<Region>) {
region.produce(applyAlignCore);
}