refactor: item repeats

This commit is contained in:
cha0s 2020-01-17 03:48:03 -06:00
parent 128d39aa42
commit 989e34e68e

View File

@ -11,6 +11,7 @@ export class Controllable extends Trait {
constructor(entity, params, state) {
super(entity, params, state);
this._isUsingItem = -1;
this._itemPromise = undefined;
this._movementVector = [0, 0];
}
@ -34,12 +35,7 @@ export class Controllable extends Trait {
break;
case 'UseItem':
if (AVOCADO_SERVER) {
if (-1 !== value && !this._itemPromise) {
this._itemPromise = this.entity.useItemInSlot(value);
Promise.resolve(this._itemPromise).then(() => {
this._itemPromise = undefined;
});
}
this._isUsingItem = value;
}
break;
}
@ -53,6 +49,12 @@ export class Controllable extends Trait {
}
tick(elapsed) {
if (-1 !== this._isUsingItem && !this._itemPromise) {
this._itemPromise = this.entity.useItemInSlot(this._isUsingItem);
Promise.resolve(this._itemPromise).then(() => {
this._itemPromise = undefined;
});
}
if (this._itemPromise && this._itemPromise instanceof TickingPromise) {
this._itemPromise.tick(elapsed);
}