This commit is contained in:
yhh
2021-01-19 10:24:36 +08:00
13 changed files with 163 additions and 67 deletions

View File

@@ -81,10 +81,7 @@ module es {
* @param value
*/
public static set scene(value: Scene) {
if (!value) {
console.error("场景不能为空");
return;
}
Insist.isNotNull(value, "场景不能为空");
if (this._instance._scene == null) {
this._instance._scene = value;

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;

View File

@@ -129,9 +129,7 @@ module es {
public onAddedToEntity(){
this._collider = this.entity.getComponent<es.Collider>(es.Collider);
if (this._collider == null) {
console.warn("ArcadeRigidbody 没有 Collider。ArcadeRigidbody需要一个Collider!");
}
Debug.warnIf(this._collider == null, "ArcadeRigidbody 没有 Collider。ArcadeRigidbody需要一个Collider!");
}
public update(){

View File

@@ -9,8 +9,7 @@ module es {
public onAddedToEntity() {
this._collider = this.entity.getComponent<Collider>(Collider);
if (!this._collider)
console.warn("ProjectileMover没有Collider。ProjectilMover需要一个Collider!");
Debug.warnIf(this._collider == null, "ProjectileMover没有Collider。ProjectilMover需要一个Collider!");
}
/**

View File

@@ -145,12 +145,9 @@ module es {
* @param component
*/
public removeSceneComponent(component: SceneComponent) {
if (!new linq.List(this._sceneComponents).contains(component)) {
console.warn(`SceneComponent${component}不在SceneComponents列表中!`);
return;
}
new linq.List(this._sceneComponents).remove(component);
const sceneComponentList = new linq.List(this._sceneComponents);
Insist.isTrue(sceneComponentList.contains(component), `SceneComponent${component}不在SceneComponents列表中!`);
sceneComponentList.remove(component);
component.onRemovedFromScene();
}

View File

@@ -52,8 +52,7 @@ module es {
public remove(component: Component) {
let componentToRemove = new linq.List(this._componentsToRemove);
let componentToAdd = new linq.List(this._componentsToAdd);
if (componentToRemove.contains(component))
console.warn(`您正在尝试删除一个您已经删除的组件(${component})`);
Debug.warnIf(componentToRemove.contains(component), `您正在尝试删除一个您已经删除的组件(${component})`);
// 这可能不是一个活动的组件,所以我们必须注意它是否还没有被处理,它可能正在同一帧中被删除
if (componentToAdd.contains(component)) {

View File

@@ -56,10 +56,7 @@ module es {
* @param entity
*/
public remove(entity: Entity) {
if (!this._entitiesToRemove.contains(entity)) {
console.warn(`您正在尝试删除已经删除的实体(${entity.name})`);
return;
}
Debug.warnIf(this._entitiesToRemove.contains(entity), `您正在尝试删除已经删除的实体(${entity.name})`);
// 防止在同一帧中添加或删除实体
if (this._entitiesToAdded.contains(entity)) {

View File

@@ -75,9 +75,8 @@ module es {
for (let y = p1.y; y <= p2.y; y++) {
// 单元格应该始终存在,因为这个碰撞器应该在所有查询的单元格中
let cell = this.cellAtPosition(x, y);
if (!cell)
console.log(`从不存在碰撞器的单元格中移除碰撞器: [${collider}]`);
else
Insist.isNotNull(cell, `从不存在碰撞器的单元格中移除碰撞器: [${collider}]`);
if (cell != null)
new linq.List(cell).remove(collider);
}
}

View File

@@ -37,8 +37,7 @@ module es {
this._messageTable.set(eventType, list);
}
if (list.findIndex(funcPack => funcPack.func == handler) != -1)
console.warn("您试图添加相同的观察者两次");
Insist.isFalse(list.findIndex(funcPack => funcPack.func == handler) != -1, "您试图添加相同的观察者两次");
list.push(new FuncPack(handler, context));
}