Files
foundryvtt-reve-de-dragon/module/roll/roll-part.mjs

95 lines
2.6 KiB
JavaScript

import { Misc } from "../misc.js"
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 */
getSaved(rollData) {
return rollData.selected[this.code] ?? {}
}
setSaved(rollData, saved) {
rollData.selected[this.code] = saved
}
restore(rollData) { }
store(rollData, targetData) { }
/**
* le texte à ajouter dans la barre de titre
* @returns une chaîne vide si rien ne doit être affiché
*/
title() { return '' }
isRollMode(rollData, mode) { return rollData.mode.current == mode }
isActive(rollData) { return this.isValid(rollData) && this.visible(rollData) }
isValid(rollData) { return true }
visible(rollData) { return true }
onReady() { }
loadRefs(rollData) { }
prepareContext(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) { }
}