2019-04-28 23:45:03 -05:00
|
|
|
import {compose, EventEmitter, Property} from '@avocado/core';
|
2019-03-22 11:25:20 -05:00
|
|
|
import {Vector} from '@avocado/math';
|
|
|
|
|
|
|
|
const decorate = compose(
|
|
|
|
EventEmitter,
|
|
|
|
Property('parent'),
|
|
|
|
Property('rotation', {
|
|
|
|
default: 0,
|
|
|
|
track: true,
|
|
|
|
}),
|
|
|
|
Property('scale', {
|
|
|
|
default: 1,
|
|
|
|
track: true,
|
|
|
|
}),
|
|
|
|
Vector.Mixin('origin', 'originX', 'originY', {
|
|
|
|
default: [0, 0],
|
|
|
|
track: true,
|
|
|
|
}),
|
|
|
|
Vector.Mixin('position', 'x', 'y', {
|
|
|
|
default: [0, 0],
|
|
|
|
track: true,
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
|
2019-03-27 16:18:27 -05:00
|
|
|
export class Shape extends decorate(class {}) {
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.on([
|
|
|
|
'originChanged',
|
|
|
|
'rotationChanged',
|
|
|
|
'scaleChanged',
|
2019-05-03 01:21:35 -05:00
|
|
|
], this.onAabbChanged, this);
|
2019-03-27 16:18:27 -05:00
|
|
|
}
|
2019-03-22 11:25:20 -05:00
|
|
|
|
|
|
|
get aabb() {
|
|
|
|
return [0, 0, 0, 0];
|
|
|
|
}
|
|
|
|
|
2019-05-03 01:21:35 -05:00
|
|
|
destroy() {
|
|
|
|
this.off([
|
|
|
|
'originChanged',
|
|
|
|
'rotationChanged',
|
|
|
|
'scaleChanged',
|
|
|
|
], this.onAabbChanged);
|
|
|
|
}
|
|
|
|
|
2019-03-22 11:25:20 -05:00
|
|
|
fromJSON(json) {
|
|
|
|
const keys = [
|
|
|
|
'origin',
|
|
|
|
'position',
|
|
|
|
'rotation',
|
|
|
|
'scale',
|
|
|
|
]
|
|
|
|
for (const key of keys) {
|
|
|
|
if (json[key]) {
|
|
|
|
this[key] = json[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2019-05-03 01:21:35 -05:00
|
|
|
onAabbChanged() {
|
|
|
|
this.emit('aabbChanged');
|
|
|
|
}
|
|
|
|
|
2019-04-13 03:32:44 -05:00
|
|
|
toJSON() {
|
|
|
|
return {
|
|
|
|
origin: this.origin,
|
|
|
|
position: this.position,
|
|
|
|
rotation: this.rotation,
|
|
|
|
scale: this.scale,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-03-22 11:25:20 -05:00
|
|
|
}
|