Skip to content

Commit

Permalink
Update module for compatibility with Foundry VTT v12 unfulfilled roll…
Browse files Browse the repository at this point in the history
…s API.
  • Loading branch information
Fyorl committed Feb 21, 2024
1 parent 73220a7 commit c86e20a
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 187 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Pixels Electronic Dice - Foundry VTT Integration

![alt text](https://raw.githubusercontent.com/foundryvtt/pixels/main/ui/pixels-logo.png)
![Pixels Electronic Dice Logo](https://raw.githubusercontent.com/foundryvtt/pixels/main/ui/pixels-logo.png)

This module integrates **Pixels - The Electronic Dice** (https://gamewithpixels.com) with **Foundry Virtual Tabletop** (https://foundryvtt.com).

Expand All @@ -10,7 +10,7 @@ To use this module you must have:
2. One or more Pixels electronic dice. This module is currently designed and tested using Pixels DevKit d20s.

## Installing and Activating the Module
Install the `pixels` module from the Foundry Virtual Tabletop module installation menu. Also install the dependency module `unfulfilled-rolls` which you will be automatically prompted to install. In your game World, activate both the `pixels` and `unfulfilled-rolls` modules.
Install the "Pixels - Electronic Dice" module from the Foundry Virtual Tabletop module installation menu. In your game World, activate the "Pixels - Electronic Dice" module.

## Enabling Pixels Dice Integration
Navigate to the **Settings** sidebar, **Configure Settings**, and the **Pixels** tab. From here check the **Enable Pixels Dice** setting. You will be automatically prompted after this to configure your dice. You can return to this menu at any time to disable Pixels dice or change your Pixels configuration.
Expand Down
16 changes: 2 additions & 14 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,15 @@
"download": "#{DOWNLOAD}#",
"url": "https://gamewithpixels.com/",
"compatibility": {
"minimum": 10,
"verified": 11
"minimum": 12,
"verified": 12
},
"authors": [
{
"name": "Foundry Virtual Tabletop Team",
"website": "https://foundryvtt.com"
}
],
"relationships": {
"systems": [],
"requires": [
{
"id": "unfulfilled-rolls",
"type": "module",
"compatibility": {
"minimum": "0.1.0"
}
}
]
},
"scripts": [
"node_modules/@systemic-games/pixels-web-connect/dist/umd/index.js"
],
Expand Down
111 changes: 0 additions & 111 deletions scripts/apps/pixels-resolver.mjs

This file was deleted.

8 changes: 4 additions & 4 deletions scripts/handlers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
*/
export function handleRoll(config, result) {
console.debug(`${config.name} rolled an ${result}`);
const resolver = pixelsDice.RESOLVERS[0];
if ( resolver ) return resolver.registerResult(config, result);
else return manualRoll(config, result);
if ( !Roll.defaultImplementation.registerResult("pixels", `d${config.denomination}`, result) ) {
return manualRoll(config, result);
}
}

/* -------------------------------------------- */
Expand Down Expand Up @@ -49,7 +49,7 @@ let _pendingRoll = {};

export function manualRoll(config, result) {
_pendingRoll[config.name] = {denomination: config.denomination, value: result};
pixelsDice.debounceRoll()
pixelsDice.debounceRoll();
}

/* -------------------------------------------- */
Expand Down
40 changes: 3 additions & 37 deletions scripts/pixels.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import PixelsManager from "./manager.mjs";
import PixelsConfiguration from "./apps/pixels-config.mjs";
import PixelsResolver from "./apps/pixels-resolver.mjs";
import * as api from "./handlers.mjs";

/**
* A queue of PixelsResolver instances which require resolution
* @type {PixelsResolver[]}
*/
const RESOLVERS = [];

/* -------------------------------------------- */
/* Client Initialization */
/* -------------------------------------------- */
Expand Down Expand Up @@ -46,11 +39,13 @@ Hooks.on("init", function() {
restricted: false
});

// Core Dice Configuration
CONFIG.Dice.fulfillment.methods.pixels = { label: "Pixels - Electronic Dice", interactive: true };

// Register module properties
const module = globalThis.pixelsDice = game.modules.get("pixels");
module.enabled = false;
module.PIXELS = PixelsManager.fromSetting();
module.RESOLVERS = RESOLVERS;
module.api = api;
module.debounceRoll = foundry.utils.debounce(api.completeManualRoll, 1000);
});
Expand All @@ -67,22 +62,6 @@ Hooks.on("ready", function() {
/* -------------------------------------------- */

async function _initialize(enabled) {

// Automatic configuration of dice provider settings
const unfulfilledRollsConfig = game.settings.get("unfulfilled-rolls", "diceSettings");
if ( enabled ) {
game.settings.set("unfulfilled-rolls", "diceSettings", Object.assign(unfulfilledRollsConfig, {
bluetoothDieProvider: "pixels",
d20: "bluetooth"
}));
}
else if ( unfulfilledRollsConfig.bluetoothDieProvider === "pixels" ) {
game.settings.set("unfulfilled-rolls", "diceSettings", Object.assign(unfulfilledRollsConfig, {
bluetoothDieProvider: "none",
d20: "fvtt"
}));
}

// Automatic connection to available dice
if ( !enabled ) return;
const reconnectSuccess = await pixelsDice.PIXELS.tryReconnect();
Expand All @@ -93,16 +72,3 @@ async function _initialize(enabled) {
app.render(true);
}
}

/* -------------------------------------------- */
/* Unfulfilled Rolls Configuration */
/* -------------------------------------------- */

Hooks.once('unfulfilled-rolls-bluetooth', function(providers) {
providers.pixels = {
label: "Pixels - Electronic Dice",
url: "https://gamewithpixels.com",
app: PixelsResolver
}
});

3 changes: 2 additions & 1 deletion templates/pixels-config.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

<form autocomplete="off">
<figure>
<img class="noborder" src="modules/pixels/ui/pixels-logo.webp">
<img class="noborder" src="modules/pixels/ui/pixels-logo.webp" width="437" height="170"
alt="Pixels Electronic Dice Logo">
</figure>

{{#if hasDevices}}
Expand Down
18 changes: 0 additions & 18 deletions templates/pixels-resolver.hbs

This file was deleted.

0 comments on commit c86e20a

Please sign in to comment.