Files
foundryvtt-reve-de-dragon/module/roll/roll-part.mjs
Vincent Vandemeulebrouck fa6769fcd7 Fenêtres Roll V2
Maintenant disponibles pour:
- méditation
- tâches
- soins
2025-10-05 03:09:52 +02:00

113 lines
3.2 KiB
JavaScript

export const ROLLDIALOG_SECTION = {
ACTION: 'action',
CARAC: 'carac',
COMP: 'comp',
CHOIX: 'choix',
CONDITIONS: 'conditions',
AJUSTEMENTS: 'ajustements',
}
export class RollPart {
static settingKey(rollPart, key) { return `roll-part-${rollPart.code}.${key}` }
get code() { throw new Error(`Pas dse code définie pour ${this}`) }
get name() { return this.code }
/** la section de la fenêtre ou le paramêtre apparaît */
get section() { return undefined }
get priority() { return 0 /* TODO */ }
/** le template handlebars pour affichage */
get template() { return `systems/foundryvtt-reve-de-dragon/templates/roll/roll-part-${this.code}.hbs` }
initialize(rollData) {
if (rollData.refs[this.code] == undefined) {
rollData.refs[this.code] = {}
}
if (rollData.current[this.code] == undefined) {
rollData.current[this.code] = {}
}
if (rollData.selected[this.code] == undefined) {
rollData.selected[this.code] = {}
}
}
/** le conteneur de données du RollPart */
getRefs(rollData) {
return rollData.refs[this.code]
}
/** les informations de sélection du paramètre */
getCurrent(rollData) {
return rollData.current[this.code]
}
setCurrent(rollData, current) {
rollData.current[this.code] = current
}
/** les informations minimales représentant la sélection dans le rollData permettant de restaurer la fenêtre */
getSelected(rollData) { return this.getSaved(rollData) }
getSaved(rollData) {
return rollData.selected[this.code] ?? {}
}
setSaved(rollData, saved) {
rollData.selected[this.code] = saved
}
restore(rollData) { }
storeClean(rollData, targetData) {
this.store(rollData, targetData)
if (rollData.selected[this.code]) {
const toDelete = Object.entries(rollData.selected[this.code])
.map(([k, v]) => v == undefined ? k : undefined)
.filter(k => k != undefined)
toDelete.forEach(k => delete rollData.selected[this.code][k])
if (Object.keys(rollData.selected[this.code]).length == 0) {
delete rollData.selected[this.code]
}
}
}
store(rollData, targetData) {
this.setSaved(targetData, { key: this.getCurrent(rollData).key })
}
/**
* le texte à ajouter dans la barre de titre
* @returns une chaîne vide si rien ne doit être affiché
*/
title() { return '' }
isRollType(rollData, type) { return rollData.type.current == type }
isActive(rollData) { return this.isValid(rollData) && this.visible(rollData) }
isValid(rollData) { return true }
visible(rollData) { return true }
onReady() { }
loadRefs(rollData) { }
prepareContext(rollData) { }
/** permet de sauvegarder dans rollData les informations (cas des champs edit) */
validate(rollData) { }
/** ---- cross roll-part filtering ---- */
applyImpact(rollData, filter) { }
getSpecialComp(rollData) { return [] }
setSpecialComp(comps) { }
impactOtherPart(partCode, rollData) { }
applyExternalImpacts(rollParts, rollData) {
rollParts.forEach(part => part.impactOtherPart(this, rollData))
}
toTemplateData() {
return { code: this.code, name: this.name, template: this.template, section: this.section }
}
getAjustements(rollData) {
return []
}
async _onRender(rollDialog, context, options) { }
}