refactor: addTickingPromise
This commit is contained in:
parent
320a20e695
commit
5b7e30de04
|
@ -74,7 +74,6 @@ export class Alive extends decorate(Trait) {
|
|||
this._deathActions = behaviorItemFromJSON(this.params.deathActions);
|
||||
this._deathSound = this.params.deathSound;
|
||||
this._deathCondition = behaviorItemFromJSON(this.params.deathCondition);
|
||||
this._dyingTickingPromise = false;
|
||||
}
|
||||
|
||||
destroy() {
|
||||
|
@ -133,21 +132,21 @@ export class Alive extends decorate(Trait) {
|
|||
methods() {
|
||||
return {
|
||||
|
||||
dieIfPossible: () => {
|
||||
dieIfPrescribed: () => {
|
||||
if (this._deathCondition.check(this._context)) {
|
||||
this.entity.forceDeath();
|
||||
}
|
||||
},
|
||||
|
||||
forceDeath: () => {
|
||||
if (this._dyingTickingPromise) {
|
||||
if (this.entity.isDying) {
|
||||
return;
|
||||
}
|
||||
this.entity.isDying = true;
|
||||
this._dyingTickingPromise = this._deathActions.tickingPromise(
|
||||
const dyingTickingPromise = this._deathActions.tickingPromise(
|
||||
this._context
|
||||
)
|
||||
this._dyingTickingPromise.then(() => {
|
||||
this.entity.addTickingPromise(dyingTickingPromise).then(() => {
|
||||
const diedPromises = this.entity.invokeHookFlat('died');
|
||||
Promise.all(diedPromises).then(() => {
|
||||
this.entity.destroy();
|
||||
|
@ -159,13 +158,8 @@ export class Alive extends decorate(Trait) {
|
|||
}
|
||||
|
||||
tick(elapsed) {
|
||||
if (this._dyingTickingPromise) {
|
||||
this._dyingTickingPromise.tick(elapsed);
|
||||
}
|
||||
else {
|
||||
if (AVOCADO_SERVER) {
|
||||
this.entity.dieIfPossible();
|
||||
}
|
||||
if (AVOCADO_SERVER) {
|
||||
this.entity.dieIfPrescribed();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user