Finalize aappv2 data models migration
This commit is contained in:
@@ -1,91 +1,57 @@
|
||||
import { MaleficesUtility } from "./malefices-utility.js";
|
||||
|
||||
export class MaleficesRollDialog extends Dialog {
|
||||
export class MaleficesRollDialog {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async create(actor, rollData) {
|
||||
const isCard = rollData?.attr?.iscard
|
||||
const template = isCard
|
||||
? 'systems/fvtt-malefices/templates/dialogs/confrontation-dialog.hbs'
|
||||
: 'systems/fvtt-malefices/templates/dialogs/roll-dialog-generic.hbs'
|
||||
|
||||
let options = { classes: ["MaleficesDialog"], width: 540, height: 'fit-content', 'z-index': 99999 }
|
||||
let html
|
||||
if (rollData?.attr?.iscard) {
|
||||
html = await foundry.applications.handlebars.renderTemplate('systems/fvtt-malefices/templates/dialogs/confrontation-dialog.hbs', rollData);
|
||||
} else {
|
||||
html = await foundry.applications.handlebars.renderTemplate('systems/fvtt-malefices/templates/dialogs/roll-dialog-generic.hbs', rollData);
|
||||
}
|
||||
const content = await foundry.applications.handlebars.renderTemplate(template, rollData)
|
||||
|
||||
return new MaleficesRollDialog(actor, rollData, html, options);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
constructor(actor, rollData, html, options, close = undefined) {
|
||||
let isCard = rollData?.attr?.iscard
|
||||
let conf = {
|
||||
title: (isCard) ? "Jet" : "Tirage",
|
||||
content: html,
|
||||
buttons: {
|
||||
roll: {
|
||||
icon: '<i class="fas fa-check"></i>',
|
||||
label: (isCard) ? "Tirer une carte" : "Lancer le dé",
|
||||
callback: () => { this.roll() }
|
||||
},
|
||||
cancel: {
|
||||
icon: '<i class="fas fa-times"></i>',
|
||||
label: "Annuler",
|
||||
callback: () => { this.close() }
|
||||
}
|
||||
return foundry.applications.api.DialogV2.wait({
|
||||
window: {
|
||||
title: isCard ? "Tirage" : "Jet de dé",
|
||||
icon: isCard ? "fa-solid fa-layer-group" : "fa-solid fa-dice-d20",
|
||||
},
|
||||
close: close
|
||||
}
|
||||
|
||||
super(conf, options);
|
||||
|
||||
this.actor = actor;
|
||||
this.rollData = rollData;
|
||||
classes: ["malefices-roll-dialog"],
|
||||
position: { width: 540 },
|
||||
modal: false,
|
||||
rejectClose: false,
|
||||
content,
|
||||
buttons: [
|
||||
{
|
||||
action: "roll",
|
||||
label: isCard ? "Tirer une carte" : "Lancer le dé",
|
||||
icon: isCard ? "fa-solid fa-layer-group" : "fa-solid fa-check",
|
||||
default: true,
|
||||
callback: (event, button, dialog) => {
|
||||
MaleficesRollDialog._updateRollDataFromForm(rollData, button.form.elements)
|
||||
if (isCard) {
|
||||
MaleficesUtility.tirageConfrontationMalefices(rollData)
|
||||
} else {
|
||||
MaleficesUtility.rollMalefices(rollData)
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
action: "cancel",
|
||||
label: "Annuler",
|
||||
icon: "fa-solid fa-times",
|
||||
}
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
roll() {
|
||||
let isCard = this.rollData?.attr?.iscard
|
||||
if (isCard) {
|
||||
MaleficesUtility.tirageConfrontationMalefices(this.rollData)
|
||||
} else {
|
||||
MaleficesUtility.rollMalefices(this.rollData)
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async refreshDialog() {
|
||||
const content = await renderTemplate("systems/fvtt-malefices/templates/dialogs/roll-dialog-generic.hbs", this.rollData)
|
||||
this.data.content = content
|
||||
this.render(true)
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
|
||||
function onLoad() {
|
||||
}
|
||||
$(function () { onLoad(); });
|
||||
|
||||
html.find('#bonusMalusSituation').change((event) => {
|
||||
this.rollData.bonusMalusSituation = Number(event.currentTarget.value)
|
||||
})
|
||||
html.find('#bonusMalusPerso').change((event) => {
|
||||
this.rollData.bonusMalusPerso = Number(event.currentTarget.value)
|
||||
})
|
||||
html.find('#bonusMalusDef').change((event) => {
|
||||
this.rollData.bonusMalusDef = Number(event.currentTarget.value)
|
||||
})
|
||||
html.find('#bonusMalusPortee').change((event) => {
|
||||
this.rollData.bonusMalusPortee = Number(event.currentTarget.value)
|
||||
})
|
||||
html.find('#confrontationDegre').change((event) => {
|
||||
this.rollData.confrontationDegre = Number(event.currentTarget.value)
|
||||
})
|
||||
html.find('#confrontationModif').change((event) => {
|
||||
this.rollData.confrontationModif = Number(event.currentTarget.value)
|
||||
})
|
||||
|
||||
static _updateRollDataFromForm(rollData, elements) {
|
||||
if (elements.bonusMalusPerso) rollData.bonusMalusPerso = Number(elements.bonusMalusPerso.value)
|
||||
if (elements.bonusMalusSituation) rollData.bonusMalusSituation = Number(elements.bonusMalusSituation.value)
|
||||
if (elements.bonusMalusDef) rollData.bonusMalusDef = Number(elements.bonusMalusDef.value)
|
||||
if (elements.bonusMalusPortee) rollData.bonusMalusPortee = Number(elements.bonusMalusPortee.value)
|
||||
if (elements.confrontationDegre) rollData.confrontationDegre = Number(elements.confrontationDegre.value)
|
||||
if (elements.confrontationModif) rollData.confrontationModif = Number(elements.confrontationModif.value)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user