diff --git a/module/rdd-roll-resolution-table.js b/module/rdd-roll-resolution-table.js index 6603babc..e988da68 100644 --- a/module/rdd-roll-resolution-table.js +++ b/module/rdd-roll-resolution-table.js @@ -70,44 +70,44 @@ export class RdDRollResolutionTable extends Dialog { this.bringToTop(); - var rollData = this.rollData; var dialog = this; - function updateRollResult(rollData) { - rollData.caracValue = parseInt(rollData.selectedCarac.value) - rollData.finalLevel = dialog._computeFinalLevel(rollData); - - // Mise à jour valeurs - $("#carac").val(rollData.caracValue); - $("#roll-param").text(rollData.selectedCarac.value + " / " + Misc.toSignedString(rollData.finalLevel)); - $(".table-resolution").remove(); - $("#resolutionTable").append(RdDResolutionTable.buildHTMLTable(rollData.caracValue, rollData.finalLevel, 1, 20, -10, 10)); - $(".table-proba-reussite").remove(); - $("#tableProbaReussite").append(RdDResolutionTable.buildHTMLResults(rollData.caracValue, rollData.finalLevel)); - } - // Setup everything onload - $(function () { - $("#diffLibre").val(Misc.toInt(rollData.diffLibre)); - $("#diffConditions").val(Misc.toInt(rollData.diffConditions)); - updateRollResult(rollData); - }); - + function onLoad(){ + $("#diffLibre").val(Misc.toInt(dialog.rollData.diffLibre)); + $("#diffConditions").val(Misc.toInt(dialog.rollData.diffConditions)); + dialog.updateRollResult(); + } + $(function () { onLoad();}); + // Update ! html.find('#diffLibre').change((event) => { - rollData.diffLibre = Misc.toInt(event.currentTarget.value); - updateRollResult(rollData); + this.rollData.diffLibre = Misc.toInt(event.currentTarget.value); + this.updateRollResult(); }); html.find('#diffConditions').change((event) => { rollData.diffConditions = Misc.toInt(event.currentTarget.value); - updateRollResult(rollData); + this.updateRollResult(); }); html.find('#carac').change((event) => { let caracKey = event.currentTarget.value; - this.rollData.selectedCarac = rollData.carac[caracKey]; - updateRollResult(rollData); + this.rollData.selectedCarac = this.rollData.carac[caracKey]; + this.updateRollResult(); }); } + async updateRollResult() { + let rollData = this.rollData; + rollData.caracValue = parseInt(rollData.selectedCarac.value) + rollData.finalLevel = this._computeFinalLevel(rollData); + + // Mise à jour valeurs + $("#carac").val(rollData.caracValue); + $("#roll-param").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)); + } /* -------------------------------------------- */ _computeFinalLevel(rollData) { diff --git a/templates/dialog-roll-resolution.html b/templates/dialog-roll-resolution.html index 34feacf4..cd6a5a3f 100644 --- a/templates/dialog-roll-resolution.html +++ b/templates/dialog-roll-resolution.html @@ -28,8 +28,6 @@ {{/select}} -
-