Skip to content

Commit

Permalink
feat: make compatible with foundry V9
Browse files Browse the repository at this point in the history
Additionally, this introduces a new setting to set the required role to be able to create
effects.

BREAKING CHANGE: In foundry V9, it's not possible anymore to manipulate
the permissions in `CONST`. For that reason, it was necessary to switch
to using a setting instead. Unfortunately, it is not easily possible to
to migrate from the old way to the new way, so users will have to adapt
their settings to match what they had configured previously.
  • Loading branch information
ghost91- committed Dec 11, 2021
1 parent c9c21b2 commit e2320a5
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"FXMASTER.Ease": "Ease",
"FXMASTER.EaseHint": "Speed animation easing function",
"FXMASTER.PermissionCreate": "Use FXMaster special effects",
"FXMASTER.PermissionCreateHint": "Allow usage of FXMaster special effects through the scene controls.",
"FXMASTER.PermissionCreateHint": "Allow users with the selected role or above to use FXMaster special effects through the scene controls.",
"FXMASTER.MaskWeather": "Mask FXMaster Weather",
"FXMASTER.CastStatic": "Face target",
"FXMASTER.CastThrow": "Throw to target",
Expand Down
2 changes: 1 addition & 1 deletion src/lang/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@
"FXMASTER.Ease": "Ease",
"FXMASTER.EaseHint": "Función de redución de la animación de velocidad",
"FXMASTER.PermissionCreate": "Usar efectos especiales FXMaster",
"FXMASTER.PermissionCreateHint": "Permite usar los efectos especiales FXMaster en los controles de escena",
"FXMASTER.PermissionCreateHint": "Permitir a los usuarios con el rol seleccionado o superior utilizar los efectos especiales de FXMaster a través de los controles de la escena.",
"FXMASTER.MaskWeather": "Enmascarar climatología FXMaster"
}
2 changes: 1 addition & 1 deletion src/lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"FXMASTER.AnimationDelay": "Délai",
"FXMASTER.Ease": "Ease",
"FXMASTER.PermissionCreate": "Autoriser les effets spéciaux FXMaster",
"FXMASTER.PermissionCreateHint": "Autorise l'utilisation des effets spéciaux de FXMaster grâce aux contrôles de scène.",
"FXMASTER.PermissionCreateHint": "Permettre aux utilisateurs ayant le rôle sélectionné ou supérieur d'utiliser les effets spéciaux de FXMaster par le biais des commandes de scène.",
"FXMASTER.MaskWeather": "Masque la Météo FXMaster",
"FXMASTER.CastStatic": "En direction de la cible",
"FXMASTER.CastThrow": "En lançant vers la cible",
Expand Down
2 changes: 1 addition & 1 deletion src/module.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@
"license": "https://github.com/ghost-fvtt/fxmaster/blob/master/LICENSE",
"readme": "https://github.com/ghost-fvtt/fxmaster#readme",
"changelog": "https://github.com/ghost-fvtt/fxmaster/blob/master/CHANGELOG.md",
"compatibleCoreVersion": "0.8.8",
"compatibleCoreVersion": "9",
"minimumCoreVersion": "0.8.5"
}
2 changes: 1 addition & 1 deletion src/module/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function getSceneControlButtons(controls) {
title: "CONTROLS.Effects",
icon: "fas fa-magic",
layer: "specials",
visible: game.user.can("EFFECT_CREATE") || game.user.isGM,
visible: game.user.role >= game.settings.get("fxmaster", "permission-create"),
tools: [
{
name: "specials",
Expand Down
25 changes: 3 additions & 22 deletions src/module/fxmaster.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,9 @@ window.FXMASTER = {
};

function registerLayer() {
CONFIG.Canvas.layers = foundry.utils.mergeObject(CONFIG.Canvas.layers, {
fxmaster: WeatherLayer,
specials: SpecialsLayer,
});
// Overriding other modules if needed
if (!Object.is(Canvas.layers, CONFIG.Canvas.layers)) {
console.error("Possible incomplete layer injection by other module detected!...");

const layers = Canvas.layers;
Object.defineProperty(Canvas, "layers", {
get: function () {
return foundry.utils.mergeObject(layers, CONFIG.Canvas.layers);
},
});
}
const isV9OrLater = game.release?.generation ?? 0 >= 9;
CONFIG.Canvas.layers.fxmaster = isV9OrLater ? { layerClass: WeatherLayer, group: "effects" } : WeatherLayer;
CONFIG.Canvas.layers.specials = isV9OrLater ? { layerClass: SpecialsLayer, group: "effects" } : SpecialsLayer;
}

function parseSpecialEffects() {
Expand All @@ -55,13 +43,6 @@ Hooks.once("init", function () {
registerLayer();
registerHelpers();

CONST.USER_PERMISSIONS.EFFECT_CREATE = {
label: "FXMASTER.PermissionCreate",
hint: "FXMASTER.PermissionCreateHint",
defaultRole: 2,
disableGM: false,
};

// Adding filters, weathers and effects
if (!CONFIG.fxmaster) CONFIG.fxmaster = {};
foundry.utils.mergeObject(CONFIG.fxmaster, {
Expand Down
24 changes: 22 additions & 2 deletions src/module/settings.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export const registerSettings = function () {
game.settings.register("fxmaster", "enable", {
name: game.i18n.localize("FXMASTER.Enable"),
name: "FXMASTER.Enable",
default: true,
scope: "client",
type: Boolean,
config: true,
onChange: () => window.location.reload(),
onChange: debouncedReload,
});

game.settings.register("fxmaster", "specialEffects", {
Expand All @@ -23,4 +23,24 @@ export const registerSettings = function () {
type: Number,
config: false,
});

game.settings.register("fxmaster", "permission-create", {
name: "FXMASTER.PermissionCreate",
hint: "FXMASTER.PermissionCreateHint",
scope: "world",
config: true,
default: foundry.CONST.USER_ROLES.ASSISTANT,
type: Number,
choices: {
[foundry.CONST.USER_ROLES.PLAYER]: "USER.RolePlayer",
[foundry.CONST.USER_ROLES.TRUSTED]: "USER.RoleTrusted",
[foundry.CONST.USER_ROLES.ASSISTANT]: "USER.RoleAssistant",
[foundry.CONST.USER_ROLES.GAMEMASTER]: "USER.RoleGamemaster",
},
onChange: debouncedReload,
});
};

const debouncedReload = foundry.utils.debounce(() => {
window.location.reload();
}, 100);

0 comments on commit e2320a5

Please sign in to comment.