feat: explicit directional movement tracking

This commit is contained in:
cha0s 2019-03-19 10:20:49 -05:00
parent 1afc3609e4
commit d250d94f3b

View File

@ -14,6 +14,7 @@ class DirectionalBase extends Trait {
static defaultParams() {
return {
directionCount: 1,
trackMovement: true,
};
}
@ -23,15 +24,19 @@ class DirectionalBase extends Trait {
};
}
constructor(entity, params, state) {
super(...arguments);
this.directionCount = this.params.get('directionCount');
}
listeners() {
return {
movementRequest: (vector) => {
this.entity.direction = Vector.toDirection(
vector,
this.params.get('directionCount')
);
},
const listeners = {};
if (this.params.get('trackMovement')) {
listeners.movementRequest = (vector) => {
this.entity.direction = Vector.toDirection(vector, this.directionCount);
};
}
return listeners;
}
}