forked from public/foundryvtt-reve-de-dragon
Nouvelle fenêtre de jets de dés
This commit is contained in:
61
module/roll/roll-part-checkbox.mjs
Normal file
61
module/roll/roll-part-checkbox.mjs
Normal file
@@ -0,0 +1,61 @@
|
||||
import { ROLLDIALOG_SECTION, RollPart } from "./roll-part.mjs"
|
||||
|
||||
export class RollPartCheckbox extends RollPart {
|
||||
|
||||
get section() { return ROLLDIALOG_SECTION.CONDITIONS }
|
||||
|
||||
get useCheckboxTemplate() { return true }
|
||||
get template() { return this.useCheckboxTemplate ? 'systems/foundryvtt-reve-de-dragon/templates/roll/roll-part-checkbox.hbs' : super.template }
|
||||
get isDefaultChecked() { return true }
|
||||
|
||||
restore(rollData) {
|
||||
const checked = this.getSaved(rollData).checked
|
||||
this.getCurrent(rollData).checked = checked == undefined? this.isDefaultChecked : checked
|
||||
}
|
||||
|
||||
store(rollData, targetData) {
|
||||
this.setSaved(targetData, { checked: this.getCurrent(rollData).checked })
|
||||
}
|
||||
|
||||
loadRefs(rollData) {
|
||||
const current = this.getCurrent(rollData)
|
||||
current.label = this.getCheckboxLabel(rollData)
|
||||
}
|
||||
|
||||
prepareContext(rollData) {
|
||||
const current = this.getCurrent(rollData)
|
||||
if (current.checked == undefined) {
|
||||
/* TODO: user setting? */
|
||||
current.checked = true
|
||||
}
|
||||
if (current.value == undefined) {
|
||||
current.value = this.getCheckboxValue(rollData)
|
||||
}
|
||||
current.icon = this.getCheckboxIcon(rollData)
|
||||
}
|
||||
|
||||
getAjustements(rollData) {
|
||||
const current = this.getCurrent(rollData)
|
||||
if (current.checked) {
|
||||
return [{ label: this.getCheckboxLabelAjustement(rollData), diff: current.value }]
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
getCheckboxLabelAjustement(rollData) {
|
||||
return `${this.getCheckboxIcon(rollData)} ${this.getCurrent(rollData).label}`
|
||||
}
|
||||
|
||||
async _onRender(rollDialog, context, options) {
|
||||
const checkbox = rollDialog.element.querySelector(`roll-section[name="${this.code}"] input[name="${this.code}"]`)
|
||||
|
||||
checkbox?.addEventListener("change", e => {
|
||||
this.getCurrent(rollDialog.rollData).checked = e.currentTarget.checked
|
||||
rollDialog.render()
|
||||
})
|
||||
}
|
||||
|
||||
getCheckboxIcon(rollData) { return '' }
|
||||
getCheckboxLabel(rollData) { return "LABEL" }
|
||||
getCheckboxValue(rollData) { return 0 }
|
||||
}
|
Reference in New Issue
Block a user