refactor: ticking promise
This commit is contained in:
parent
a856950931
commit
4f6869863c
|
@ -71,7 +71,7 @@ export class Alive extends decorate(Trait) {
|
||||||
this._deathSound = this.params.deathSound;
|
this._deathSound = this.params.deathSound;
|
||||||
const conditionJSON = this.params.deathCondition;
|
const conditionJSON = this.params.deathCondition;
|
||||||
this._deathCondition = behaviorItemFromJSON(conditionJSON);
|
this._deathCondition = behaviorItemFromJSON(conditionJSON);
|
||||||
this._isDying = false;
|
this._dyingTickingPromise = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
|
@ -123,15 +123,17 @@ export class Alive extends decorate(Trait) {
|
||||||
},
|
},
|
||||||
|
|
||||||
forceDeath: () => {
|
forceDeath: () => {
|
||||||
if (this._isDying) {
|
if (this._dyingTickingPromise) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this._isDying = true;
|
this._dyingTickingPromise = this._deathActions.tickingPromise(
|
||||||
this.entity.emit('dying');
|
this._context
|
||||||
this._deathActions.once('actionsFinished', () => {
|
)
|
||||||
if (this.entity.is('existent')) {
|
this._dyingTickingPromise.then(() => {
|
||||||
this.entity.destroy();
|
if (!this.entity.is('existent')) {
|
||||||
|
throw new Error("STATE PROBLEM: non-existent entity up for death");
|
||||||
}
|
}
|
||||||
|
this.entity.destroy();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -139,8 +141,8 @@ export class Alive extends decorate(Trait) {
|
||||||
}
|
}
|
||||||
|
|
||||||
tick(elapsed) {
|
tick(elapsed) {
|
||||||
if (this._isDying) {
|
if (this._dyingTickingPromise) {
|
||||||
this._deathActions.tick(this._context, elapsed);
|
this._dyingTickingPromise.tick(elapsed);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.entity.dieIfPossible();
|
this.entity.dieIfPossible();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user