From 71843116c49eaf158fc8ee410df2f1536d4c819c Mon Sep 17 00:00:00 2001 From: Christopher Renaud Oelerich Date: Sat, 30 Mar 2024 16:54:41 -0500 Subject: [PATCH] Scaffolding for initiative tracking. --- src/combat.mjs | 18 ++++++++++++++---- src/module.mjs | 5 +++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/combat.mjs b/src/combat.mjs index 8883e13..266bd70 100644 --- a/src/combat.mjs +++ b/src/combat.mjs @@ -1,11 +1,21 @@ import {item_roll, Logger} from "./util.mjs"; -import {session_id, socket} from "./module.mjs"; +import {socket} from "./module.mjs"; import {ID_MAP, MODULE_ID} from "./constants.mjs"; -export function combat_hooks() { - Logger.info("Monk's Tokenbar found.") - socket.emit('combat', {session_id: session_id, id_to_xp: mtb.actors.map(a => ([a['id'], a['xp']]))}) +//TODO: Include some logic to set/remove these hooks when combat_tracking_enabled is changed +export function set_combat_hooks() { + Logger.info("Setting Combat Hooks.") + + Hooks.on("combatStart", async (combat, updateData) => { + socket.emit('combat', combat.toJSON()) + }) + Hooks.on("combatTurn", async (combat, updateData) => { + socket.emit('combat', combat.toJSON()) + }) + Hooks.on("combatRound", async (combat, updateData) => { + socket.emit('combat', combat.toJSON()) + }) } export function handle_incoming_rolls() { diff --git a/src/module.mjs b/src/module.mjs index ee54f32..6fe2343 100644 --- a/src/module.mjs +++ b/src/module.mjs @@ -29,8 +29,6 @@ Hooks.once("ready", async () => { if (game.user.isGM) { await registerSettings() open_socket_with_oronder() - monks_token_bar_hooks() - handle_incoming_rolls() } game.socket.on(SOCKET_NAME, data => { @@ -96,6 +94,9 @@ export function open_socket_with_oronder(update = false) { set_session(session) game.socket.emit(SOCKET_NAME, {action: 'session', session: session}) }) + + monks_token_bar_hooks() + handle_incoming_rolls() }