avocado-old/packages/physics/shape.js
2019-04-28 23:45:03 -05:00

67 lines
1.1 KiB
JavaScript

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.emit('aabbChanged');
});
}
get aabb() {
return [0, 0, 0, 0];
}
fromJSON(json) {
const keys = [
'origin',
'position',
'rotation',
'scale',
]
for (const key of keys) {
if (json[key]) {
this[key] = json[key];
}
}
return this;
}
toJSON() {
return {
origin: this.origin,
position: this.position,
rotation: this.rotation,
scale: this.scale,
};
}
}