69 lines
1.3 KiB
JavaScript
69 lines
1.3 KiB
JavaScript
import {compose} from '@avocado/core';
|
|
import {Trait} from '@avocado/entity';
|
|
|
|
import {shapeFromJSON} from '../shape-from-json';
|
|
import {ShapeView} from '../shape-view';
|
|
|
|
const decorate = compose(
|
|
);
|
|
|
|
export default class Shaped extends decorate(Trait) {
|
|
|
|
static defaultParams() {
|
|
return {
|
|
shape: undefined,
|
|
};
|
|
}
|
|
|
|
static describeParams() {
|
|
return {
|
|
shape: {
|
|
type: 'object',
|
|
label: 'Shape',
|
|
},
|
|
};
|
|
}
|
|
|
|
static type() {
|
|
return 'shaped';
|
|
}
|
|
|
|
constructor(entity, params, state) {
|
|
super(entity, params, state);
|
|
this._shape = shapeFromJSON(this.params.shape);
|
|
this.shapeView = undefined;
|
|
}
|
|
|
|
destroy() {
|
|
this._shape.destroy();
|
|
if (this.shapeView) {
|
|
this.shapeView.destroy();
|
|
this.shapeView = undefined;
|
|
}
|
|
}
|
|
|
|
get shape() {
|
|
return this._shape;
|
|
}
|
|
|
|
listeners() {
|
|
return {
|
|
|
|
traitAdded: (type) => {
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
};
|
|
}
|
|
|
|
}
|