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