diff --git a/AGENTS.md b/AGENTS.md index 9cc3c83..ca210d0 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -14,3 +14,12 @@ ## 提交与 Pull Request 规范 Git 历史采用 Conventional Commits,且摘要多为中文,例如 `feat: 支持分享关卡通关上报`、`fix: 修复关卡排序`、`docs: 添加设计文档`。请继续使用 `feat:`、`fix:`、`perf:`、`docs:` 前缀,首行聚焦单一变更。PR 需说明改动范围、影响页面或模块、验证方式;涉及 UI 请附截图或录屏,涉及微信环境差异请写明复现条件与平台。 + + + +# Memory Context + +# [mp-xieyingeng] recent context, 2026-04-24 8:45am GMT+8 + +No previous sessions found. + \ No newline at end of file diff --git a/assets/prefabs/PageLevel.ts b/assets/prefabs/PageLevel.ts index b5d36a0..9e4c805 100644 --- a/assets/prefabs/PageLevel.ts +++ b/assets/prefabs/PageLevel.ts @@ -21,6 +21,9 @@ export class PageLevel extends BaseView { /** 静态常量:零位置 */ private static readonly ZERO_POS = new Vec3(0, 0, 0); + /** 默认体力上限,服务端未返回 max 时使用 */ + private static readonly DEFAULT_STAMINA_MAX = 50; + // ========== 节点引用 ========== @property(Node) inputLayout: Node | null = null; @@ -237,7 +240,7 @@ export class PageLevel extends BaseView { } // 提示用户消耗体力 - ToastManager.show(`消耗1点体力,剩余 ${enterData.stamina.current}/${enterData.stamina.max}`); + ToastManager.show(`消耗1点体力,剩余 ${enterData.stamina.current}/${this._getStaminaMax(enterData.stamina)}`); // 用 enter 接口返回的数据更新关卡配置(填充答案和线索) LevelDataManager.instance.updateLevelDetails( @@ -783,15 +786,27 @@ export class PageLevel extends BaseView { /** 上次显示的体力值,用于变更检测 */ private _lastDisplayedStamina: number = -1; + /** 上次显示的体力上限,用于变更检测 */ + private _lastDisplayedStaminaMax: number = -1; + + /** + * 获取体力上限,服务端未返回时使用默认值兜底 + */ + private _getStaminaMax(stamina: StaminaInfo): number { + return typeof stamina.max === 'number' ? stamina.max : PageLevel.DEFAULT_STAMINA_MAX; + } + /** * 更新体力值显示(仅值变化时更新 UI) */ private updateStaminaLabel(): void { if (this.liveLabel) { const stamina = StaminaManager.instance.getStamina(); - if (stamina.current !== this._lastDisplayedStamina) { - this.liveLabel.string = `x ${stamina.current}`; + const maxStamina = this._getStaminaMax(stamina); + if (stamina.current !== this._lastDisplayedStamina || maxStamina !== this._lastDisplayedStaminaMax) { + this.liveLabel.string = `${stamina.current}/${maxStamina}`; this._lastDisplayedStamina = stamina.current; + this._lastDisplayedStaminaMax = maxStamina; } } } @@ -803,7 +818,8 @@ export class PageLevel extends BaseView { this._stopStaminaRecoverTimer(); const stamina = StaminaManager.instance.getStamina(); - if (!stamina.nextRecoverAt || stamina.current >= stamina.max) { + const maxStamina = this._getStaminaMax(stamina); + if (!stamina.nextRecoverAt || stamina.current >= maxStamina) { return; } @@ -815,11 +831,13 @@ export class PageLevel extends BaseView { // 恢复一点体力 const currentStamina = StaminaManager.instance.getStamina(); - const newCurrent = Math.min(currentStamina.current + 1, currentStamina.max); + const currentMaxStamina = this._getStaminaMax(currentStamina); + const newCurrent = Math.min(currentStamina.current + 1, currentMaxStamina); const newStamina: StaminaInfo = { ...currentStamina, + max: currentMaxStamina, current: newCurrent, - nextRecoverAt: newCurrent < currentStamina.max + nextRecoverAt: newCurrent < currentMaxStamina ? new Date(Date.now() + 10 * 60 * 1000).toISOString() : null, };