From f160f71d7aaaa6be4450334ae81651f6f7f33459 Mon Sep 17 00:00:00 2001 From: cha0s Date: Sun, 21 Apr 2019 02:54:07 -0500 Subject: [PATCH] feat: debuggable --- packages/entity/traits/debuggable.trait.js | 19 +++++++++++++++++++ packages/physics/shape-view.js | 6 +++--- packages/physics/traits/physical.trait.js | 3 ++- packages/physics/traits/shaped.trait.js | 3 ++- 4 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 packages/entity/traits/debuggable.trait.js diff --git a/packages/entity/traits/debuggable.trait.js b/packages/entity/traits/debuggable.trait.js new file mode 100644 index 0000000..8714a3f --- /dev/null +++ b/packages/entity/traits/debuggable.trait.js @@ -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, + }; + } + +} diff --git a/packages/physics/shape-view.js b/packages/physics/shape-view.js index 4b4d7ec..6a3f34c 100644 --- a/packages/physics/shape-view.js +++ b/packages/physics/shape-view.js @@ -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); diff --git a/packages/physics/traits/physical.trait.js b/packages/physics/traits/physical.trait.js index a0b0252..668def1 100644 --- a/packages/physics/traits/physical.trait.js +++ b/packages/physics/traits/physical.trait.js @@ -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); } diff --git a/packages/physics/traits/shaped.trait.js b/packages/physics/traits/shaped.trait.js index da2adf9..600e0f1 100644 --- a/packages/physics/traits/shaped.trait.js +++ b/packages/physics/traits/shaped.trait.js @@ -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); }