refactor: heat off entity tick

This commit is contained in:
cha0s 2019-04-12 13:05:39 -05:00
parent 5119aea688
commit 4a076c7678

View File

@ -9,44 +9,40 @@ export class Controllable extends Trait {
this._inputState = I.Map();
}
listeners() {
return {
tick: (elapsed) => {
const {_inputState: inputState} = this;
if (0 === inputState.size) {
this.entity.currentAnimation = 'idle';
return;
}
const movementVector = [0, 0];
if (inputState.has('MoveTo')) {
const moveTo = inputState.get('MoveTo');
movementVector[0] = moveTo[0];
movementVector[1] = moveTo[1];
}
if (inputState.has('MoveUp')) {
movementVector[1] -= 1;
}
if (inputState.has('MoveRight')) {
movementVector[0] += 1;
}
if (inputState.has('MoveDown')) {
movementVector[1] += 1;
}
if (inputState.has('MoveLeft')) {
movementVector[0] -= 1;
}
if (0 === movementVector[0] && 0 === movementVector[1]) {
return;
}
this.entity.requestMovement(movementVector);
this.entity.currentAnimation = 'moving';
},
}
}
set inputState(inputState) {
this._inputState = I.Map(inputState);
}
tick(elapsed) {
const {_inputState: inputState} = this;
if (0 === inputState.size) {
this.entity.currentAnimation = 'idle';
return;
}
const movementVector = [0, 0];
if (inputState.has('MoveTo')) {
const moveTo = inputState.get('MoveTo');
movementVector[0] = moveTo[0];
movementVector[1] = moveTo[1];
}
if (inputState.has('MoveUp')) {
movementVector[1] -= 1;
}
if (inputState.has('MoveRight')) {
movementVector[0] += 1;
}
if (inputState.has('MoveDown')) {
movementVector[1] += 1;
}
if (inputState.has('MoveLeft')) {
movementVector[0] -= 1;
}
if (0 === movementVector[0] && 0 === movementVector[1]) {
return;
}
this.entity.requestMovement(movementVector);
this.entity.currentAnimation = 'moving';
}
}