From 394b8d2faff51993d10cfd403bcc60a7a05b4394 Mon Sep 17 00:00:00 2001 From: richarjiang Date: Wed, 13 May 2026 08:29:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=BE=93=E5=85=A5?= =?UTF-8?q?=E6=A1=86=E7=BC=96=E8=BE=91=E7=B4=A2=E5=BC=95=E7=AE=A1=E7=90=86?= =?UTF-8?q?=EF=BC=8C=E4=BC=98=E5=8C=96=E8=BE=93=E5=85=A5=E6=96=87=E6=9C=AC?= =?UTF-8?q?=E5=88=86=E5=8F=91=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AGENTS.md | 2 +- assets/prefabs/PageLevel.ts | 64 ++++++++++++++++++++++++------------- 2 files changed, 42 insertions(+), 24 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 915aa3f..6a1d85b 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -40,7 +40,7 @@ Git 历史采用 Conventional Commits,且摘要多为中文,例如 `feat: # Memory Context -# $CMEM mp-xieyingeng 2026-05-13 8:06am GMT+8 +# $CMEM mp-xieyingeng 2026-05-13 8:12am GMT+8 Legend: 🎯session 🔴bugfix 🟣feature 🔄refactor ✅change 🔵discovery ⚖️decision Format: ID TIME TYPE TITLE diff --git a/assets/prefabs/PageLevel.ts b/assets/prefabs/PageLevel.ts index 195f35f..21ee5dc 100644 --- a/assets/prefabs/PageLevel.ts +++ b/assets/prefabs/PageLevel.ts @@ -234,6 +234,9 @@ export class PageLevel extends BaseView { /** 最近一次自动提交的答案,避免填满后重复提交同一内容 */ private _lastAutoSubmittedAnswer: string = ''; + /** 当前正在编辑的输入格索引 */ + private _editingInputIndex: number = -1; + /** 倒计时剩余秒数 */ private _countdown: number = 60; @@ -659,28 +662,13 @@ export class PageLevel extends BaseView { // ========== EditBox 事件回调 ========== - /** - * 输入框开始编辑时,把当前所有格子的内容合并到当前输入框里 - */ private onInputEditingBegan(editBox: EditBox): void { if (this._isSyncingInputText) return; const inputIndex = this._inputNodes.findIndex(node => node === editBox.node); if (inputIndex < 0) return; - const answer = this.getAnswer(); - this._isSyncingInputText = true; - - try { - for (let i = 0; i < this._inputNodes.length; i++) { - const itemEditBox = this._inputNodes[i].getComponent(EditBox); - if (itemEditBox) { - itemEditBox.string = i === inputIndex ? answer : ''; - } - } - } finally { - this._isSyncingInputText = false; - } + this._editingInputIndex = inputIndex; } /** @@ -696,22 +684,48 @@ export class PageLevel extends BaseView { private onInputEditingEnded(editBox: EditBox): void { if (this._isSyncingInputText) return; - const inputIndex = this._inputNodes.findIndex(node => node === editBox.node); + const inputIndex = this._editingInputIndex >= 0 + ? this._editingInputIndex + : this._inputNodes.findIndex(node => node === editBox.node); if (inputIndex < 0) return; - this.distributeInputText(editBox.string); + this.applyInputTextToBlocks(editBox.string, inputIndex); + this._editingInputIndex = -1; this.tryAutoSubmitAnswer(); } - private distributeInputText(text: string): void { - const chars = Array.from(text); + private applyInputTextToBlocks(text: string, inputIndex: number): void { + const chars = Array.from(text.trim()); + if (chars.length <= 1) { + this.setInputBlockText(inputIndex, chars[0] ?? ''); + return; + } + + this.distributeInputText(text, inputIndex); + } + + private setInputBlockText(index: number, text: string): void { + const editBox = this._inputNodes[index]?.getComponent(EditBox); + if (!editBox) return; + + this._isSyncingInputText = true; + try { + editBox.string = Array.from(text.trim())[0] ?? ''; + } finally { + this._isSyncingInputText = false; + } + } + + private distributeInputText(text: string, startIndex: number = 0): void { + const chars = Array.from(text.trim()); + const safeStartIndex = Math.max(0, Math.min(startIndex, this._inputNodes.length - 1)); this._isSyncingInputText = true; try { - for (let i = 0; i < this._inputNodes.length; i++) { + for (let i = safeStartIndex; i < this._inputNodes.length; i++) { const editBox = this._inputNodes[i].getComponent(EditBox); if (editBox) { - editBox.string = chars[i] ?? ''; + editBox.string = chars[i - safeStartIndex] ?? ''; } } } finally { @@ -752,6 +766,10 @@ export class PageLevel extends BaseView { this.onSubmitAnswer(); } + private normalizeAnswerForCompare(answer: string): string { + return answer.trim().toLocaleLowerCase(); + } + // ========== IconSetting 按钮相关 ========== /** @@ -1741,7 +1759,7 @@ export class PageLevel extends BaseView { const userAnswer = this.getAnswer(); console.log(`[PageLevel] 提交答案: ${userAnswer}, 正确答案: ${this._currentConfig.answer}`); - if (userAnswer === this._currentConfig.answer) { + if (this.normalizeAnswerForCompare(userAnswer) === this.normalizeAnswerForCompare(this._currentConfig.answer)) { if (this._isShareMode) { this._recordCurrentShareSubmission(userAnswer); }