fix: usage compliance

This commit is contained in:
hypercross 2026-04-03 16:18:05 +08:00
parent 771afaa053
commit 01407b5ede
2 changed files with 8 additions and 17 deletions

View File

@ -31,10 +31,11 @@ export interface BindRegionOptions<TPart extends Part> {
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,
parts: Record<string, TPart>,
options: BindRegionOptions<TPart>,
options: BindRegionOptions<Part<TMeta>>,
container: Phaser.GameObjects.Container,
): { cleanup: () => void; objects: 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 };
function syncParts() {
const parts = partsGetter(state.value);
const currentIds = new Set(region.childIds);
for (const [id, obj] of objects) {
if (!currentIds.has(id)) {
@ -52,7 +54,7 @@ export function bindRegion<TPart extends Part>(
}
for (const childId of region.childIds) {
const part = parts[childId];
const part = parts.find(p => p.id === childId);
if (!part) continue;
const pos = new Phaser.Math.Vector2(

View File

@ -35,7 +35,7 @@ export class InputMapper<TState extends Record<string, unknown>> {
const cmd = onCellClick(col, row);
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 onSubmit: (input: string) => string | null;
private onCancel: (reason?: string) => void;
private listener: ((event: PromptEvent) => void) | null = null;
constructor(options: PromptHandlerOptions<TState>) {
this.scene = options.scene;
@ -94,13 +93,6 @@ export class PromptHandler<TState extends Record<string, unknown>> {
}
start(): void {
const listener = (event: PromptEvent) => {
this.onPrompt(event);
};
this.listener = listener;
this.commands.on('prompt', listener);
this.commands.promptQueue.pop().then((promptEvent) => {
this.onPrompt(promptEvent);
}).catch(() => {
@ -117,10 +109,7 @@ export class PromptHandler<TState extends Record<string, unknown>> {
}
destroy(): void {
if (this.listener) {
this.commands.off('prompt', this.listener);
this.listener = null;
}
// No cleanup needed - promptQueue handles its own lifecycle
}
}