fix: fix bugs
This commit is contained in:
parent
656c33cb59
commit
7501b5f592
|
|
@ -63,9 +63,10 @@ export function bindRegion<TState, TMeta>(
|
|||
if (!part) continue;
|
||||
|
||||
// 支持动态维度:取前两个维度作为 x, y
|
||||
// position[0] = row (y轴), position[1] = col (x轴)
|
||||
const pos = new Phaser.Math.Vector2(
|
||||
(part.position[0] ?? 0) * options.cellSize.x + offset.x,
|
||||
(part.position[1] ?? 0) * options.cellSize.y + offset.y,
|
||||
(part.position[1] ?? 0) * options.cellSize.x + offset.x,
|
||||
(part.position[0] ?? 0) * options.cellSize.y + offset.y,
|
||||
);
|
||||
|
||||
let obj = objects.get(childId);
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ export class InputMapper<TState extends Record<string, unknown>> {
|
|||
private activePrompt: { current: PromptEvent | null };
|
||||
private onSubmitPrompt: (input: string) => string | null;
|
||||
private pointerDownCallback: ((pointer: Phaser.Input.Pointer) => void) | null = null;
|
||||
private isWaitingForPrompt = false;
|
||||
|
||||
constructor(options: InputMapperOptions<TState>) {
|
||||
this.scene = options.scene;
|
||||
|
|
@ -41,12 +42,9 @@ export class InputMapper<TState extends Record<string, unknown>> {
|
|||
|
||||
const cmd = onCellClick(col, row);
|
||||
if (cmd) {
|
||||
// 如果有活跃的 prompt,通过 submit 提交
|
||||
if (this.activePrompt.current) {
|
||||
// 总是尝试提交到 prompt
|
||||
// 如果没有活跃 prompt,onSubmitPrompt 会返回错误,我们忽略它
|
||||
this.onSubmitPrompt(cmd);
|
||||
} else {
|
||||
this.commands.run(cmd);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -94,6 +92,7 @@ export class PromptHandler<TState extends Record<string, unknown>> {
|
|||
private onCancel: (reason?: string) => void;
|
||||
private activePrompt: PromptEvent | null = null;
|
||||
private isListening = false;
|
||||
private pendingInput: string | null = null;
|
||||
|
||||
constructor(options: PromptHandlerOptions<TState>) {
|
||||
this.scene = options.scene;
|
||||
|
|
@ -113,6 +112,19 @@ export class PromptHandler<TState extends Record<string, unknown>> {
|
|||
this.commands.promptQueue.pop()
|
||||
.then((promptEvent) => {
|
||||
this.activePrompt = promptEvent;
|
||||
|
||||
// 如果有等待的输入,自动提交
|
||||
if (this.pendingInput) {
|
||||
const input = this.pendingInput;
|
||||
this.pendingInput = null;
|
||||
const error = this.activePrompt.tryCommit(input);
|
||||
if (error === null) {
|
||||
this.activePrompt = null;
|
||||
this.listenForPrompt();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
this.onPrompt(promptEvent);
|
||||
})
|
||||
.catch((reason) => {
|
||||
|
|
@ -123,7 +135,9 @@ export class PromptHandler<TState extends Record<string, unknown>> {
|
|||
|
||||
submit(input: string): string | null {
|
||||
if (!this.activePrompt) {
|
||||
return 'No active prompt';
|
||||
// 没有活跃 prompt,保存为待处理输入
|
||||
this.pendingInput = input;
|
||||
return null; // 返回 null 表示已接受,会等待
|
||||
}
|
||||
|
||||
const error = this.activePrompt.tryCommit(input);
|
||||
|
|
|
|||
|
|
@ -83,24 +83,14 @@ export class GameScene extends ReactiveScene<TicTacToeState> {
|
|||
}
|
||||
|
||||
private setupInput(): void {
|
||||
const scene = this;
|
||||
const activePromptRef = {
|
||||
get current() { return scene.activePrompt; }
|
||||
};
|
||||
|
||||
this.inputMapper = createInputMapper(
|
||||
this,
|
||||
this.commands,
|
||||
activePromptRef,
|
||||
{ current: null }, // 不再需要,保留以兼容接口
|
||||
(cmd: string) => {
|
||||
const activePrompt = this.activePrompt;
|
||||
if (!activePrompt) return 'No active prompt';
|
||||
const error = activePrompt.tryCommit(cmd);
|
||||
if (error === null) {
|
||||
this.activePrompt = null;
|
||||
this.promptHandler.start();
|
||||
}
|
||||
return error;
|
||||
// 使用 PromptHandler.submit() 而不是直接 tryCommit
|
||||
// 这样会自动处理没有活跃 prompt 时的排队逻辑
|
||||
return this.promptHandler.submit(cmd);
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue