178 lines
6.2 KiB
JavaScript
178 lines
6.2 KiB
JavaScript
import { HawkmoonUtility } from "../hawkmoon-utility.js"
|
|
import { HAWKMOON_CONFIG } from "../hawkmoon-config.js"
|
|
|
|
/**
|
|
* Dialogue de jet de dé pour Hawkmoon - Version DialogV2
|
|
*/
|
|
export class HawkmoonRollDialog {
|
|
|
|
/**
|
|
* Create and display the roll dialog
|
|
* @param {HawkmoonActor} actor - The actor making the roll
|
|
* @param {Object} rollData - Data for the roll
|
|
* @returns {Promise<HawkmoonRollDialog>}
|
|
*/
|
|
static async create(actor, rollData) {
|
|
// Préparer le contexte pour le template
|
|
const context = {
|
|
...rollData,
|
|
difficulte: String(rollData.difficulte || 0), // Convertir en string pour matcher les options du select
|
|
img: actor.img,
|
|
name: actor.name,
|
|
config: HAWKMOON_CONFIG,
|
|
}
|
|
|
|
// Si attrKey est "tochoose", préparer la liste des attributs sélectionnables
|
|
if (rollData.attrKey === "tochoose") {
|
|
context.selectableAttributes = actor.system.attributs
|
|
// Ne pas changer attrKey ni attr - l'utilisateur doit choisir
|
|
}
|
|
|
|
// Rendre le template en HTML
|
|
const content = await foundry.applications.handlebars.renderTemplate(
|
|
"systems/fvtt-hawkmoon-cyd/templates/roll-dialog-generic.hbs",
|
|
context
|
|
)
|
|
|
|
// Utiliser DialogV2.wait avec le HTML rendu
|
|
return foundry.applications.api.DialogV2.wait({
|
|
window: { title: "Test de Capacité", icon: "fa-solid fa-dice-d20" },
|
|
classes: ["hawkmoon-roll-dialog"],
|
|
position: { width: 480 },
|
|
modal: false, // Permettre l'interaction avec le canvas pour garder la cible sélectionnée
|
|
content,
|
|
buttons: [
|
|
{
|
|
action: "rolld10",
|
|
label: "Lancer 1d10",
|
|
icon: "fa-solid fa-dice-d10",
|
|
default: true,
|
|
callback: (event, button, dialog) => {
|
|
this._updateRollDataFromForm(rollData, button.form.elements, actor)
|
|
rollData.mainDice = "d10"
|
|
HawkmoonUtility.rollHawkmoon(rollData)
|
|
}
|
|
},
|
|
{
|
|
action: "rolld20",
|
|
label: "Lancer 1d20",
|
|
icon: "fa-solid fa-dice-d20",
|
|
callback: (event, button, dialog) => {
|
|
this._updateRollDataFromForm(rollData, button.form.elements, actor)
|
|
rollData.mainDice = "d20"
|
|
HawkmoonUtility.rollHawkmoon(rollData)
|
|
}
|
|
},
|
|
],
|
|
rejectClose: false,
|
|
})
|
|
}
|
|
|
|
/**
|
|
* Mettre à jour rollData avec les valeurs du formulaire
|
|
* @param {Object} rollData - L'objet rollData à mettre à jour
|
|
* @param {HTMLFormControlsCollection} formElements - Les éléments du formulaire
|
|
* @param {HawkmoonActor} actor - L'acteur pour récupérer les attributs
|
|
* @private
|
|
*/
|
|
static _updateRollDataFromForm(rollData, formElements, actor) {
|
|
// Attributs
|
|
if (formElements.attrKey) {
|
|
rollData.attrKey = formElements.attrKey.value
|
|
// Si l'attribut a changé, mettre à jour rollData.attr
|
|
if (rollData.attrKey !== "tochoose" && rollData.attrKey !== "none" && actor) {
|
|
rollData.attr = foundry.utils.duplicate(actor.system.attributs[rollData.attrKey])
|
|
rollData.actionImg = "systems/fvtt-hawkmoon-cyd/assets/icons/" + actor.system.attributs[rollData.attrKey].labelnorm + ".webp"
|
|
}
|
|
}
|
|
if (formElements.attrKey2) {
|
|
rollData.attrKey2 = formElements.attrKey2.value
|
|
}
|
|
|
|
// Modificateurs de base
|
|
if (formElements.difficulte) {
|
|
rollData.difficulte = Number(formElements.difficulte.value)
|
|
}
|
|
if (formElements.modificateur) {
|
|
rollData.modificateur = Number(formElements.modificateur.value)
|
|
}
|
|
if (formElements.soutiens) {
|
|
rollData.soutiens = Number(formElements.soutiens.value)
|
|
}
|
|
|
|
// Compétence
|
|
if (formElements.maitrise) {
|
|
rollData.maitriseId = formElements.maitrise.value
|
|
}
|
|
if (formElements.talents) {
|
|
// Récupérer toutes les options sélectionnées (select multiple)
|
|
const selectedOptions = Array.from(formElements.talents.selectedOptions)
|
|
rollData.selectedTalents = selectedOptions.map(opt => opt.value)
|
|
}
|
|
|
|
// Modificateurs de tir
|
|
if (formElements.tailleCible) {
|
|
rollData.tailleCible = formElements.tailleCible.value
|
|
}
|
|
if (formElements.tireurDeplacement) {
|
|
rollData.tireurDeplacement = formElements.tireurDeplacement.value
|
|
}
|
|
if (formElements.cibleCouvert) {
|
|
rollData.cibleCouvert = formElements.cibleCouvert.value
|
|
}
|
|
if (formElements.distanceTir) {
|
|
rollData.distanceTir = formElements.distanceTir.value
|
|
}
|
|
if (formElements.cibleDeplace) {
|
|
rollData.cibleDeplace = formElements.cibleDeplace.checked
|
|
}
|
|
if (formElements.cibleCaC) {
|
|
rollData.cibleCaC = formElements.cibleCaC.checked
|
|
}
|
|
|
|
// Modificateurs de combat (checkboxes)
|
|
if (formElements.defenseurAuSol) {
|
|
rollData.defenseurAuSol = formElements.defenseurAuSol.checked
|
|
}
|
|
if (formElements.ambidextre1) {
|
|
rollData.ambidextre1 = formElements.ambidextre1.checked
|
|
}
|
|
if (formElements.ambidextre2) {
|
|
rollData.ambidextre2 = formElements.ambidextre2.checked
|
|
}
|
|
if (formElements.attaqueMonte) {
|
|
rollData.attaqueMonte = formElements.attaqueMonte.checked
|
|
}
|
|
if (formElements.defenseurAveugle) {
|
|
rollData.defenseurAveugle = formElements.defenseurAveugle.checked
|
|
}
|
|
if (formElements.defenseurDeDos) {
|
|
rollData.defenseurDeDos = formElements.defenseurDeDos.checked
|
|
}
|
|
if (formElements.defenseurRestreint) {
|
|
rollData.defenseurRestreint = formElements.defenseurRestreint.checked
|
|
}
|
|
if (formElements.defenseurImmobilise) {
|
|
rollData.defenseurImmobilise = formElements.defenseurImmobilise.checked
|
|
}
|
|
if (formElements.attaqueCharge) {
|
|
rollData.attaqueCharge = formElements.attaqueCharge.checked
|
|
}
|
|
if (formElements.chargeCavalerie) {
|
|
rollData.chargeCavalerie = formElements.chargeCavalerie.checked
|
|
}
|
|
if (formElements.attaquantsMultiple) {
|
|
rollData.attaquantsMultiple = formElements.attaquantsMultiple.checked
|
|
}
|
|
if (formElements.feinte) {
|
|
rollData.feinte = formElements.feinte.checked
|
|
}
|
|
if (formElements.contenir) {
|
|
rollData.contenir = formElements.contenir.checked
|
|
}
|
|
if (formElements.attaqueDesarme) {
|
|
rollData.attaqueDesarme = formElements.attaqueDesarme.checked
|
|
}
|
|
}
|
|
}
|