49 lines
872 B
JavaScript
49 lines
872 B
JavaScript
|
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);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
};
|
||
|
}
|
||
|
|
||
|
}
|