Skip to content

Commit

Permalink
Add an opt-in setting to enable Pixels dice for the client
Browse files Browse the repository at this point in the history
  • Loading branch information
aaclayton committed Jun 27, 2023
1 parent 5bdbb03 commit 0bf9f67
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
13 changes: 10 additions & 3 deletions scripts/apps/pixels-config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -121,4 +121,11 @@ export default class PixelsConfiguration extends Application {
await pixel.disconnect();
this.render(false, {height: "auto"});
}

/* -------------------------------------------- */

/** @override */
_updateObject(event, formData) {
// No-op
}
}
31 changes: 31 additions & 0 deletions scripts/pixels.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
});
Expand Down
6 changes: 5 additions & 1 deletion templates/pixels-config.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@
{{/each}}
</header>

<footer>
<footer class="flexrow">
<button type="button" data-action="requestPixel">
<i class="fa-solid fa-plus"></i>
Add Pixel Dice
</button>
<button type="submit">
<i class="fa-solid fa-check"></i>
Complete
</button>
</footer>
</section>
</form>

0 comments on commit 0bf9f67

Please sign in to comment.