Skip to content

Commit

Permalink
feat: make make handling of weather and filter effects more robust ag…
Browse files Browse the repository at this point in the history
…ainst unknown types
  • Loading branch information
ghost91- committed Jan 9, 2022
1 parent 61617bc commit 3ebee9d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/module/filterEffects/FilterManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,15 @@ class FilterManager {
if (!canvas.scene) {
return;
}
this.filterInfos = canvas.scene.getFlag("fxmaster", "filters") ?? {};
this.filterInfos = Object.fromEntries(
Object.entries(canvas.scene.getFlag("fxmaster", "filters") ?? {}).filter(([id, filterInfo]) => {
if (!(filterInfo.type in CONFIG.fxmaster.filters)) {
logger.warn(`Filter effect '${id}' is of unknown type '${filterInfo.type}', skipping it.`);
return false;
}
return true;
}),
);
this.filteredLayers = canvas.scene.getFlag("fxmaster", "filteredLayers") ?? this.filteredLayers;

const filtersToCreate = Object.keys(this.filterInfos).filter((key) => !(key in this.filters));
Expand Down Expand Up @@ -140,8 +148,9 @@ class FilterManager {
return;
}
const filter = this.filters[name];
if (filter === undefined) return;
await filter.stop();
if (filter) {
await filter.stop();
}
const rmFilter = {
[`-=${name}`]: null,
};
Expand Down
5 changes: 5 additions & 0 deletions src/module/weatherEffects/WeatherLayer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { logger } from "../logger.js";
import { executeWhenWorldIsMigratedToLatest, isOnTargetMigration } from "../migration.js";
import { intersectRectangles } from "../pixi-helpers.js";

Expand Down Expand Up @@ -207,6 +208,10 @@ export class WeatherLayer extends CanvasLayer {
// Updating scene weather
const flags = canvas.scene.getFlag("fxmaster", "effects") ?? {};
for (const id in flags) {
if (!(flags[id].type in CONFIG.fxmaster.weather)) {
logger.warn(`Weather effect '${id}' is of unknown type '${flags[id].type}', skipping it.`);
continue;
}
const options = Object.fromEntries(
Object.entries(flags[id].options).map(([optionName, value]) => [optionName, { value }]),
);
Expand Down

0 comments on commit 3ebee9d

Please sign in to comment.