70 lines
2.2 KiB
JavaScript
70 lines
2.2 KiB
JavaScript
import { ITEM_TYPES } from "../constants.js"
|
|
import { ROLL_TYPE_TACHE } 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_TACHE = "tache"
|
|
|
|
export class RollPartTache extends RollPartSelect {
|
|
|
|
get code() { return PART_TACHE }
|
|
get section() { return ROLLDIALOG_SECTION.CHOIX }
|
|
|
|
isValid(rollData) { return rollData.active.actor.isPersonnage() }
|
|
visible(rollData) { return this.isRollType(rollData, ROLL_TYPE_TACHE) }
|
|
|
|
loadRefs(rollData) {
|
|
const refs = this.getRefs(rollData)
|
|
const selected = this.getSelected(rollData)
|
|
refs.all = rollData.active.actor.itemTypes[ITEM_TYPES.tache]
|
|
.filter(tache => !selected.forced || tache.id == selected.key)
|
|
.filter(tache => tache.system.points_de_tache_courant < tache.system.points_de_tache)
|
|
.map(tache => RollPartTache.$extractTache(tache, rollData.active.actor))
|
|
refs.taches = refs.all
|
|
if (refs.taches.length > 0) {
|
|
this.$selectTache(rollData)
|
|
}
|
|
}
|
|
|
|
choices(refs) { return refs.taches }
|
|
|
|
static $extractTache(tache, actor) {
|
|
return {
|
|
key: tache.id,
|
|
label: tache.name,
|
|
value: tache.system.difficulte,
|
|
tache: tache,
|
|
comp: actor.getCompetence(tache.system.competence)
|
|
}
|
|
}
|
|
|
|
$selectTache(rollData, key) {
|
|
this.selectByKey(rollData, key, 0)
|
|
}
|
|
|
|
async _onRender(rollDialog, context, options) {
|
|
const selectTache = rollDialog.element.querySelector(`roll-section[name="${this.code}"] select[name="select-tache"]`)
|
|
|
|
selectTache.addEventListener("change", e => {
|
|
const selectOptions = e.currentTarget.options
|
|
const index = selectOptions.selectedIndex
|
|
this.$selectTache(rollDialog.rollData, selectOptions[index]?.value)
|
|
rollDialog.render()
|
|
})
|
|
}
|
|
|
|
impactOtherPart(part, rollData) {
|
|
if (this.visible(rollData)) {
|
|
const current = this.getCurrent(rollData)
|
|
switch (part.code) {
|
|
case PART_CARAC: return part.filterCaracs(rollData, [current?.tache.system.carac])
|
|
case PART_COMP: return part.filterComps(rollData, [current.comp?.name])
|
|
}
|
|
}
|
|
return undefined
|
|
}
|
|
|
|
}
|