Skip to content

Commit

Permalink
feat: make it possible to wait for effects to be stopped
Browse files Browse the repository at this point in the history
This is done mostly so that Perfect Vision can react to all effects being stopped.
  • Loading branch information
ghost91- committed Dec 26, 2021
1 parent bc866bf commit c7a1b9b
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/module/weatherEffects/WeatherLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export class WeatherLayer extends CanvasLayer {
this._sceneMaskFilter = this._createSceneMaskFilter();
}

this.drawWeather();
await this.drawWeather();
this.updateMask();
}

Expand All @@ -169,17 +169,19 @@ export class WeatherLayer extends CanvasLayer {
}
Hooks.callAll("drawWeather", this, this.weather, this.weatherEffects);

Object.entries(this.weatherEffects).forEach(async ([id, effect]) => {
if (soft) {
await effect.fx.fadeOut({ timeout: 20000 });
} else {
effect.fx.stop();
}
// The check is needed because a new effect might have been set already.
if (this.weatherEffects[id] === effect) {
delete this.weatherEffects[id];
}
});
const stopPromise = Promise.all(
Object.entries(this.weatherEffects).map(async ([id, effect]) => {
if (soft) {
await effect.fx.fadeOut({ timeout: 20000 });
} else {
effect.fx.stop();
}
// The check is needed because a new effect might have been set already.
if (this.weatherEffects[id] === effect) {
delete this.weatherEffects[id];
}
}),
);

// Updating scene weather
const flags = canvas.scene.getFlag("fxmaster", "effects") ?? {};
Expand All @@ -194,6 +196,8 @@ export class WeatherLayer extends CanvasLayer {
};
this.weatherEffects[id].fx.play();
}

await stopPromise;
}

/**
Expand Down

0 comments on commit c7a1b9b

Please sign in to comment.