refactor: add region entity
This commit is contained in:
parent
2581a8e0e6
commit
b1a6619ae3
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue