diff --git a/scripts/apps/pixels-config.mjs b/scripts/apps/pixels-config.mjs index 577c921..3e93af1 100644 --- a/scripts/apps/pixels-config.mjs +++ b/scripts/apps/pixels-config.mjs @@ -3,9 +3,9 @@ import {handleRoll, handleStatus} from "../handlers.mjs"; /** * An application used for initial configuration of Pixels dice. */ -export default class PixelsConfiguration extends Application { - constructor(options) { - super(options); +export default class PixelsConfiguration extends FormApplication { + constructor(_, options) { + super(pixelsDice, options); pixelsDice.config = this; } @@ -121,4 +121,11 @@ export default class PixelsConfiguration extends Application { await pixel.disconnect(); this.render(false, {height: "auto"}); } + + /* -------------------------------------------- */ + + /** @override */ + _updateObject(event, formData) { + // No-op + } } diff --git a/scripts/pixels.mjs b/scripts/pixels.mjs index f3a8de5..a8706eb 100644 --- a/scripts/pixels.mjs +++ b/scripts/pixels.mjs @@ -28,7 +28,36 @@ const RESOLVERS = []; /* -------------------------------------------- */ Hooks.on("init", function() { + + // Pixels enabled + game.settings.register("pixels", "enabled", { + scope: "client", + name: "Enable Pixels Dice", + hint: "Enable use of Pixels Electronic Dice in the Foundry VTT game client", + config: true, + type: Boolean, + default: false, + onChange: enabled => { + module.enabled = enabled; + if ( enabled ) { + const config = new PixelsConfiguration(); + config.render(true); + } + } + }); + + // Configuration menu + game.settings.registerMenu("pixels", "configuration", { + name: "Pixels Configuration", + label: "Configure Pixels", + icon: "fa-solid fa-dice-d20", + type: PixelsConfiguration, + restricted: false + }) + + // Register module properties const module = globalThis.pixelsDice = game.modules.get("pixels"); + module.enabled = false; module.PIXELS = PIXELS; module.RESOLVERS = RESOLVERS; module.api = api; @@ -40,6 +69,8 @@ Hooks.on("init", function() { /* -------------------------------------------- */ Hooks.on("ready", async function() { + const enabled = globalThis.pixelsDice.enabled = game.settings.get("pixels", "enabled"); + if ( !enabled ) return; const app = new PixelsConfiguration(); app.render(true); }); diff --git a/templates/pixels-config.hbs b/templates/pixels-config.hbs index 2a8dac3..27e4a58 100644 --- a/templates/pixels-config.hbs +++ b/templates/pixels-config.hbs @@ -14,11 +14,15 @@ {{/each}} -