diff --git a/module/rdd-main.js b/module/rdd-main.js index 4ac24479..394afcfa 100644 --- a/module/rdd-main.js +++ b/module/rdd-main.js @@ -18,6 +18,7 @@ import { RdDUtility } from "./rdd-utility.js"; import { TMRUtility } from "./tmr-utility.js"; import { RdDCalendrier } from "./rdd-calendrier.js"; import { RdDResolutionTable } from "./rdd-resolution-table.js"; +import { RdDTokenHud } from "./rdd-token-hud.js"; /* -------------------------------------------- */ /* Foundry VTT Initialization */ @@ -67,13 +68,12 @@ const _patch_initiative = () => { } //console.log("Combatat", c); const roll = this._getInitiativeRoll(c, rollFormula); - //console.log("Compute init for", armeCombat, competence, rollFormula, roll.total); - + if ( roll.total <= 0 ) roll.total = 1; + //console.log("Compute init for", armeCombat, competence, rollFormula, roll.total); await this.updateEmbeddedEntity("Combatant", { _id: c._id, initiative: roll.total }); // Send a chat message - let rollMode = - messageOptions.rollMode || game.settings.get("core", "rollMode"); + let rollMode = messageOptions.rollMode || game.settings.get("core", "rollMode"); let messageData = mergeObject( { speaker: { @@ -187,10 +187,6 @@ Hooks.once("init", async function() { _patch_initiative(); }); -Hooks.once("renderApplication", () => { - messageDeBienvenue(); -}); - /* -------------------------------------------- */ function messageDeBienvenue(){ game.messages @@ -204,6 +200,11 @@ function messageDeBienvenue(){ ); } +/* -------------------------------------------- */ +Hooks.once("renderApplication", () => { + messageDeBienvenue(); +}); + /* -------------------------------------------- */ /* Foundry VTT Initialization */ /* -------------------------------------------- */ @@ -223,6 +224,8 @@ Hooks.once("ready", function() { //whisper: [ ChatMessage.getWhisperRecipients("GM") ] } ); } + // Integration du TokenHUD + Hooks.on('renderTokenHUD', (app, html, data) => { RdDTokenHud.addTokenHudExtensions(app, html, data) }); }); /* -------------------------------------------- */ diff --git a/module/rdd-resolution-table.js b/module/rdd-resolution-table.js index 43a8fa59..9edf47d3 100644 --- a/module/rdd-resolution-table.js +++ b/module/rdd-resolution-table.js @@ -51,10 +51,12 @@ const reussites = [ { code: "error", isPart: false, isSign: false, isSuccess: false, isEchec: true, isEPart: true, isETotal: true, ptTache: 0, ptQualite: 0, quality: "Jet de dés invalide", condition: (target, roll) => (roll <= 0 || roll > 100) } ]; +/* -------------------------------------------- */ const reussiteSignificative = reussites.find(r => r.code == "sign"); const reussiteNormale = reussites.find(r => r.code == "norm"); const echecNormal = reussites.find(r => r.code == "echec"); +/* -------------------------------------------- */ export class RdDResolutionTable { static resolutionTable = this.build() diff --git a/module/rdd-token-hud.js b/module/rdd-token-hud.js new file mode 100644 index 00000000..c1206948 --- /dev/null +++ b/module/rdd-token-hud.js @@ -0,0 +1,51 @@ +/* -------------------------------------------- */ +import { RdDUtility } from "./rdd-utility.js"; + +/* -------------------------------------------- */ +export class RdDTokenHud { + + /* -------------------------------------------- */ + static addTokenHudExtensions( app, html, data ) { + let token = canvas.tokens.get(data._id); + + // Affichage seulement si le token est un combat + if ( token.inCombat) { + this.addInitiativeTokenTip(html, token); + } + } + + /* -------------------------------------------- */ + static async addInitiativeTokenTip(html, token ) { + // Helper actor and sanity check + let actor = token.actor; + if (actor === undefined) return; + + // Get combatant stuff + let combatant = game.combat.data.combatants.find(c => c.tokenId == token.data._id ); + if ( combatant ) { + console.log("Token !!!", combatant); + // Create space for Hud Extensions next to combat icon + let divTokenHudExt = '