refactor: controllable ticks its used item
This commit is contained in:
parent
6728a20695
commit
4dc4a555de
|
@ -1,5 +1,6 @@
|
|||
import * as I from 'immutable';
|
||||
|
||||
import {TickingPromise} from '@avocado/core';
|
||||
import {Trait} from '@avocado/entity';
|
||||
|
||||
// Input handling.
|
||||
|
@ -12,6 +13,7 @@ export class Controllable extends Trait {
|
|||
constructor(entity, params, state) {
|
||||
super(entity, params, state);
|
||||
this._inputState = I.Map();
|
||||
this._itemPromise = undefined;
|
||||
}
|
||||
|
||||
set inputState(inputState) {
|
||||
|
@ -19,12 +21,18 @@ export class Controllable extends Trait {
|
|||
if (AVOCADO_SERVER) {
|
||||
if (inputState.has('UseItem')) {
|
||||
const slotIndex = inputState.get('UseItem');
|
||||
this.entity.useItemInSlot(slotIndex);
|
||||
this._itemPromise = this.entity.useItemInSlot(slotIndex);
|
||||
Promise.resolve(this._itemPromise).then(() => {
|
||||
this._itemPromise = undefined;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tick(elapsed) {
|
||||
if (this._itemPromise && this._itemPromise instanceof TickingPromise) {
|
||||
this._itemPromise.tick(elapsed);
|
||||
}
|
||||
const {_inputState: inputState} = this;
|
||||
if (0 === inputState.size) {
|
||||
this.entity.currentAnimation = 'idle';
|
||||
|
|
Loading…
Reference in New Issue
Block a user