import {compose} from '@avocado/core'; import {Trait} from '@avocado/entity'; 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); } } } }; } }