import {compose, EventEmitter, Property} from '@avocado/core'; 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, }), ) export class Shape extends decorate(class {}) { constructor() { super(); this.on([ 'originChanged', 'rotationChanged', 'scaleChanged', ], this.onAabbChanged, this); } get aabb() { return [0, 0, 0, 0]; } destroy() { this.off([ 'originChanged', 'rotationChanged', 'scaleChanged', ], this.onAabbChanged); } fromJSON(json) { const keys = [ 'origin', 'position', 'rotation', 'scale', ] for (const key of keys) { if (json[key]) { this[key] = json[key]; } } return this; } onAabbChanged() { this.emit('aabbChanged'); } toJSON() { return { origin: this.origin, position: this.position, rotation: this.rotation, scale: this.scale, }; } }