diff --git a/module.json b/module.json index c6f8c19..98467dd 100644 --- a/module.json +++ b/module.json @@ -7,7 +7,7 @@ "manifestPlusVersion": "1.2.0", "compatibility": { "minimum": 11.303, - "verified": 11.315 + "verified": 12.316 }, "authors": [ { @@ -27,7 +27,7 @@ "manifest": "https://raw.githubusercontent.com/foundryvtt/dnd5e/master/system.json", "compatibility": { "minimum": "2.4.0", - "verified": "3.0.0" + "verified": "3.0.1" } } ] diff --git a/package.json b/package.json index 7e0a136..6519d02 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "scripts": { "build": "esbuild src/module.mjs --bundle --minify --format=esm --outdir=dist", "build-dev": "esbuild src/module.mjs --bundle --sourcemap=inline --format=esm --outdir=dist", - "build-dev-with-copy": "esbuild src/module.mjs --bundle --sourcemap=inline --format=esm --outdir=dist && mkdir -p ../foundry_data/Data/modules/oronder/ && cp -r ./* ../foundry_data/Data/modules/oronder/" + "copy-11": "mkdir -p ../foundry_data/Data/modules/oronder/ && cp -r ./* ../foundry_data/Data/modules/oronder/", + "copy-12": "mkdir -p ../foundry_data_12/Data/modules/oronder/ && cp -r ./* ../foundry_data_12/Data/modules/oronder/" } } diff --git a/src/module.mjs b/src/module.mjs index 5a1f577..8f9bc9d 100644 --- a/src/module.mjs +++ b/src/module.mjs @@ -2,11 +2,12 @@ import {Logger} from "./util.mjs" import {registerSettings} from "./settings.mjs" import {AUTH, MODULE_ID, ORONDER_WS_URL} from "./constants.mjs" import {del_actor, sync_actor} from "./sync.mjs" +import {monks_token_bar_hooks} from "./monks_token_bar_hooks.mjs"; -let socket +export let socket +export let session_id +export let session_ts let session_name -let session_id -let session_ts let default_title const SOCKET_NAME = `module.${MODULE_ID}` @@ -27,36 +28,8 @@ Hooks.once("ready", async () => { if (game.user.isGM) { await registerSettings() open_socket_with_oronder() - - const monks_tokenbar = game.modules.get('monks-tokenbar') - if (monks_tokenbar?.active) { - Logger.info("Monk's Tokenbar found.") - let last_xp_ts = new Date().getTime() - Hooks.on("renderChatMessage", async (message, html, messageData) => { - const mtb = message.flags['monks-tokenbar'] - if ( - mtb && - messageData.author.id === game.userId && - game.user.role >= CONST.USER_ROLES.ASSISTANT && - message['timestamp'] > last_xp_ts - ) { - if (!mtb.actors.map(a => a.xp).every(xp => xp === mtb.actors[0].xp)) { - Logger.warn('Oronder does not currently support unequal XP distribution :(') - } else if (!mtb.actors.length) { - Logger.warn('No actors to reward xp to') - } else if (session_id === undefined) { - Logger.warn('No Session Found') - } else if (message['timestamp'] < session_ts) { - Logger.warn('XP reward predates session start') - } else { - last_xp_ts = message['timestamp'] - socket.emit('xp', {session_id: session_id, id_to_xp: mtb.actors.map(a => ([a['id'], a['xp']]))}) - } - } - }) - } + monks_token_bar_hooks(); } - Logger.info('Ready') }) diff --git a/src/monks_token_bar_hooks.mjs b/src/monks_token_bar_hooks.mjs new file mode 100644 index 0000000..be9335f --- /dev/null +++ b/src/monks_token_bar_hooks.mjs @@ -0,0 +1,32 @@ +import {Logger} from "./util.mjs"; +import {session_id, session_ts, socket} from "./module.mjs"; + +export function monks_token_bar_hooks() { + const monks_tokenbar = game.modules.get('monks-tokenbar') + if (monks_tokenbar?.active) { + Logger.info("Monk's Tokenbar found.") + let last_xp_ts = new Date().getTime() + Hooks.on("renderChatMessage", async (message, html, messageData) => { + const mtb = message.flags['monks-tokenbar'] + if ( + mtb && + messageData.author.id === game.userId && + game.user.role >= CONST.USER_ROLES.ASSISTANT && + message['timestamp'] > last_xp_ts + ) { + if (!mtb.actors.map(a => a.xp).every(xp => xp === mtb.actors[0].xp)) { + Logger.warn('Oronder does not currently support unequal XP distribution :(') + } else if (!mtb.actors.length) { + Logger.warn('No actors to reward xp to') + } else if (session_id === undefined) { + Logger.warn('No Session Found') + } else if (message['timestamp'] < session_ts) { + Logger.warn('XP reward predates session start') + } else { + last_xp_ts = message['timestamp'] + socket.emit('xp', {session_id: session_id, id_to_xp: mtb.actors.map(a => ([a['id'], a['xp']]))}) + } + } + }) + } +} \ No newline at end of file diff --git a/src/settings-form-application.mjs b/src/settings-form-application.mjs index d39af0f..bdf8acb 100644 --- a/src/settings-form-application.mjs +++ b/src/settings-form-application.mjs @@ -210,7 +210,7 @@ export class OronderSettingsFormApplication extends FormApplication { const guild = await this._handle_json_response(response) this.object.guild_name = guild.name } catch (error) { - this.object.guild_name = undefined + this.object.guild_name = '' Logger.error(`Error setting guild name: ${error.message}`) } } diff --git a/src/settings.mjs b/src/settings.mjs index b285243..f31bd65 100644 --- a/src/settings.mjs +++ b/src/settings.mjs @@ -6,13 +6,15 @@ export const registerSettings = async () => { game.settings.register(MODULE_ID, GUILD_NAME, { scope: "world", type: String, - config: false + config: false, + default:'' }) game.settings.register(MODULE_ID, AUTH, { scope: "world", type: String, - config: false + config: false, + default:'' }) game.settings.register(MODULE_ID, ID_MAP, {