foundryvtt-reve-de-dragon/module/rdd-roll-dialog.js

132 lines
5.6 KiB
JavaScript
Raw Normal View History

2020-06-03 21:35:18 +02:00
/**
* Extend the base Dialog entity by defining a custom window to perform roll.
* @extends {Dialog}
*/
export class RdDRollDialog extends Dialog {
/* -------------------------------------------- */
constructor(mode, html, rollData, actor) {
2020-07-26 17:26:17 +02:00
let myButtons = { rollButton: {
label: "Lancer",
callback: html => this.performRollSort(html, false)
} };
if (mode == "sort") {
myButtons['reserveButton'] = { label: "Mettre en reserve",
callback: html => this.performRollSort(html, true)
}
}
2020-06-03 21:35:18 +02:00
// Common conf
let dialogConf = {
content: html,
2020-07-26 17:26:17 +02:00
buttons: myButtons,
default: "rollButton"
}
2020-06-03 21:35:18 +02:00
let dialogOptions = { classes: [ "rdddialog"] }
// Select proper roll dialog template and stuff
if (mode == "competence" ) {
dialogConf.title = "Test de compétence",
dialogOptions.width = 600;
dialogOptions.height = 360;
2020-06-07 23:16:29 +02:00
} else if (mode == "arme") {
dialogConf.title = "Test de combat/arme",
dialogOptions.width = 600;
dialogOptions.height = 360;
2020-06-12 22:46:04 +02:00
} else if (mode == "carac") {
dialogConf.title = "Test de caractéristique",
dialogOptions.width = 600;
dialogOptions.height = 320;
2020-07-23 22:09:40 +02:00
} else if (mode == "sort") {
dialogConf.title = "Lancer un sort",
dialogOptions.width = 600;
2020-07-26 17:26:17 +02:00
dialogOptions.height = 380;
2020-06-07 23:16:29 +02:00
}
2020-06-03 21:35:18 +02:00
super(dialogConf, dialogOptions);
this.mode = mode;
this.rollData = rollData;
this.actor = actor;
}
/* -------------------------------------------- */
2020-07-26 17:26:17 +02:00
performRollSort (html, isReserve=false) {
this.rollData.isSortReserve = isReserve;
2020-06-03 21:35:18 +02:00
this.actor.performRoll( this.rollData );
}
/* -------------------------------------------- */
activateListeners(html) {
super.activateListeners(html);
// Get the rollData stuff
var rollData = this.rollData;
function updateRollResult( rollData ) {
2020-06-12 22:46:04 +02:00
if ( rollData.competence )
rollData.finalLevel = parseInt(rollData.competence.data.niveau) + parseInt(rollData.bmValue) + parseInt(rollData.etat);
2020-07-23 22:09:40 +02:00
else if ( rollData.draconicList )
rollData.finalLevel = parseInt(rollData.selectedDraconic.data.niveau) + parseInt(rollData.selectedSort.data.difficulte) + parseInt(rollData.etat);
else
2020-06-12 22:46:04 +02:00
rollData.finalLevel = parseInt(rollData.bmValue) + parseInt(rollData.etat);
2020-06-03 21:35:18 +02:00
rollData.finalLevelStr = (rollData.finalLevel >= 0 ) ? "+" + rollData.finalLevel : rollData.finalLevel;
$("#roll-param").text( rollData.selectedCarac.value + " / " + rollData.finalLevelStr );
rollData.rollTarget = game.data.RdDUtility.getResolutionField( rollData.selectedCarac.value, rollData.finalLevel);
2020-06-12 22:46:04 +02:00
2020-06-07 23:16:29 +02:00
let armeTitle = ( rollData.arme ) ? " ("+rollData.arme.name+") " : ""; // If a weapon is there, add it in the title
2020-06-12 22:46:04 +02:00
let niveauStr = "";
if ( rollData.competence ) {
niveauStr = (rollData.competence.data.niveau >= 0) ? "+" + rollData.competence.data.niveau : rollData.competence.data.niveau;
$("#compdialogTitle").text( rollData.selectedCarac.label + "/" + rollData.competence.name + armeTitle + " " + niveauStr );
2020-07-23 22:09:40 +02:00
} else if ( rollData.draconicList) {
$("#compdialogTitle").text( rollData.selectedDraconic.name + " - " + rollData.selectedSort.name );
2020-06-12 22:46:04 +02:00
} else {
$("#compdialogTitle").text( rollData.selectedCarac.label );
}
2020-06-03 21:35:18 +02:00
$(".table-resolution").remove();
game.data.RdDUtility.makeHTMLResolutionTable( $("#resolutionTable"), rollData.selectedCarac.value-2, parseInt(rollData.selectedCarac.value) + 2, -10, 11,
rollData.selectedCarac.value, rollData.finalLevel );
}
// Setup everything onload
$(function() {
// Update html, according to data
2020-06-12 22:46:04 +02:00
if (rollData.competence) {
// Set the default carac from the competence item
rollData.selectedCarac = rollData.carac[rollData.competence.data.defaut_carac];
$("#carac").val( rollData.competence.data.defaut_carac );
}
2020-06-03 21:35:18 +02:00
$("#bonusmalus").val( rollData.bmValue );
updateRollResult(rollData);
});
2020-06-11 00:29:32 +02:00
2020-06-03 21:35:18 +02:00
// Update !
2020-06-23 23:34:12 +02:00
html.find('#bonusmalus').click((event) => {
2020-06-03 21:35:18 +02:00
rollData.bmValue = event.currentTarget.value; // Update the selected bonus/malus
//console.log("BM CLICKED !!!", rollData.bmValue, rollData.competence.data.niveau, parseInt(rollData.competence.data.niveau) + parseInt(rollData.bmValue) );
updateRollResult(rollData);
});
2020-06-23 23:34:12 +02:00
html.find('#carac').click((event) => {
2020-06-03 21:35:18 +02:00
let caracKey = event.currentTarget.value;
rollData.selectedCarac = rollData.carac[caracKey]; // Update the selectedCarac
//console.log("CARAC CLICKED !!!", rollData.selectedCarac, rollData.competence.data.niveau, rollData.bmValue);
updateRollResult(rollData);
});
2020-07-23 22:09:40 +02:00
html.find('#draconic').click((event) => {
let draconicKey = event.currentTarget.value;
rollData.selectedDraconic = rollData.draconicList[draconicKey]; // Update the selectedCarac
//console.log("CARAC CLICKED !!!", rollData.selectedCarac, rollData.competence.data.niveau, rollData.bmValue);
updateRollResult(rollData);
});
html.find('#sort').click((event) => {
let sortKey = event.currentTarget.value;
rollData.selectedSort = rollData.sortList[sortKey]; // Update the selectedCarac
//console.log("CARAC CLICKED !!!", rollData.selectedCarac, rollData.competence.data.niveau, rollData.bmValue);
updateRollResult(rollData);
});
2020-06-03 21:35:18 +02:00
}
}