Files
foundryvtt-reve-de-dragon/module/roll/roll-part-diff.mjs
Vincent Vandemeulebrouck d26ab59c51 Nouvelle fenêtre: attaque/defense
quelques améliorations
préparation pour gérer les messages de résultats en
fonction du type de jet (attaque/compétence/...)

quelques corrections (suppression du filtre de compétences
quand on change de type de jet, astrologie, ..)
2025-09-24 22:39:25 +02:00

77 lines
2.2 KiB
JavaScript

import { DIFF, DIFFS, ROLL_TYPE_MEDITATION, ROLL_TYPE_OEUVRE, ROLL_TYPE_SORT, ROLL_TYPE_TACHE } from "./roll-constants.mjs";
import { ROLLDIALOG_SECTION, RollPart } from "./roll-part.mjs";
export const PART_DIFF = "diff"
const EXCLUDED_ROLL_TYPES = [ROLL_TYPE_TACHE, ROLL_TYPE_MEDITATION, ROLL_TYPE_SORT, ROLL_TYPE_OEUVRE]
export class RollPartDiff extends RollPart {
get code() { return PART_DIFF }
get section() { return ROLLDIALOG_SECTION.CHOIX }
restore(rollData) {
const current = this.getCurrent(rollData)
const saved = this.getSaved(rollData)
current.value = saved?.value ?? current.value ?? 0
current.type = saved?.type ?? current.type
}
store(rollData, targetData) {
const current = this.getCurrent(rollData)
this.setSaved(targetData, {
value: current.value,
type: current.type
})
}
visible(rollData) {
if (EXCLUDED_ROLL_TYPES.includes(rollData.type.current)) {
return false
}
const current = this.getCurrent(rollData)
/* TODO: affiner les cas où afficher ou non. devrait s'afficher pour les jets basiques (même si pas d'opposant sélectionné)*/
return Object.values(DIFF).includes(current.type)
}
prepareContext(rollData) {
const current = this.getCurrent(rollData)
const diffType = DIFFS[current.type] ?? DIFFS[DIFF.AUCUN]
foundry.utils.mergeObject(current,
{
type: diffType.key,
label: diffType?.label ?? '',
value: current.value ?? 0,
disabled: !diffType.libre,
min: -10,
max: diffType.max
},
{ inplace: true }
)
}
setDiff(rollData, diffDefense) {
const current = this.getCurrent(rollData)
current.value = diffDefense.diff
current.type = diffDefense.type
}
getAjustements(rollData) {
const current = this.getCurrent(rollData)
return [{
label: current.label,
diff: current.value
}]
}
async _onRender(rollDialog, context, options) {
const input = rollDialog.element.querySelector(`roll-section[name="${this.code}"] input[name="${this.code}"]`)
input?.addEventListener("change", e => {
this.getCurrent(rollDialog.rollData).value = parseInt(e.currentTarget.value)
rollDialog.render()
})
}
}