From f02959adee45c981e557e134489aa85db7908044 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Wed, 7 Dec 2022 14:21:48 +0100 Subject: [PATCH] Cleanup Construction du message de jet de constitution par template hbs --- module/actor.js | 11 +++++++---- module/rdd-resolution-table.js | 11 ----------- module/rdd-utility.js | 1 + templates/roll/explain.hbs | 11 +++++++++++ 4 files changed, 19 insertions(+), 15 deletions(-) create mode 100644 templates/roll/explain.hbs diff --git a/module/actor.js b/module/actor.js index 8d335b59..5975448c 100644 --- a/module/actor.js +++ b/module/actor.js @@ -590,11 +590,14 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async _jetRecuperationConstitution(bonusSoins, message = undefined) { - const tData = this.system; - let difficulte = Misc.toInt(bonusSoins) + Math.min(0, tData.sante.vie.value - tData.sante.vie.max); - let rolled = await RdDResolutionTable.roll(tData.carac.constitution.value, difficulte); + let difficulte = Misc.toInt(bonusSoins) + Math.min(0, this.system.sante.vie.value - this.system.sante.vie.max); + let rolled = await RdDResolutionTable.roll(this.system.carac.constitution.value, difficulte); if (message) { - message.content += RdDResolutionTable.explain(rolled).replace(/Jet :/, "Constitution :"); + message.content = await renderTemplate("systems/foundryvtt-reve-de-dragon/templates/roll/explain.hbs", { + actor: this, + carac: this.system.carac.constitution, + rolled + }) } return rolled; } diff --git a/module/rdd-resolution-table.js b/module/rdd-resolution-table.js index c52d2a19..fd2e482a 100644 --- a/module/rdd-resolution-table.js +++ b/module/rdd-resolution-table.js @@ -89,17 +89,6 @@ export class RdDResolutionTable { return resultat; } - /* -------------------------------------------- */ - static explain(rolled) { - let message = "
Jet : " + rolled.roll + " sur " + rolled.score + "% "; - if (rolled.caracValue != undefined && rolled.finalLevel != undefined) { - message += (rolled.diviseurSignificative > 1 ? `(1/${rolled.diviseurSignificative} de ` : "(") - + rolled.caracValue + " à " + Misc.toSignedString(rolled.finalLevel) + ") "; - } - message += '' + rolled.quality + '' - return message; - } - /* -------------------------------------------- */ static async displayRollData(rollData, actor = undefined, template = 'chat-resultat-general.html') { return await ChatUtility.createChatWithRollMode(actor?.userName ?? game.user.name, { diff --git a/module/rdd-utility.js b/module/rdd-utility.js index f72650db..ecd8a843 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -238,6 +238,7 @@ export class RdDUtility { 'systems/foundryvtt-reve-de-dragon/templates/partial-item-hautrevant.html', 'systems/foundryvtt-reve-de-dragon/templates/partial-item-frequence.html', 'systems/foundryvtt-reve-de-dragon/templates/partial-item-description.html', + 'systems/foundryvtt-reve-de-dragon/templates/roll/explain.hbs', 'systems/foundryvtt-reve-de-dragon/templates/resolution-table.html', // Dialogs 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-resolution.html', diff --git a/templates/roll/explain.hbs b/templates/roll/explain.hbs new file mode 100644 index 00000000..c7ee3fee --- /dev/null +++ b/templates/roll/explain.hbs @@ -0,0 +1,11 @@ +{{actor.name}} +

Jet de {{carac.label}} à {{rolled.finalLevel}}: + + {{rolled.roll}} + sur {{rolled.score}}% +{{#if (and rolled.caracValue rolled.finalLevel)}} +({{#if (gt rolled.diviseurSignificative 1)}}1/{{rolled.diviseurSignificative}}{{/if}} + de {{rolled.caracValue}} à {{numberFormat rolled.finalLevel decimals=0 sign=true}}) +{{/if}} +{{rolled.quality}} +