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