From 2122a54db7858ae1cc9fce351f543691e8e989f5 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Tue, 6 Dec 2022 01:30:12 +0100 Subject: [PATCH 1/5] Cleanup roll windows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - permettre plusieurs fenêtres de jets en même temps en éliminant les id dans le html et les jquery sur id pour éviter les interactions - génération de la table par handlebars --- module/actor.js | 11 - module/dialog-fabriquer-potion.js | 4 +- module/dialog-validation-encaissement.js | 2 +- module/rdd-astrologie-editeur.js | 2 +- module/rdd-astrologie-joueur.js | 8 +- module/rdd-resolution-table.js | 216 ++++++++---------- module/rdd-roll-encaisser.js | 2 +- module/rdd-roll-ethylisme.js | 10 +- module/rdd-roll-resolution-table.js | 63 +++-- module/rdd-roll.js | 142 +++++------- module/rdd-utility.js | 4 + styles/simple.css | 8 +- templates/actor/header-compteurs.html | 4 +- templates/dialog-astrologie-joueur.html | 2 +- templates/dialog-fabriquer-potion-base.html | 2 +- templates/dialog-item-achat.html | 2 +- templates/dialog-item-consommer.html | 2 +- templates/dialog-item-split.html | 2 +- templates/dialog-item-vente.html | 2 +- templates/dialog-roll-alchimie.html | 8 +- templates/dialog-roll-carac.html | 6 +- templates/dialog-roll-chant.html | 7 +- templates/dialog-roll-competence.html | 7 +- templates/dialog-roll-danse.html | 5 +- templates/dialog-roll-defense-possession.html | 5 +- templates/dialog-roll-ethylisme.html | 8 +- templates/dialog-roll-jeu.html | 7 +- templates/dialog-roll-maitrise-tmr.html | 5 +- templates/dialog-roll-meditation.html | 13 +- templates/dialog-roll-musique.html | 7 +- templates/dialog-roll-oeuvre.html | 7 +- templates/dialog-roll-recettecuisine.html | 7 +- templates/dialog-roll-resolution.html | 5 +- templates/dialog-roll-reve-de-dragon.html | 5 +- templates/dialog-roll-signedraconique.html | 5 +- templates/dialog-roll-sort.html | 9 +- templates/item-tache-sheet.html | 4 +- templates/partial-roll-ajustements.html | 2 +- templates/partial-roll-diffCondition.html | 2 +- templates/partial-roll-diffLibre.html | 2 +- templates/partial-roll-forcer.html | 2 +- templates/partial-select-carac.html | 2 +- templates/resolution-table.html | 44 ++++ 43 files changed, 319 insertions(+), 343 deletions(-) create mode 100644 templates/resolution-table.html diff --git a/module/actor.js b/module/actor.js index f8c6ea1c..3ff85b7a 100644 --- a/module/actor.js +++ b/module/actor.js @@ -150,17 +150,6 @@ export class RdDActor extends Actor { this.computeEtatGeneral(); } - /* -------------------------------------------- */ - setRollWindowsOpened(flag) { - // TODO: résoudre le souci lié aux ids dans les fenêtres roll - this.rollWindowsOpened = flag; - } - - /* -------------------------------------------- */ - isRollWindowsOpened() { - return this.rollWindowsOpened; - } - /* -------------------------------------------- */ _prepareCreatureData(actorData) { this.computeEncombrementTotalEtMalusArmure(); diff --git a/module/dialog-fabriquer-potion.js b/module/dialog-fabriquer-potion.js index a8571c5a..a9e552b5 100644 --- a/module/dialog-fabriquer-potion.js +++ b/module/dialog-fabriquer-potion.js @@ -73,7 +73,7 @@ export class DialogFabriquerPotion extends Dialog { activateListeners(html) { super.activateListeners(html); - html.find("#nbBrins").change(event => { + html.find("[name='nbBrins']").change(event => { this.potionData.nbBrins = Misc.toInt(event.currentTarget.value); const brinsManquants = Math.max(0, DialogFabriquerPotion.nombreBrinsOptimal(this.potionData) - this.potionData.nbBrins); this.potionData.herbebonus = Math.max(0, this.potionData.system.niveau - brinsManquants) @@ -82,7 +82,7 @@ export class DialogFabriquerPotion extends Dialog { /* -------------------------------------------- */ async onFabriquer(it) { - await $("#nbBrins").change(); + await $("[name='nbBrins']").change(); this.actor.fabriquerPotion(this.potionData); this.close(); } diff --git a/module/dialog-validation-encaissement.js b/module/dialog-validation-encaissement.js index addcf45c..034b9502 100644 --- a/module/dialog-validation-encaissement.js +++ b/module/dialog-validation-encaissement.js @@ -35,7 +35,7 @@ export class DialogValidationEncaissement extends Dialog { } let dialogOptions = { - classes: ["rdddialog"], + classes: ["rdd-roll-dialog"], width: 350, height: 290 } diff --git a/module/rdd-astrologie-editeur.js b/module/rdd-astrologie-editeur.js index 75913483..13582a27 100644 --- a/module/rdd-astrologie-editeur.js +++ b/module/rdd-astrologie-editeur.js @@ -15,7 +15,7 @@ // Common conf let dialogConf = { content: html, title: "Editeur d'Astrologie", buttons: myButtons, default: "saveButton" }; - let dialogOptions = { classes: ["rdddialog"], width: 600, height: 300, 'z-index': 99999 } + let dialogOptions = { classes: ["rdd-roll-dialog"], width: 600, height: 300, 'z-index': 99999 } super(dialogConf, dialogOptions) this.calendrier = calendrier; diff --git a/module/rdd-astrologie-joueur.js b/module/rdd-astrologie-joueur.js index 5c520d6a..0a604d0a 100644 --- a/module/rdd-astrologie-joueur.js +++ b/module/rdd-astrologie-joueur.js @@ -20,7 +20,7 @@ export class RdDAstrologieJoueur extends Dialog { astrologie: RdDItemCompetence.findCompetence(actor.items, 'Astrologie') } const html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-astrologie-joueur.html', dialogData); - let options = { classes: ["rdddialog"], width: 600, height: 500, 'z-index': 99999 }; + let options = { classes: ["rdd-roll-dialog"], width: 600, height: 500, 'z-index': 99999 }; if (dialogConfig.options) { mergeObject(options, dialogConfig.options, { overwrite: true }); } @@ -37,7 +37,7 @@ export class RdDAstrologieJoueur extends Dialog { // Get all n // Common conf let dialogConf = { content: html, title: "Nombres Astraux", buttons: myButtons, default: "saveButton" }; - let dialogOptions = { classes: ["rdddialog"], width: 600, height: 300, 'z-index': 99999 }; + let dialogOptions = { classes: ["rdd-roll-dialog"], width: 600, height: 300, 'z-index': 99999 }; super(dialogConf, dialogOptions); this.actor = actor; @@ -68,7 +68,7 @@ export class RdDAstrologieJoueur extends Dialog { carac_vue: this.actor.system.carac['vue'].value, etat: this.dataNombreAstral.etat, astrologie: this.dataNombreAstral.astrologie, - conditions: $("#diffConditions").val(), + conditions: $("[name='diffConditions']").val(), date: $("#joursAstrologie").val(), userId: game.user.id } @@ -92,7 +92,7 @@ export class RdDAstrologieJoueur extends Dialog { super.activateListeners(html); $(function () { - $("#diffConditions").val(0); + $("[name='diffConditions']").val(0); }); html.find('#jet-astrologie').click((event) => { diff --git a/module/rdd-resolution-table.js b/module/rdd-resolution-table.js index c6d67bf3..c52d2a19 100644 --- a/module/rdd-resolution-table.js +++ b/module/rdd-resolution-table.js @@ -14,7 +14,7 @@ const levelDown = [ { level: -15, score: 1, norm: 1, sign: 0, part: 0, epart: 2, etotal: 10 }, { level: -16, score: 1, norm: 1, sign: 0, part: 0, epart: 0, etotal: 2 } ]; -const levelImpossible = { score: 0, norm:0, sign: 0, part: 0, epart: 0, etotal: 1 }; +const levelImpossible = { score: 0, norm: 0, sign: 0, part: 0, epart: 0, etotal: 1 }; const reussites = [ { code: "etotal", isPart: false, isSign: false, isSuccess: false, isEchec: true, isEPart: true, isETotal: true, ptTache: -4, ptQualite: -6, quality: "Echec total", condition: (target, roll) => roll >= target.etotal && roll <= 100 }, @@ -42,6 +42,44 @@ export class RdDResolutionTable { return table; } + /* -------------------------------------------- */ + static computeChances(carac, level) { + if (level < -16) { + return levelImpossible; + } + if (level < -10) { + return levelDown.find(it => it.level == level); + } + const percentage = RdDResolutionTable.computePercentage(carac, level); + return this._computeCell(level, percentage); + } + + + /* -------------------------------------------- */ + static _computeRow(caracValue) { + let dataRow = [ + this._computeCell(-10, Math.max(Math.floor(caracValue / 4), 1)), + this._computeCell(-9, Math.max(Math.floor(caracValue / 2), 1)) + ] + for (var diff = -8; diff <= 22; diff++) { + dataRow[diff + 10] = this._computeCell(diff, RdDResolutionTable.computePercentage(caracValue, diff)); + } + return dataRow; + } + + /* -------------------------------------------- */ + static _computeCell(niveau, percentage) { + return { + niveau: niveau, + score: percentage, + norm: Math.min(99, percentage), + sign: this._reussiteSignificative(percentage), + part: this._reussitePart(percentage), + epart: this._echecParticulier(percentage), + etotal: this._echecTotal(percentage) + }; + } + /* -------------------------------------------- */ static getResultat(code) { let resultat = reussites.find(r => code == r.code); @@ -82,8 +120,8 @@ export class RdDResolutionTable { } /* -------------------------------------------- */ - static async roll(caracValue, finalLevel, rollData = {}){ - let chances = this.computeChances(caracValue, finalLevel); + static async roll(caracValue, finalLevel, rollData = {}) { + let chances = duplicate(this.computeChances(caracValue, finalLevel)); this._updateChancesWithBonus(chances, rollData.bonus, finalLevel); this._updateChancesFactor(chances, rollData.diviseurSignificative); chances.showDice = rollData.showDice; @@ -95,7 +133,7 @@ export class RdDResolutionTable { rolled.bonus = rollData.bonus; rolled.factorHtml = Misc.getFractionHtml(rollData.diviseurSignificative); - if (ReglesOptionelles.isUsing("afficher-colonnes-reussite")){ + if (ReglesOptionelles.isUsing("afficher-colonnes-reussite")) { rolled.niveauNecessaire = this.findNiveauNecessaire(caracValue, rolled.roll); rolled.ajustementNecessaire = rolled.niveauNecessaire - finalLevel; } @@ -103,13 +141,24 @@ export class RdDResolutionTable { } /* -------------------------------------------- */ - static findNiveauNecessaire(caracValue, rollValue) { - for (let cell of this.resolutionTable[caracValue]) { - if ( rollValue <= cell.norm) { - return cell.niveau; - } + static findNiveauNecessaire(carac, rolled) { + if (carac == 0) { + return NaN; } - return 16; // Dummy default + if (rolled >= carac){ + const upper = Math.ceil(rolled/carac); + return 2*upper -10 + } + if (rolled > Math.floor(carac/2)) { + return -8 + } + if (rolled > Math.floor(carac/4)) { + return -9 + } + if (rolled > 1) { + return -10 + } + return -11; } /* -------------------------------------------- */ @@ -122,7 +171,7 @@ export class RdDResolutionTable { /* -------------------------------------------- */ static _updateChancesWithBonus(chances, bonus, finalLevel) { - if (bonus && finalLevel>-11) { + if (bonus && finalLevel > -11) { let newScore = Number(chances.score) + bonus; mergeObject(chances, this._computeCell(undefined, newScore), { overwrite: true }); } @@ -142,21 +191,19 @@ export class RdDResolutionTable { /* -------------------------------------------- */ static async rollChances(chances, diviseur, forceDiceResult = -1) { - chances.forceDiceResult = forceDiceResult <= 0 || forceDiceResult > 100 ? undefined : {total: forceDiceResult}; - chances.roll = await RdDDice.rollTotal( "1d100", chances); + chances.forceDiceResult = forceDiceResult <= 0 || forceDiceResult > 100 ? undefined : { total: forceDiceResult }; + chances.roll = await RdDDice.rollTotal("1d100", chances); mergeObject(chances, this.computeReussite(chances, chances.roll, diviseur), { overwrite: true }); return chances; } /* -------------------------------------------- */ - static computeChances(caracValue, difficulte) { - if (difficulte < -16) { - return duplicate(levelImpossible); - } - if (difficulte < -10) { - return duplicate(levelDown.find(levelData => levelData.level == difficulte)); - } - return duplicate(RdDResolutionTable.resolutionTable[caracValue][difficulte + 10]); + static computePercentage(carac, diff) { + if (diff < -16) return 0 + if (diff < -10) return 1 + if (diff == -10) return Math.max(Math.floor(carac / 4), 1) + if (diff == -9) return Math.max(Math.floor(carac / 2), 1) + return Math.max(Math.floor(carac * (diff + 10) / 2), 1); } /* -------------------------------------------- */ @@ -213,31 +260,6 @@ export class RdDResolutionTable { return reussite; } - /* -------------------------------------------- */ - static _computeRow(caracValue) { - let dataRow = [ - this._computeCell(-10, Math.max(Math.floor(caracValue / 4), 1)), - this._computeCell(-9, Math.max(Math.floor(caracValue / 2), 1)) - ] - for (var diff = -8; diff <= 22; diff++) { - dataRow[diff + 10] = this._computeCell(diff, Math.max(Math.floor(caracValue * (diff + 10) / 2), 1)); - } - return dataRow; - } - - /* -------------------------------------------- */ - static _computeCell(niveau, percentage) { - return { - niveau: niveau, - score: percentage, - norm: Math.min(99, percentage), - sign: this._reussiteSignificative(percentage), - part: this._reussitePart(percentage), - epart: this._echecParticulier(percentage), - etotal: this._echecTotal(percentage) - }; - } - /* -------------------------------------------- */ static _reussiteSignificative(percentage) { return Math.floor(percentage / 2); @@ -261,92 +283,34 @@ export class RdDResolutionTable { } /* -------------------------------------------- */ - static buildHTMLResults(caracValue, levelValue) { - if (caracValue == undefined || isNaN(caracValue)) caracValue = 10; - if (levelValue == undefined || isNaN(levelValue)) levelValue = 0; - - let cell = this.computeChances(caracValue, levelValue); - cell.epart = cell.epart > 99 ? 'N/A' : cell.epart; - cell.etotal = cell.etotal > 100 ? 'N/A' : cell.etotal; - cell.score = Math.min(cell.score, 99); - - return ` - - Particulière: ${cell.part} - - Significative: ${cell.sign} - - Réussite: ${cell.score} - - Echec Particulier: ${cell.epart} - - Echec Total: ${cell.etotal} - - ` + static subTable(carac, level, delta = { carac: 2, level: 5}) { + return { + carac, + level, + minCarac: carac - (delta?.carac ?? 2), + maxCarac: carac + (delta?.carac ?? 2), + minLevel: level - (delta?.level ?? 5), + maxLevel: level + (delta?.level ?? 5) + }; } /* -------------------------------------------- */ - static buildHTMLTableExtract(caracValue, levelValue) { - return this.buildHTMLTable(caracValue, levelValue, caracValue - 2, caracValue + 2, levelValue - 5, levelValue + 5) - } - - static buildHTMLTable(caracValue, levelValue, minCarac = 1, maxCarac = 21, minLevel = -10, maxLevel = 11) { - return this._buildHTMLTable(caracValue, levelValue, minCarac, maxCarac, minLevel, maxLevel) - } - - /* -------------------------------------------- */ - static _buildHTMLTable(caracValue, levelValue, minCarac, maxCarac, minLevel, maxLevel) { - let countColonnes = maxLevel - minLevel; + static async buildHTMLTable({ carac: carac, level: level, minCarac = 1, maxCarac = 21, minLevel = -10, maxLevel = 11 }) { + let colonnes = maxLevel - minLevel; minCarac = Math.max(minCarac, 1); - maxCarac = Math.min(maxCarac, caracMaximumResolution); + maxCarac = Math.min(maxCarac, minCarac + 20); minLevel = Math.max(minLevel, -10); - maxLevel = Math.max(Math.min(maxLevel, 22), minLevel + countColonnes); - - let table = $("") - .append(this._buildHTMLHeader(RdDResolutionTable.resolutionTable[0], minLevel, maxLevel)); - - for (var rowIndex = minCarac; rowIndex <= maxCarac; rowIndex++) { - table.append(this._buildHTMLRow(RdDResolutionTable.resolutionTable[rowIndex], rowIndex, caracValue, levelValue, minLevel, maxLevel)); - } - table.append("
"); - return table; + maxLevel = Math.max(Math.min(maxLevel, 30), minLevel + colonnes); + return await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/resolution-table.html', { + carac: carac, + difficulte: level, + min: minLevel, + rows: RdDResolutionTable.incrementalArray(minCarac, maxCarac), + cols: RdDResolutionTable.incrementalArray(minLevel, maxLevel) + }); } - - /* -------------------------------------------- */ - static _buildHTMLHeader(dataRow, minLevel, maxLevel) { - let tr = $(""); - - if (minLevel > -8) { - tr.append($("").text("-8")) - } - if (minLevel > -7) { - tr.append($("").text("...")); - } - for (let difficulte = minLevel; difficulte <= maxLevel; difficulte++) { - tr.append($("").text(Misc.toSignedString(difficulte))); - } - return tr; - } - - /* -------------------------------------------- */ - static _buildHTMLRow(dataRow, rowIndex, caracValue, levelValue, minLevel, maxLevel) { - let tr = $(""); - let max = maxLevel; - - if (minLevel > -8) { - let score = dataRow[-8 + 10].score; - tr.append($("").text(score)) - } - if (minLevel > -7) { - tr.append($("")) - } - for (let difficulte = minLevel; difficulte <= max; difficulte++) { - let td = $(""); - let score = dataRow[difficulte + 10].score; - if (rowIndex == caracValue && levelValue == difficulte) { - td.addClass('table-resolution-target'); - } else if (difficulte == -8) { - td.addClass('table-resolution-carac'); - } - tr.append(td.text(score)); - } - return tr; + static incrementalArray(min, max) { + return Array.from(Array(max-min+1).keys()).map(i=>i+min) } } \ No newline at end of file diff --git a/module/rdd-roll-encaisser.js b/module/rdd-roll-encaisser.js index a109b35d..1968d744 100644 --- a/module/rdd-roll-encaisser.js +++ b/module/rdd-roll-encaisser.js @@ -31,7 +31,7 @@ export class RdDEncaisser extends Dialog { } let dialogOptions = { - classes: ["rdddialog"], + classes: ["rdd-roll-dialog"], width: 320, height: 'fit-content' } diff --git a/module/rdd-roll-ethylisme.js b/module/rdd-roll-ethylisme.js index ce7580d4..157ecaec 100644 --- a/module/rdd-roll-ethylisme.js +++ b/module/rdd-roll-ethylisme.js @@ -15,7 +15,7 @@ export class RdDRollDialogEthylisme extends Dialog { default: "rollButton", buttons: { "rollButton": { label: "Test d'éthylisme", callback: html => this.onButton(html) } } }; - let dialogOptions = { classes: ["rdddialog"], width: 400, height: 'fit-content', 'z-index': 99999 } + let dialogOptions = { classes: ["rdd-roll-dialog"], width: 400, height: 'fit-content', 'z-index': 99999 } super(dialogConf, dialogOptions) //console.log("ETH", rollData); @@ -39,20 +39,20 @@ export class RdDRollDialogEthylisme extends Dialog { // Setup everything onload $(function () { - $("#forceAlcool").val(Misc.toInt(rollData.forceAlcool)); + html.find(".force-alcool").val(Misc.toInt(rollData.forceAlcool)); dialog.updateRollResult(); }); // Update ! - html.find('#forceAlcool').change((event) => { - rollData.forceAlcool = Misc.toInt(event.currentTarget.value); // Update the selected bonus/malus + html.find(".force-alcool").change((event) => { + rollData.forceAlcool = Misc.toInt(event.currentTarget.value); dialog.updateRollResult(); }); } async updateRollResult() { // Mise à jour valeurs - $("#roll-param").text(this.rollData.vie + " / " + Misc.toSignedString(Number(this.rollData.etat) + Number(this.rollData.forceAlcool) + this.rollData.diffNbDoses)); + $(".roll-ethylisme").text(this.rollData.vie + " / " + Misc.toSignedString(Number(this.rollData.etat) + Number(this.rollData.forceAlcool) + this.rollData.diffNbDoses)); $(".table-resolution").remove(); } diff --git a/module/rdd-roll-resolution-table.js b/module/rdd-roll-resolution-table.js index f276ede4..5b44778f 100644 --- a/module/rdd-roll-resolution-table.js +++ b/module/rdd-roll-resolution-table.js @@ -9,12 +9,19 @@ const titleTableDeResolution = 'Table de résolution'; /* -------------------------------------------- */ export class RdDRollResolutionTable extends Dialog { + static resolutionTable = undefined; /* -------------------------------------------- */ - static async open(rollData = {}) { - RdDRollResolutionTable._setDefaultOptions(rollData); - let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-roll-resolution.html', rollData); - const dialog = new RdDRollResolutionTable(rollData, html); - dialog.render(true); + static async open() { + if (RdDRollResolutionTable.resolutionTable == undefined) { + const rollData = {} + RdDRollResolutionTable._setDefaultOptions(rollData); + let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-roll-resolution.html', rollData); + RdDRollResolutionTable.resolutionTable = new RdDRollResolutionTable(rollData, html); + RdDRollResolutionTable.resolutionTable.render(true); + } + else{ + RdDRollResolutionTable.resolutionTable.bringToTop(); + } } /* -------------------------------------------- */ @@ -53,7 +60,7 @@ export class RdDRollResolutionTable extends Dialog { 'lancer-fermer': { label: 'Lancer les dés et fermer', callback: html => this.onLancerFermer() } } }; - super(conf, { classes: ["rdddialog"], width: 800, height: 'fit-content', 'z-index': 99999 }); + super(conf, { classes: ["rdd-roll-dialog"], top: 50, width: 'fit-content', height: 'fit-content', 'z-index': 99999 }); this.rollData = rollData; } @@ -82,55 +89,61 @@ export class RdDRollResolutionTable extends Dialog { // Setup everything onload function onLoad(){ - $("#diffLibre").val(Misc.toInt(dialog.rollData.diffLibre)); - $("#diffConditions").val(Misc.toInt(dialog.rollData.diffConditions)); - dialog.updateRollResult(); + $("[name='diffLibre']").val(Misc.toInt(dialog.rollData.diffLibre)); + $("[name='diffConditions']").val(Misc.toInt(dialog.rollData.diffConditions)); + dialog.updateRollResult(html); } $(function () { onLoad();}); - html.find('#lancer').click((event) => { + html.find('.lancer-table-resolution').click((event) => { this.onLancer(); }); // Update ! - html.find('#diffLibre').change((event) => { + html.find("[name='diffLibre']").change((event) => { this.rollData.diffLibre = Misc.toInt(event.currentTarget.value); - this.updateRollResult(); + this.updateRollResult(html); }); - html.find('#diffConditions').change((event) => { + html.find("[name='diffConditions']").change((event) => { this.rollData.diffConditions = Misc.toInt(event.currentTarget.value); - this.updateRollResult(); + this.updateRollResult(html); }); - html.find('#carac').change((event) => { + html.find("[name='carac']").change((event) => { let caracKey = event.currentTarget.value; this.rollData.selectedCarac = this.rollData.carac[caracKey]; - this.updateRollResult(); + this.updateRollResult(html); }); } /* -------------------------------------------- */ - async updateRollResult() { + async updateRollResult(html) { let rollData = this.rollData; rollData.caracValue = parseInt(rollData.selectedCarac.value) rollData.finalLevel = this._computeFinalLevel(rollData); + const htmlTable = await RdDResolutionTable.buildHTMLTable({ + carac:rollData.caracValue, + level: rollData.finalLevel + }); + // Mise à jour valeurs - $("#carac").val(rollData.caracValue); - $("#roll-param").text(rollData.selectedCarac.value + " / " + Misc.toSignedString(rollData.finalLevel)); + html.find("[name='carac']").val(rollData.caracValue); + $(".roll-param-resolution").text(rollData.selectedCarac.value + " / " + Misc.toSignedString(rollData.finalLevel)); $(".table-resolution").remove(); $(".table-proba-reussite").remove(); - $("#tableResolution").append(RdDResolutionTable.buildHTMLTable(rollData.caracValue, rollData.finalLevel)); - $("#tableProbaReussite").append(RdDResolutionTable.buildHTMLResults(rollData.caracValue, rollData.finalLevel)); + + html.find("div.placeholder-resolution").append(htmlTable) + } /* -------------------------------------------- */ _computeFinalLevel(rollData) { const diffConditions = Misc.toInt(rollData.diffConditions); - const diffLibre = this._computeDiffLibre(rollData); + const diffLibre = Misc.toInt(rollData.diffLibre); return diffLibre + diffConditions; } - /* -------------------------------------------- */ - _computeDiffLibre(rollData) { - return Misc.toInt(rollData.diffLibre); + async close() { + await super.close(); + RdDRollResolutionTable.resolutionTable = undefined; } } diff --git a/module/rdd-roll.js b/module/rdd-roll.js index a8253ad6..8c7a8e17 100644 --- a/module/rdd-roll.js +++ b/module/rdd-roll.js @@ -17,23 +17,16 @@ export class RdDRoll extends Dialog { /* -------------------------------------------- */ static async create(actor, rollData, dialogConfig, ...actions) { - - if (actor.isRollWindowsOpened()) { - ui.notifications.warn("Vous avez déja une fenêtre de Test ouverte, il faut la fermer avant d'en ouvrir une autre.") - return; - } - actor.setRollWindowsOpened(true); - RdDRoll._ensureCorrectActions(actions); RdDRoll._setDefaultOptions(actor, rollData); const html = await renderTemplate(dialogConfig.html, rollData); - let options = { classes: ["rdddialog"], width: 600, height: 'fit-content', 'z-index': 99999 }; + let options = { classes: [ "rdd-roll-dialog"], width: 600, height: 'fit-content', 'z-index': 99999 }; if (dialogConfig.options) { mergeObject(options, dialogConfig.options, { overwrite: true }) } - return new RdDRoll(actor, rollData, html, options, actions, dialogConfig.close); + return new RdDRoll(actor, rollData, html, options, actions); } /* -------------------------------------------- */ @@ -97,7 +90,6 @@ export class RdDRoll extends Dialog { return facteurSign; } - /* -------------------------------------------- */ static _ensureCorrectActions(actions) { if (actions.length == 0) { @@ -111,13 +103,13 @@ export class RdDRoll extends Dialog { } /* -------------------------------------------- */ - constructor(actor, rollData, html, options, actions, close = undefined) { + constructor(actor, rollData, html, options, actions) { let conf = { title: actions[0].label, content: html, buttons: {}, default: actions[0].name, - close: close + close: options.close }; for (let action of actions) { conf.buttons[action.name] = { @@ -136,7 +128,6 @@ export class RdDRoll extends Dialog { close() { if (this.rollData.canClose) { - this.actor.setRollWindowsOpened(false); return super.close(); } ui.notifications.info("Vous devez faire ce jet de dés!"); @@ -145,10 +136,9 @@ export class RdDRoll extends Dialog { /* -------------------------------------------- */ async onAction(action, html) { - this.rollData.forceDiceResult = Number.parseInt($('#force-dice-result').val()) ?? -1; + this.rollData.forceDiceResult = Number.parseInt(html.find("[name='force-dice-result']").val()) ?? -1; await RdDResolutionTable.rollData(this.rollData); console.log("RdDRoll -=>", this.rollData, this.rollData.rolled); - this.actor.setRollWindowsOpened(false); if (action.callbacks) for (let callback of action.callbacks) { if (callback.condition == undefined || callback.condition(this.rollData)) { @@ -173,90 +163,90 @@ export class RdDRoll extends Dialog { const defaut_carac = rollData.competence.system.defaut_carac // Set the default carac from the competence item rollData.selectedCarac = rollData.carac[defaut_carac]; - $("#carac").val(defaut_carac); + html.find("[name='carac']").val(defaut_carac); } if (rollData.selectedSort) { - dialog.setSelectedSort(rollData.selectedSort); - $(".draconic").val(rollData.selectedSort.system.listIndex); // Uniquement a la selection du sort, pour permettre de changer + dialog.setSelectedSort(rollData.selectedSort, html); + html.find(".draconic").val(rollData.selectedSort.system.listIndex); // Uniquement a la selection du sort, pour permettre de changer } RdDItemSort.setCoutReveReel(rollData.selectedSort); - $("#diffLibre").val(Misc.toInt(rollData.diffLibre)); - $("#diffConditions").val(Misc.toInt(rollData.diffConditions)); - dialog.updateRollResult(); + html.find("[name='diffLibre']").val(Misc.toInt(rollData.diffLibre)); + html.find("[name='diffConditions']").val(Misc.toInt(rollData.diffConditions)); + dialog.updateRollResult(html); } // Setup everything onload $(function () { onLoad(); }); // Update ! - html.find('#diffLibre').change((event) => { + html.find("[name='diffLibre']").change((event) => { this.rollData.diffLibre = Misc.toInt(event.currentTarget.value); // Update the selected bonus/malus - this.updateRollResult(); + this.updateRollResult(html); }); - html.find('#diffConditions').change((event) => { + html.find("[name='diffConditions']").change((event) => { this.rollData.diffConditions = Misc.toInt(event.currentTarget.value); // Update the selected bonus/malus - this.updateRollResult(); + this.updateRollResult(html); }); - html.find('#force-dice-result').change((event) => { + html.find("[name='force-dice-result']").change((event) => { this.rollData.forceDiceResult = Misc.toInt(event.currentTarget.value); }); - html.find('#carac').change((event) => { + html.find("[name='carac']").change((event) => { let caracKey = event.currentTarget.value; this.rollData.selectedCarac = this.rollData.carac[caracKey]; // Update the selectedCarac - this.updateRollResult(); + this.updateRollResult(html); }); html.find('.roll-draconic').change((event) => { let draconicKey = Misc.toInt(event.currentTarget.value); this.rollData.competence = this.rollData.draconicList[draconicKey]; // Update the selectedCarac - this.updateRollResult(); + this.updateRollResult(html); }); html.find('.roll-sort').change((event) => { let sortKey = Misc.toInt(event.currentTarget.value); - this.setSelectedSort(this.rollData.sortList[sortKey]); - this.updateRollResult(); - $("#diffLibre").val(this.rollData.diffLibre); + this.setSelectedSort(this.rollData.sortList[sortKey], html); + this.updateRollResult(html); + html.find("[name='diffLibre']").val(this.rollData.diffLibre); }); html.find('.roll-carac-competence').change((event) => { const competence = event.currentTarget.value; this.rollData.competence = this.rollData.competences.find(it => it.name == competence); - this.updateRollResult(); + this.updateRollResult(html); }); html.find('.roll-signedraconique').change((event) => { let sortKey = Misc.toInt(event.currentTarget.value); this.setSelectedSigneDraconique(this.rollData.signes[sortKey]); - this.updateRollResult(); + this.updateRollResult(html); }); - html.find('#ptreve-variable').change((event) => { + html.find("[name='ptreve-variable']").change((event) => { let ptreve = Misc.toInt(event.currentTarget.value); this.rollData.selectedSort.system.ptreve_reel = ptreve; console.log("RdDRollSelectDialog - Cout reve", ptreve); - this.updateRollResult(); + this.updateRollResult(html); }); html.find("[name='coupsNonMortels']").change((event) => { this.rollData.dmg.mortalite = event.currentTarget.checked ? "non-mortel" : "mortel"; - this.updateRollResult(); + this.updateRollResult(html); }); html.find('.cuisine-proportions').change((event) => { this.rollData.proportions = Number(event.currentTarget.value); - this.updateRollResult(); + this.updateRollResult(html); }); html.find('.select-by-name').change((event) => { const attribute = event.currentTarget.attributes['name'].value; this.rollData[attribute] = event.currentTarget.value; - this.updateRollResult(); + this.updateRollResult(html); }); html.find('.checkbox-by-name').change((event) => { const attribute = event.currentTarget.attributes['name'].value; this.rollData[attribute] = event.currentTarget.checked; - this.updateRollResult(); + this.updateRollResult(html); }); html.find('input.use-encTotal').change((event) => { this.rollData.use.encTotal = event.currentTarget.checked; - this.updateRollResult(); + this.updateRollResult(html); }); html.find('input.use-surenc').change((event) => { this.rollData.use.surenc = event.currentTarget.checked; - this.updateRollResult(); + this.updateRollResult(html); }); html.find('.appel-moral').click((event) => { /* l'appel au moral, qui donne un bonus de +1 */ this.rollData.use.moral = !this.rollData.use.moral; @@ -274,38 +264,38 @@ export class RdDRoll extends Dialog { tooltip.innerHTML = "Sans appel au moral"; appelMoral.src = "/systems/foundryvtt-reve-de-dragon/icons/moral-neutre.svg"; } - this.updateRollResult(); + this.updateRollResult(html); }); // Section Méditation html.find('.conditionMeditation').change((event) => { - let condition = event.currentTarget.attributes['id'].value; + let condition = event.currentTarget.attributes['name'].value; this.rollData.conditionMeditation[condition] = event.currentTarget.checked; - this.updateRollResult(); + this.updateRollResult(html); }); } - async setSelectedSort(sort) { + async setSelectedSort(sort, html) { this.rollData.selectedSort = sort; // Update the selectedCarac this.rollData.competence = RdDItemCompetence.getVoieDraconic(this.rollData.draconicList, sort.system.draconic); this.rollData.bonus = RdDItemSort.getCaseBonus(sort, this.rollData.tmr.coord); this.rollData.diffLibre = RdDItemSort.getDifficulte(sort, -7); RdDItemSort.setCoutReveReel(sort); const htmlSortDescription = await renderTemplate("systems/foundryvtt-reve-de-dragon/templates/partial-description-sort.html", { sort: sort }); - $(".sort-ou-rituel").text(sort.system.isrituel ? "rituel" : "sort"); - $(".bonus-case").text(`${this.rollData.bonus}%`); - $(".details-sort").remove(); - $(".description-sort").append(htmlSortDescription); - $(".roll-draconic").val(sort.system.listIndex); - $(".div-sort-difficulte-fixe").text(Misc.toSignedString(sort.system.difficulte)); - $(".div-sort-ptreve-fixe").text(sort.system.ptreve); + html.find(".sort-ou-rituel").text(sort.system.isrituel ? "rituel" : "sort"); + html.find(".bonus-case").text(`${this.rollData.bonus}%`); + html.find(".details-sort").remove(); + html.find(".description-sort").append(htmlSortDescription); + html.find(".roll-draconic").val(sort.system.listIndex); + html.find(".div-sort-difficulte-fixe").text(Misc.toSignedString(sort.system.difficulte)); + html.find(".div-sort-ptreve-fixe").text(sort.system.ptreve); const diffVariable = RdDItemSort.isDifficulteVariable(sort); const coutVariable = RdDItemSort.isCoutVariable(sort); - HtmlUtility._showControlWhen($(".div-sort-non-rituel"), !sort.system.isrituel); - HtmlUtility._showControlWhen($(".div-sort-difficulte-var"), diffVariable); - HtmlUtility._showControlWhen($(".div-sort-difficulte-fixe"), !diffVariable); - HtmlUtility._showControlWhen($(".div-sort-ptreve-var"), coutVariable); - HtmlUtility._showControlWhen($(".div-sort-ptreve-fixe"), !coutVariable); + HtmlUtility._showControlWhen(html.find(".div-sort-non-rituel"), !sort.system.isrituel); + HtmlUtility._showControlWhen(html.find(".div-sort-difficulte-var"), diffVariable); + HtmlUtility._showControlWhen(html.find(".div-sort-difficulte-fixe"), !diffVariable); + HtmlUtility._showControlWhen(html.find(".div-sort-ptreve-var"), coutVariable); + HtmlUtility._showControlWhen(html.find(".div-sort-ptreve-fixe"), !coutVariable); } async setSelectedSigneDraconique(signe){ @@ -315,7 +305,7 @@ export class RdDRoll extends Dialog { } /* -------------------------------------------- */ - async updateRollResult() { + async updateRollResult(html) { let rollData = this.rollData; rollData.dmg = rollData.attackerRoll?.dmg ?? RdDBonus.dmg(rollData, this.actor.getBonusDegat()) @@ -333,31 +323,27 @@ export class RdDRoll extends Dialog { RollDataAjustements.calcul(rollData, this.actor); rollData.finalLevel = this._computeFinalLevel(rollData); + const resolutionTable = await RdDResolutionTable.buildHTMLTable(RdDResolutionTable.subTable(rollData.caracValue, rollData.finalLevel)) + const adjustements = await this.buildAjustements(rollData); + HtmlUtility._showControlWhen($(".use-encTotal"), rollData.ajustements.encTotal.visible && RdDCarac.isAgiliteOuDerivee(rollData.selectedCarac)); HtmlUtility._showControlWhen($(".use-surenc"), rollData.ajustements.surenc.visible && RdDCarac.isActionPhysique(rollData.selectedCarac)); HtmlUtility._showControlWhen($(".utilisation-moral"), rollData.use.appelAuMoral); HtmlUtility._showControlWhen($(".diffMoral"), rollData.ajustements.moralTotal.used); HtmlUtility._showControlWhen($(".divAppelAuMoral"), rollData.use.appelAuMoral); - HtmlUtility._showControlWhen($("#etat-general"), !RdDCarac.isIgnoreEtatGeneral(rollData)); - HtmlUtility._showControlWhen($("#ajust-astrologique"), RdDResolutionTable.isAjustementAstrologique(rollData)); // Mise à jour valeurs - $(".dialog-roll-title").text(this._getTitle(rollData)); - $("[name='coupsNonMortels']").prop('checked', rollData.mortalite == 'non-mortel'); - $(".dmg-arme-actor").text(dmgText); - $('.table-ajustement').remove(); - $(".table-resolution").remove(); - $(".table-proba-reussite").remove(); - $("#tableAjustements").append(await this.buildAjustements(rollData)); - $("#tableResolution").append(RdDResolutionTable.buildHTMLTableExtract(rollData.caracValue, rollData.finalLevel)); - $("#tableProbaReussite").append(RdDResolutionTable.buildHTMLResults(rollData.caracValue, rollData.finalLevel)); + html.find(".dialog-roll-title").text(this._getTitle(rollData)); + html.find("[name='coupsNonMortels']").prop('checked', rollData.mortalite == 'non-mortel'); + html.find(".dmg-arme-actor").text(dmgText); + html.find("div.placeholder-ajustements").empty().append(adjustements); + html.find("div.placeholder-resolution").empty().append(resolutionTable) } /* -------------------------------------------- */ async buildAjustements(rollData) { - const html = await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/partial-roll-ajustements.html`, rollData); - return html; + return await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/partial-roll-ajustements.html`, rollData); } /* -------------------------------------------- */ @@ -375,23 +361,11 @@ export class RdDRoll extends Dialog { return 0; } - /* -------------------------------------------- */ - _computeDiffLibre(rollData) { - let diffLibre = Misc.toInt(rollData.diffLibre); - if (rollData.draconicList && rollData.selectedSort) { - return RdDItemSort.getDifficulte(rollData.selectedSort, diffLibre); - } - return diffLibre; - } - /* -------------------------------------------- */ _computeMalusArmure(rollData) { let malusArmureValue = 0; if (rollData.malusArmureValue && (rollData.selectedCarac.label == "Agilité" || rollData.selectedCarac.label == "Dérobée")) { - $("#addon-message").text("Malus armure appliqué : " + rollData.malusArmureValue); malusArmureValue = rollData.malusArmureValue; - } else { - $("#addon-message").text(""); } return malusArmureValue; } diff --git a/module/rdd-utility.js b/module/rdd-utility.js index c86000df..f72650db 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -15,6 +15,7 @@ import { RdDConfirm } from "./rdd-confirm.js"; import { RdDCalendrier } from "./rdd-calendrier.js"; import { Environnement } from "./environnement.js"; import { RdDItemCompetence } from "./item-competence.js"; +import { RdDResolutionTable } from "./rdd-resolution-table.js"; /* -------------------------------------------- */ // This table starts at 0 -> niveau -10 @@ -237,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/resolution-table.html', // Dialogs 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-resolution.html', 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-competence.html', @@ -282,6 +284,8 @@ export class RdDUtility { ]; Handlebars.registerHelper('either', (a, b) => a ?? b); + Handlebars.registerHelper('computeResolutionScore', (row, col) => RdDResolutionTable.computePercentage(row, col)); + Handlebars.registerHelper('computeResolutionChances', (row, col) => RdDResolutionTable.computeChances(row, col)); Handlebars.registerHelper('upperFirst', str => Misc.upperFirst(str ?? 'Null')); Handlebars.registerHelper('lowerFirst', str => Misc.lowerFirst(str ?? 'Null')); Handlebars.registerHelper('upper', str => str?.toUpperCase() ?? 'NULL'); diff --git a/styles/simple.css b/styles/simple.css index 052a4257..7c2b6e42 100644 --- a/styles/simple.css +++ b/styles/simple.css @@ -618,7 +618,7 @@ input:is(.blessure-premiers_soins, .blessure-soins_complets) { opacity: 0.7 ; } -.rdddialog .dialog-roll-sort { +.rdd-roll-dialog .dialog-roll-sort { width: 600px; height: 430px; z-index: 9999; @@ -659,6 +659,10 @@ input:is(.blessure-premiers_soins, .blessure-soins_complets) { text-align: right; } +.placeholder-ajustements { + flex-direction: column; +} + .table-resolution-carac { background-color: yellow; } @@ -668,7 +672,7 @@ input:is(.blessure-premiers_soins, .blessure-soins_complets) { background-color: lightblue; } -#tableProbaReussite{ +div.placeholder-resolution span.table-proba-reussite{ font-size: 0.8rem; padding: 5px; } diff --git a/templates/actor/header-compteurs.html b/templates/actor/header-compteurs.html index 9ff90fee..901dca9b 100644 --- a/templates/actor/header-compteurs.html +++ b/templates/actor/header-compteurs.html @@ -23,7 +23,7 @@ {{{calc.fatigue.html}}} Fatigue - + / {{system.sante.fatigue.max}} @@ -32,7 +32,7 @@ diff --git a/templates/dialog-astrologie-joueur.html b/templates/dialog-astrologie-joueur.html index 3b7d2fad..60f0d40a 100644 --- a/templates/dialog-astrologie-joueur.html +++ b/templates/dialog-astrologie-joueur.html @@ -6,7 +6,7 @@ - {{#select diffConditions}} {{#each ajustementsConditions as |key|}} diff --git a/templates/dialog-fabriquer-potion-base.html b/templates/dialog-fabriquer-potion-base.html index 6ad04035..16af1a07 100644 --- a/templates/dialog-fabriquer-potion-base.html +++ b/templates/dialog-fabriquer-potion-base.html @@ -5,7 +5,7 @@
- {{#select nbBrins}} {{{nbBrinsSelect}}} {{/select}} diff --git a/templates/dialog-item-achat.html b/templates/dialog-item-achat.html index c54eaf55..ade170ef 100644 --- a/templates/dialog-item-achat.html +++ b/templates/dialog-item-achat.html @@ -1,4 +1,4 @@ -
+
diff --git a/templates/dialog-item-consommer.html b/templates/dialog-item-consommer.html index 93744bac..0bbd47fc 100644 --- a/templates/dialog-item-consommer.html +++ b/templates/dialog-item-consommer.html @@ -1,4 +1,4 @@ - + {{item.name}}

{{item.name}}

diff --git a/templates/dialog-item-split.html b/templates/dialog-item-split.html index f09da7e8..0f61fc55 100644 --- a/templates/dialog-item-split.html +++ b/templates/dialog-item-split.html @@ -1,4 +1,4 @@ - + {{item.name}}

{{item.name}}

diff --git a/templates/dialog-item-vente.html b/templates/dialog-item-vente.html index c85235f8..2ba62e3b 100644 --- a/templates/dialog-item-vente.html +++ b/templates/dialog-item-vente.html @@ -1,4 +1,4 @@ - + {{item.name}}

{{item.name}}

diff --git a/templates/dialog-roll-alchimie.html b/templates/dialog-roll-alchimie.html index 7393afd4..2aa5612b 100644 --- a/templates/dialog-roll-alchimie.html +++ b/templates/dialog-roll-alchimie.html @@ -1,4 +1,4 @@ - +

Fabrication: {{recette.name}}

@@ -20,12 +20,12 @@ {{/if}} {{>"systems/foundryvtt-reve-de-dragon/templates/partial-roll-forcer.html"}} {{>"systems/foundryvtt-reve-de-dragon/templates/partial-roll-moral.html"}} -
+
-
-
+
+
\ No newline at end of file diff --git a/templates/item-competence-sheet.html b/templates/item-competence-sheet.html index c53a9274..77b2115b 100644 --- a/templates/item-competence-sheet.html +++ b/templates/item-competence-sheet.html @@ -33,13 +33,13 @@
{{#if isGM}} - {{#select system.base}} {{>"systems/foundryvtt-reve-de-dragon/templates/enum-base-competence.html"}} {{/select}} {{else}} - + {{/if}}
diff --git a/templates/item-potion-sheet.html b/templates/item-potion-sheet.html index f696d0e5..b7ecd665 100644 --- a/templates/item-potion-sheet.html +++ b/templates/item-potion-sheet.html @@ -85,14 +85,14 @@
- {{#select splitDate.day}} {{#each jourMoisOptions as |key|}} {{/each}} {{/select}} - {{#select splitDate.month}} {{>"systems/foundryvtt-reve-de-dragon/templates/enum-heures.html"}} {{/select}} diff --git a/templates/partial-description-sort.html b/templates/partial-description-sort.html index efb6d1ef..ff63cbee 100644 --- a/templates/partial-description-sort.html +++ b/templates/partial-description-sort.html @@ -5,6 +5,6 @@ {{#if sort.system.duree}}{{/if}} {{#if sort.system.coutseuil}}{{/if}}
-
+
{{> "systems/foundryvtt-reve-de-dragon/templates/partial-description-overflow.html" sort.system}}
\ No newline at end of file