新增Debug辅助Insist

This commit is contained in:
yhh
2021-01-18 19:54:41 +08:00
parent eca9ba7b82
commit 3e182db019
13 changed files with 163 additions and 67 deletions

46
source/src/Debug/Debug.ts Normal file
View File

@@ -0,0 +1,46 @@
module es {
export enum LogType {
error,
warn,
log,
info,
trace
}
export class Debug {
public static warnIf(condition: boolean, format: string, ...args: any[]) {
if (condition)
this.log(LogType.warn, format, args);
}
public static warn(format: string, ...args: any[]) {
this.log(LogType.warn, format, args);
}
public static error(format: string, ...args: any[]) {
this.log(LogType.error, format, args);
}
public static log(type: LogType, format: string, ...args: any[]) {
switch(type) {
case LogType.error:
console.error(`${type}: ${StringUtils.format(format, args)}`);
break;
case LogType.warn:
console.warn(`${type}: ${StringUtils.format(format, args)}`);
break;
case LogType.log:
console.log(`${type}: ${StringUtils.format(format, args)}`);
break;
case LogType.info:
console.info(`${type}: ${StringUtils.format(format, args)}`);
break;
case LogType.trace:
console.trace(`${type}: ${StringUtils.format(format, args)}`);
break;
default:
throw new Error('argument out of range');
}
}
}
}

View File

@@ -3,7 +3,7 @@ module es {
* 我们在这里存储了各种系统的默认颜色如对撞机调试渲染、Debug.drawText等。
* 命名方式尽可能采用CLASS-THING以明确它的使用位置
*/
export class Debug {
export class DebugDefault {
public static debugText: number = 0xffffff;
public static colliderBounds: number = 0xffffff * 0.3;