feat: debuggable

This commit is contained in:
cha0s 2019-04-21 02:54:07 -05:00
parent b59901012a
commit f160f71d7a
4 changed files with 26 additions and 5 deletions

View File

@ -0,0 +1,19 @@
import {compose} from '@avocado/core';
import {StateProperty, Trait} from '../trait';
const decorate = compose(
StateProperty('isDebugging', {
track: true,
}),
);
export class Debuggable extends decorate(Trait) {
static defaultState() {
return {
isDebugging: false,
};
}
}

View File

@ -43,7 +43,7 @@ export class ShapeView extends Renderable {
primitives.drawCircle(
this.shape.position,
this.shape.radius,
Primitives.lineStyle(new Color(255, 0, 255), 0.5),
Primitives.lineStyle(new Color(255, 0, 255), 1),
);
this.container.removeAllChildren();
this.container.addChild(primitives);
@ -61,7 +61,7 @@ export class ShapeView extends Renderable {
primitives.drawLine(
lastVertice,
vertice,
Primitives.lineStyle(new Color(255, 0, 255), 0.5),
Primitives.lineStyle(new Color(255, 0, 255), 1),
);
}
lastVertice = vertice;
@ -69,7 +69,7 @@ export class ShapeView extends Renderable {
primitives.drawLine(
lastVertice,
firstVertice,
Primitives.lineStyle(new Color(255, 0, 255), 0.5),
Primitives.lineStyle(new Color(255, 0, 255), 1),
);
this.container.removeAllChildren();
this.container.addChild(primitives);

View File

@ -36,9 +36,10 @@ export class Physical extends decorate(Trait) {
body.setCollisionForEntity(this.entity);
world.addBody(body);
this._body = body;
if (this.entity.container) {
if (this.entity.is('visible') && this.entity.is('debuggable')) {
this.bodyView = new BodyView(body);
this.bodyView.position = Vector.scale(this.entity.position, -1);
this.bodyView.visible = this.entity.isDebugging;
this.bodyView.zIndex = 101;
this.entity.container.addChild(this.bodyView);
}

View File

@ -34,9 +34,10 @@ export class Shaped extends decorate(Trait) {
return {
traitAdded: (type) => {
if (this.entity.container) {
if (this.entity.is('visible') && this.entity.is('debuggable')) {
if (!this.shapeView) {
this.shapeView = new ShapeView(this.entity.shape);
this.shapeView.visible = this.entity.isDebugging;
this.shapeView.zIndex = 100;
this.entity.container.addChild(this.shapeView);
}