v0.2.0: Add setting to disable dynamic borders

The point of the module is to allow multiple functionalities
to support our campaign.
They might not be suited all the time or to all of them.
They might be buggy !

Add a toggle setting to the dynamic borders functionality,
so that we can keep the compendium while it is fixed.
This commit is contained in:
trotFunky 2025-05-28 18:53:59 +01:00
parent 6c3ce53101
commit f617b26fe1
10 changed files with 43 additions and 18 deletions

View file

@ -18,6 +18,7 @@ const SocketMessages = Object.freeze({
})
const BorderSettings = Object.freeze({
BorderEnabled: "borderEnabled",
BaseBorderPath: "baseBorderPath",
PlayedBorderPath: "playedBorderPath",
})
@ -151,11 +152,23 @@ function combat_hook_update_token_borders(combat, data) {
function combat_border_main() {
Hooks.once("init", () => {
game.settings.register(MillsFabula.id, BorderSettings.BorderEnabled, {
name: game.i18n.localize('MF.Border.Settings.BorderEnabled.Name'),
hint: game.i18n.localize('MF.Border.Settings.BorderEnabled.Hint'),
type: Boolean,
config: true,
scope: 'world',
requiresReload: true,
default: true
});
// Only show the settings if the borders are enabled.
let borders_enabled = game.settings.get(MillsFabula.id, BorderSettings.BorderEnabled);
game.settings.register(MillsFabula.id, BorderSettings.BaseBorderPath, {
name: game.i18n.localize('MF.Border.Settings.BaseBorder.Name'),
hint: game.i18n.localize('MF.Border.Settings.BaseBorder.Hint'),
type: String,
config: true,
config: borders_enabled,
scope: 'world',
requiresReload: true,
filePicker: 'image',
@ -166,7 +179,7 @@ function combat_border_main() {
name: game.i18n.localize('MF.Border.Settings.PlayedBorder.Name'),
hint: game.i18n.localize('MF.Border.Settings.PlayedBorder.Hint'),
type: String,
config: true,
config: borders_enabled,
scope: 'world',
requiresReload: true,
filePicker: 'image',
@ -186,6 +199,10 @@ function combat_border_main() {
// Create the borders from defined textures and add them to the tokens when they are first created on canvas.
// FIXME: Does not work on scene change !
Hooks.on("drawToken", (drawn_token) => {
// FIXME: Handle deactivation properly
if (!game.settings.get(MillsFabula.id, BorderSettings.BorderEnabled)) {
return;
}
// Only apply the borders to player tokens
if (drawn_token.actor?.type !== "character")
return;
@ -207,6 +224,10 @@ function combat_border_main() {
Hooks.on("ready", () => {
// FIXME: Handle deactivation properly
if (!game.settings.get(MillsFabula.id, BorderSettings.BorderEnabled)) {
return;
}
// Players cannot run the combat hooks used here, which trigger for the GM no matter what.
// So register them for the GM only, who will execute the updates for players via SocketLib.
if (!game.user?.isGM) {