forked from public/foundryvtt-reve-de-dragon
Cleanup roll windows
- 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
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user