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

48 lines
878 B
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';
2019-04-08 13:32:40 -05:00
import {shapeFromJSON, ShapeView} from '@avocado/physics';
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);
}
}
}
};
}
}