From cd47510cb03562dd9fb071be34bdbff1b1dc3773 Mon Sep 17 00:00:00 2001 From: dgflash Date: Sun, 26 Oct 2025 21:08:07 +0800 Subject: [PATCH] =?UTF-8?q?1.=20TimeUtili=E6=B7=BB=E5=8A=A0=E5=B0=86?= =?UTF-8?q?=E7=A7=92=E6=95=B0=E6=A0=BC=E5=BC=8F=E5=8C=96=E4=B8=BA=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E6=A0=BC=E5=BC=8F=202.=20CCEntity=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E7=BB=84=E4=BB=B6=E4=B8=BA=E7=A9=BA=E6=97=B6?= =?UTF-8?q?=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/core/utils/TimeUtils.ts | 28 ++++++++++++++++++++++++++++ assets/module/common/CCEntity.ts | 7 +++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/assets/core/utils/TimeUtils.ts b/assets/core/utils/TimeUtils.ts index dfd2161..dfa57e1 100644 --- a/assets/core/utils/TimeUtils.ts +++ b/assets/core/utils/TimeUtils.ts @@ -35,4 +35,32 @@ export class TimeUtil { }, ms) }); } + + /** 格式化字符串 */ + static format(countDown: number) { + let result: string = ""; + let c: number = countDown; + let date: number = Math.floor(c / 86400); + c = c - date * 86400; + let hours: number = Math.floor(c / 3600); + c = c - hours * 3600; + let minutes: number = Math.floor(c / 60); + c = c - minutes * 60; + let seconds: number = c; + + if (date == 0 && hours == 0 && minutes == 0 && seconds == 0) { + result = "00:00:00"; + } + else { + hours += date * 24; + result = `${this.coverString(hours)}:${this.coverString(minutes)}:${this.coverString(seconds)}`; + } + return result; + } + + /** 个位数的时间数据将字符串补位 */ + private static coverString(value: number) { + if (value < 10) return "0" + value; + return value.toString(); + } } \ No newline at end of file diff --git a/assets/module/common/CCEntity.ts b/assets/module/common/CCEntity.ts index 79135f2..e83e6bc 100644 --- a/assets/module/common/CCEntity.ts +++ b/assets/module/common/CCEntity.ts @@ -190,6 +190,7 @@ export abstract class CCEntity extends ecs.Entity { * @returns 业务逻辑组件实例 */ getBusiness>(cls: any): T { + if (this.businesss == null) return null!; return this.businesss.get(cls) as T; } @@ -198,8 +199,10 @@ export abstract class CCEntity extends ecs.Entity { * @param cls 业务逻辑组件类 */ removeBusiness(cls: any) { - let business = this.businesss.get(cls); - if (business) this.businesss.delete(cls); + if (this.businesss) { + let business = this.businesss.get(cls); + if (business) this.businesss.delete(cls); + } } //#endregion