Migration vers datamodels

This commit is contained in:
2026-02-25 15:49:55 +01:00
parent 64eb40abfb
commit f1ab04bf32
95 changed files with 7418 additions and 593 deletions

View File

@@ -1,86 +1,78 @@
import { EcrymeUtility } from "../common/ecryme-utility.js";
export class EcrymeRollDialog extends Dialog {
const { HandlebarsApplicationMixin } = foundry.applications.api
/**
* Roll dialog — Application V2 version.
* Reads all form values at roll time (no live tracking needed).
*/
export class EcrymeRollDialog extends HandlebarsApplicationMixin(foundry.applications.api.ApplicationV2) {
/** @override */
static DEFAULT_OPTIONS = {
classes: ["fvtt-ecryme", "ecryme-roll-dialog"],
position: { width: 540 },
window: { title: "ECRY.ui.rolltitle" },
actions: {
roll: EcrymeRollDialog.#onRoll,
cancel: EcrymeRollDialog.#onCancel,
},
}
/** @override */
static PARTS = {
content: { template: "systems/fvtt-ecryme/templates/dialogs/roll-dialog-generic.hbs" },
}
/* -------------------------------------------- */
constructor(actor, rollData, options = {}) {
super(options)
this.actor = actor
this.rollData = rollData
}
/* -------------------------------------------- */
static async create(actor, rollData) {
let options = { classes: ["ecryme-roll-dialog"], width: 540, height: 'fit-content', 'z-index': 99999 }
let html = await foundry.applications.handlebars.renderTemplate('systems/fvtt-ecryme/templates/dialogs/roll-dialog-generic.hbs', rollData);
return new EcrymeRollDialog(actor, rollData, html, options);
return new EcrymeRollDialog(actor, rollData)
}
/* -------------------------------------------- */
constructor(actor, rollData, html, options, close = undefined) {
let conf = {
title: game.i18n.localize("ECRY.ui.rolltitle"),
content: html,
buttons: {
roll: {
icon: '<i class="fas fa-check"></i>',
label: game.i18n.localize("ECRY.ui.roll"),
callback: () => { this.roll() }
},
cancel: {
icon: '<i class="fas fa-times"></i>',
label: game.i18n.localize("ECRY.ui.cancel"),
callback: () => { this.close() }
}
},
close: close
async _prepareContext() {
return {
...this.rollData,
config: game.system.ecryme.config,
}
super(conf, options);
this.actor = actor;
this.rollData = rollData;
}
/* -------------------------------------------- */
roll() {
/** Read all form values at roll time, then execute. */
static #onRoll(event, target) {
const el = this.element
const bonusEl = el.querySelector('#bonusMalusPerso')
const diffEl = el.querySelector('#roll-difficulty')
const specEl = el.querySelector('#roll-specialization')
const traitBonusEl = el.querySelector('#roll-trait-bonus')
const traitMalusEl = el.querySelector('#roll-trait-malus')
const transcEl = el.querySelector('#roll-select-transcendence')
const spleenEl = el.querySelector('#roll-use-spleen')
const idealEl = el.querySelector('#roll-use-ideal')
if (bonusEl) this.rollData.bonusMalusPerso = Number(bonusEl.value)
if (diffEl) this.rollData.difficulty = Number(diffEl.value) || 0
if (specEl) this.rollData.selectedSpecs = Array.from(specEl.selectedOptions).map(o => o.value)
if (traitBonusEl) this.rollData.traitsBonus = Array.from(traitBonusEl.selectedOptions).map(o => o.value)
if (traitMalusEl) this.rollData.traitsMalus = Array.from(traitMalusEl.selectedOptions).map(o => o.value)
if (transcEl) this.rollData.skillTranscendence = Number(transcEl.value)
if (spleenEl) this.rollData.useSpleen = spleenEl.checked
if (idealEl) this.rollData.useIdeal = idealEl.checked
EcrymeUtility.rollEcryme(this.rollData)
this.close()
}
/* -------------------------------------------- */
async refreshDialog() {
const content = await renderTemplate("systems/fvtt-ecryme/templates/dialogs/roll-dialog-generic.hbs", this.rollData)
this.data.content = content
this.render(true)
static #onCancel(event, target) {
this.close()
}
/* -------------------------------------------- */
activateListeners(html) {
super.activateListeners(html);
function onLoad() {
}
$(function () { onLoad(); });
html.find('#bonusMalusPerso').change((event) => {
console.log("DIFF", event.currentTarget.value)
this.rollData.bonusMalusPerso = Number(event.currentTarget.value)
})
html.find('#roll-difficulty').change((event) => {
this.rollData.difficulty = Number(event.currentTarget.value) || 0
})
html.find('#roll-specialization').change((event) => {
this.rollData.selectedSpecs = $('#roll-specialization').val()
})
html.find('#roll-trait-bonus').change((event) => {
this.rollData.traitsBonus = $('#roll-trait-bonus').val()
})
html.find('#roll-trait-malus').change((event) => {
this.rollData.traitsMalus = $('#roll-trait-malus').val()
})
html.find('#roll-select-transcendence').change((event) => {
this.rollData.skillTranscendence = Number($('#roll-select-transcendence').val())
})
html.find('#roll-use-spleen').change((event) => {
this.rollData.useSpleen = event.currentTarget.checked
})
html.find('#roll-use-ideal').change((event) => {
this.rollData.useIdeal = event.currentTarget.checked
})
}
}
}