avocado-old/packages/entity/traits/positioned.js
2019-03-18 20:05:00 -05:00

37 lines
551 B
JavaScript

import {compose} from '@avocado/core';
import {simpleState, Trait} from '../trait';
const decorate = compose(
simpleState('x', {
track: true,
}),
simpleState('y', {
track: true,
}),
);
class PositionedBase extends Trait {
static defaultState() {
return {
x: 0,
y: 0,
};
}
get position() {
return [
this.state.get('x'),
this.state.get('y'),
];
}
set position([x, y]) {
this.state = this.state.merge({x, y});
}
}
export class Positioned extends decorate(PositionedBase) {}