Separation difficulte libre/conditions

* ajout de diffConditions pour gérer l'ajustement de conditions
* renommage de bmValue en diffLibre
* calcul de l'ajustement (etat+conditions+difficulté libre)
* présentation des 2 champs

fix:
* utiliser .change() au lieu de .click() permet de supporter aussi
les changements au clavier
This commit is contained in:
2020-11-15 02:07:41 +01:00
parent 5776ae0a20
commit 52caf1b39a
14 changed files with 199 additions and 165 deletions

View File

@ -1,3 +1,4 @@
import { Misc } from "./misc.js";
import { RdDResolutionTable } from "./rdd-resolution-table.js";
/**
@ -38,7 +39,7 @@ export class RdDRollDialog extends Dialog {
dialogOptions.height = 350
} else if (mode == "sort") {
dialogConf.title = "Lancer un sort"
dialogConf.height = 450
dialogConf.height = 470
}
super(dialogConf, dialogOptions)
@ -65,7 +66,6 @@ export class RdDRollDialog extends Dialog {
let rollLevel = RdDRollDialog._computeFinalLevel(rollData);
rollData.finalLevel = rollLevel;
rollData.finalLevelStr = (rollLevel > 0 ? "+" : "") + rollLevel;
rollData.rollTarget = RdDResolutionTable.computeChances(rollData.selectedCarac.value, rollData.finalLevel);
// Sort management
@ -83,7 +83,7 @@ export class RdDRollDialog extends Dialog {
}
}
$("#roll-param").text(rollData.selectedCarac.value + " / " + rollData.finalLevelStr);
$("#roll-param").text(rollData.selectedCarac.value + " / " + Misc.toSignedString(rollData.finalLevel));
$("#compdialogTitle").text(RdDRollDialog._getTitle(rollData));
$(".table-resolution").remove();
$("#resolutionTable").append(RdDResolutionTable.buildHTMLTableExtract(caracValue, rollLevel));
@ -101,36 +101,42 @@ export class RdDRollDialog extends Dialog {
// Si sort, for les points de reve à 1
if (rollData.selectedSort && !rollData.selectedSort.data.ptreve_reel)
rollData.selectedSort.data.ptreve_reel = 1;
$("#bonusmalus").val(rollData.bmValue);
$("#diffLibre").val(Misc.toInt(rollData.diffLibre));
$("#diffConditions").val(Misc.toInt(rollData.diffConditions));
updateRollResult(rollData);
});
// Update !
html.find('#bonusmalus').click((event) => {
rollData.bmValue = event.currentTarget.value; // Update the selected bonus/malus
html.find('#diffLibre').change((event) => {
rollData.diffLibre = Misc.toInt(event.currentTarget.value); // Update the selected bonus/malus
//console.log("RdDRollDialog","BM CLICKED !!!", rollData);
updateRollResult(rollData);
});
html.find('#carac').click((event) => {
html.find('#diffConditions').change((event) => {
rollData.diffConditions = Misc.toInt(event.currentTarget.value); // Update the selected bonus/malus
//console.log("RdDRollDialog","BM CLICKED !!!", rollData);
updateRollResult(rollData);
});
html.find('#carac').change((event) => {
let caracKey = event.currentTarget.value;
this.rollData.selectedCarac = rollData.carac[caracKey]; // Update the selectedCarac
//console.log("RdDRollDialog","CARAC CLICKED !!!", rollData);
updateRollResult(rollData);
});
html.find('#draconic').click((event) => {
let draconicKey = Number(event.currentTarget.value);
html.find('#draconic').change((event) => {
let draconicKey = Misc.toInt(event.currentTarget.value);
this.rollData.selectedDraconic = rollData.draconicList[draconicKey]; // Update the selectedCarac
//console.log("RdDRollDialog","CARAC CLICKED !!!", rollData);
updateRollResult(rollData);
});
html.find('#sort').click((event) => {
let sortKey = Number(event.currentTarget.value);
html.find('#sort').change((event) => {
let sortKey = Misc.toInt(event.currentTarget.value);
this.rollData.selectedSort = rollData.sortList[sortKey]; // Update the selectedCarac
//console.log("RdDRollDialog - Sort selection", rollData.selectedSort);
updateRollResult(rollData);
});
html.find('#ptreve-variable').click((event) => {
let ptreve = Number(event.currentTarget.value);
html.find('#ptreve-variable').change((event) => {
let ptreve = Misc.toInt(event.currentTarget.value);
this.rollData.selectedSort.data.ptreve_reel = ptreve; // Update the selectedCarac
console.log("RdDRollDialog - Cout reve", ptreve);
updateRollResult(rollData);
@ -139,18 +145,17 @@ export class RdDRollDialog extends Dialog {
/* -------------------------------------------- */
static _computeFinalLevel(rollData) {
let etat = rollData.etat === undefined ? 0 : parseInt(rollData.etat);
let etat = Misc.toInt(rollData.etat);
const diffLibre = Misc.toInt(rollData.diffLibre);
const diffConditions = Misc.toInt(rollData.diffConditions);
if (rollData.competence) {
return etat + parseInt(rollData.competence.data.niveau) + parseInt(rollData.bmValue);
return etat + Misc.toInt(rollData.competence.data.niveau) + diffLibre + diffConditions;
}
if (rollData.draconicList) {
let difficulte = rollData.selectedSort.data.difficulte; // Sort de difficulté variable
if (difficulte.toLowerCase() == "variable") {
difficulte = parseInt(rollData.bmValue); // Récupérer la valeur de la listbox dans ce cas
}
return etat + parseInt(rollData.selectedDraconic.data.niveau) + parseInt(difficulte);
let diffSort = (rollData.selectedSort.data.difficulte.toLowerCase() == "variable") ? diffLibre : Misc.toInt(rollData.selectedSort.data.difficulte);
return etat + Misc.toInt(rollData.selectedDraconic.data.niveau) + diffSort + diffConditions;
}
return etat + parseInt(rollData.bmValue);
return etat + diffLibre + diffConditions;
}
/* -------------------------------------------- */
@ -158,8 +163,8 @@ export class RdDRollDialog extends Dialog {
if (rollData.competence) {
// If a weapon is there, add it in the title
let armeTitle = (rollData.arme) ? " (" + rollData.arme.name + ") " : "";
let niveauStr = (rollData.competence.data.niveau > 0 ? "+" : "") + rollData.competence.data.niveau;
return rollData.selectedCarac.label + "/" + rollData.competence.name + armeTitle + " " + niveauStr
let niveau = Misc.toSignedString(rollData.competence.data.niveau);
return rollData.selectedCarac.label + "/" + rollData.competence.name + armeTitle + " " + niveau
}
if (rollData.draconicList) {
return rollData.selectedDraconic.name + " - " + rollData.selectedSort.name;