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]) { const positionChanged = x !== entity.x || y !== entity.y; const lastPosition = entity.position; this.entity.x = x; this.entity.y = y; if (positionChanged) { this.entity.emit('positionChanged', entity.position, lastPosition); } } } export class Positioned extends decorate(PositionedBase) {}