perf: 优化倒计时格式
This commit is contained in:
@@ -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,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user