avocado-old/packages/physics/traits/shaped.trait.js

55 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-04-08 13:32:40 -05:00
import {compose} from '@avocado/core';
2019-04-14 20:21:52 -05:00
import {Trait} from '@avocado/entity';
import {shapeFromJSON} from '../shape-from-json';
import {ShapeView} from '../shape-view';
2019-04-08 13:32:40 -05:00
const decorate = compose(
);
export class Shaped extends decorate(Trait) {
static defaultParams() {
return {
shape: undefined,
};
}
initialize() {
this._shape = shapeFromJSON(this.params.get('shape').toJS());
this.shapeView = undefined;
}
destroy() {
this._shape.destroy();
2019-04-08 13:32:40 -05:00
if (this.shapeView) {
this.shapeView.destroy();
this.shapeView = undefined;
2019-04-08 13:32:40 -05:00
}
}
get shape() {
return this._shape;
}
listeners() {
return {
traitAdded: (type) => {
2019-04-23 03:22:04 -05:00
if (AVOCADO_CLIENT) {
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);
}
2019-04-08 13:32:40 -05:00
}
}
}
};
}
}