fix: usage compliance
This commit is contained in:
parent
771afaa053
commit
01407b5ede
|
|
@ -31,10 +31,11 @@ export interface BindRegionOptions<TPart extends Part> {
|
||||||
factory: (part: TPart, position: Phaser.Math.Vector2) => Phaser.GameObjects.GameObject;
|
factory: (part: TPart, position: Phaser.Math.Vector2) => Phaser.GameObjects.GameObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function bindRegion<TPart extends Part>(
|
export function bindRegion<TState, TMeta>(
|
||||||
|
state: MutableSignal<TState>,
|
||||||
|
partsGetter: (state: TState) => Part<TMeta>[],
|
||||||
region: Region,
|
region: Region,
|
||||||
parts: Record<string, TPart>,
|
options: BindRegionOptions<Part<TMeta>>,
|
||||||
options: BindRegionOptions<TPart>,
|
|
||||||
container: Phaser.GameObjects.Container,
|
container: Phaser.GameObjects.Container,
|
||||||
): { cleanup: () => void; objects: Map<string, Phaser.GameObjects.GameObject> } {
|
): { cleanup: () => void; objects: Map<string, Phaser.GameObjects.GameObject> } {
|
||||||
const objects = new Map<string, Phaser.GameObjects.GameObject>();
|
const objects = new Map<string, Phaser.GameObjects.GameObject>();
|
||||||
|
|
@ -43,6 +44,7 @@ export function bindRegion<TPart extends Part>(
|
||||||
const offset = options.offset ?? { x: 0, y: 0 };
|
const offset = options.offset ?? { x: 0, y: 0 };
|
||||||
|
|
||||||
function syncParts() {
|
function syncParts() {
|
||||||
|
const parts = partsGetter(state.value);
|
||||||
const currentIds = new Set(region.childIds);
|
const currentIds = new Set(region.childIds);
|
||||||
for (const [id, obj] of objects) {
|
for (const [id, obj] of objects) {
|
||||||
if (!currentIds.has(id)) {
|
if (!currentIds.has(id)) {
|
||||||
|
|
@ -52,7 +54,7 @@ export function bindRegion<TPart extends Part>(
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const childId of region.childIds) {
|
for (const childId of region.childIds) {
|
||||||
const part = parts[childId];
|
const part = parts.find(p => p.id === childId);
|
||||||
if (!part) continue;
|
if (!part) continue;
|
||||||
|
|
||||||
const pos = new Phaser.Math.Vector2(
|
const pos = new Phaser.Math.Vector2(
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ export class InputMapper<TState extends Record<string, unknown>> {
|
||||||
|
|
||||||
const cmd = onCellClick(col, row);
|
const cmd = onCellClick(col, row);
|
||||||
if (cmd) {
|
if (cmd) {
|
||||||
this.commands.run(cmd);
|
this.commands._tryCommit(cmd);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -83,7 +83,6 @@ export class PromptHandler<TState extends Record<string, unknown>> {
|
||||||
private onPrompt: (prompt: PromptEvent) => void;
|
private onPrompt: (prompt: PromptEvent) => void;
|
||||||
private onSubmit: (input: string) => string | null;
|
private onSubmit: (input: string) => string | null;
|
||||||
private onCancel: (reason?: string) => void;
|
private onCancel: (reason?: string) => void;
|
||||||
private listener: ((event: PromptEvent) => void) | null = null;
|
|
||||||
|
|
||||||
constructor(options: PromptHandlerOptions<TState>) {
|
constructor(options: PromptHandlerOptions<TState>) {
|
||||||
this.scene = options.scene;
|
this.scene = options.scene;
|
||||||
|
|
@ -94,13 +93,6 @@ export class PromptHandler<TState extends Record<string, unknown>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
start(): void {
|
start(): void {
|
||||||
const listener = (event: PromptEvent) => {
|
|
||||||
this.onPrompt(event);
|
|
||||||
};
|
|
||||||
|
|
||||||
this.listener = listener;
|
|
||||||
this.commands.on('prompt', listener);
|
|
||||||
|
|
||||||
this.commands.promptQueue.pop().then((promptEvent) => {
|
this.commands.promptQueue.pop().then((promptEvent) => {
|
||||||
this.onPrompt(promptEvent);
|
this.onPrompt(promptEvent);
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
|
|
@ -117,10 +109,7 @@ export class PromptHandler<TState extends Record<string, unknown>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
destroy(): void {
|
destroy(): void {
|
||||||
if (this.listener) {
|
// No cleanup needed - promptQueue handles its own lifecycle
|
||||||
this.commands.off('prompt', this.listener);
|
|
||||||
this.listener = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue