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

49 lines
872 B
JavaScript
Raw Normal View History

2019-04-08 13:32:40 -05:00
import {compose} from '@avocado/core';
import {shapeFromJSON, ShapeView} from '@avocado/physics';
import {Trait} from '../trait';
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() {
if (this.shapeView) {
this.shapeView.destroy();
}
}
get shape() {
return this._shape;
}
listeners() {
return {
traitAdded: (type) => {
if (this.entity.container) {
if (!this.shapeView) {
this.shapeView = new ShapeView(this.entity.shape);
this.shapeView.zIndex = 100;
this.entity.container.addChild(this.shapeView);
}
}
}
};
}
}