Roll V2 mode possession

This commit is contained in:
2025-11-28 19:44:06 +01:00
parent 981282d809
commit fd3f988a4f
7 changed files with 114 additions and 3 deletions

View File

@@ -0,0 +1,79 @@
import { CATEGORIES_COMPETENCES_CREATURES } from "../item/base-items.js"
import { CARACS } from "../rdd-carac.js"
import { ROLL_TYPE_POSSESSION } from "./roll-constants.mjs"
import { PART_CARAC } from "./roll-part-carac.mjs"
import { PART_COMP } from "./roll-part-comp.mjs"
import { RollPartSelect } from "./roll-part-select.mjs"
import { ROLLDIALOG_SECTION } from "./roll-part.mjs"
export const PART_POSSESSION = "possession"
export class RollPartPossession extends RollPartSelect {
/** TODO: remplacer selectOption par un sélecteur plus sympa (avec image de compétence, par exemple? */
get code() { return PART_POSSESSION }
get name() { return 'Possession' }
get section() { return ROLLDIALOG_SECTION.CHOIX }
visible(rollData) { return this.isRollType(rollData, ROLL_TYPE_POSSESSION) }
loadRefs(rollData) {
const refs = this.getRefs(rollData)
const selected = this.getSelected(rollData)
refs.all = this.$getActorConjurations(rollData)
refs.isPersonnage = rollData.active.actor.isPersonnage()
refs.isENI = rollData.active.actor.isEntiteNonIncarnee()
this.$selectPossession(rollData)
}
choices(refs) { return refs.all }
$getActorConjurations(rollData) {
const competences = rollData.active.actor.getDraconicOuPossession()
return competences.map(RollPartPossession.extractPossession)
}
static extractPossession(comp) {
return {
key: comp.id ?? comp.name,
label: `${comp.system.categorie == CATEGORIES_COMPETENCES_CREATURES.possession.key ? 'Possession': 'Conjuration'} (${comp.name})`,
value: comp.system.niveau,
comp: comp
}
}
prepareContext(rollData) {
this.$selectPossession(rollData)
}
getAjustements(rollData) {
return []
}
async _onRender(rollDialog, context, options) {
const select = rollDialog.element.querySelector(`roll-section[name="${this.code}"] select[name="select-possession"]`)
select?.addEventListener("change", e => {
const selectOptions = e.currentTarget.options
const index = selectOptions.selectedIndex
this.$selectPossession(rollDialog.rollData, selectOptions[index]?.value)
rollDialog.render()
})
}
$selectPossession(rollData, key) {
this.selectByKey(rollData, key, 0)
}
impactOtherPart(part, rollData) {
if (this.visible(rollData)) {
const current = this.getCurrent(rollData)
switch (part.code) {
case PART_CARAC: return part.filterCaracs(rollData, [this.getRefs(rollData).isPersonnage ? CARACS.REVE_ACTUEL : CARACS.REVE])
case PART_COMP: return part.filterComps(rollData, [current.comp?.name])
}
}
return undefined
}
}