import { SYSTEM_RDD } from "../constants.js"; import { ROLLDIALOG_SECTION, RollPart } from "./roll-part.mjs"; const CONDITIONS = "conditions" const DESCR_CONDITIONS = "Conditions" export class RollPartConditions extends RollPart { /** TODO: use alternate to numberInput that supports displaying '+' sign */ settingMin() { return RollPart.settingKey(this, 'min') } settingMax() { return RollPart.settingKey(this, 'max') } onReady() { game.settings.register(SYSTEM_RDD, this.settingMin(), { name: "Malus maximal de conditions", type: Number, config: true, scope: "world", range: { min: -20, max: -10, step: 1 }, default: -16 } ) game.settings.register(SYSTEM_RDD, this.settingMax(), { name: "Bonus maximal de conditions", type: Number, config: true, scope: "world", range: { min: 5, max: 15, step: 1 }, default: 10 } ) } restore(rollData) { const current = this.getCurrent(rollData) current.value = this.getSaved(rollData)?.value ?? current.value ?? 0 } store(rollData, targetData) { this.setSaved(targetData, { value: this.getCurrent(rollData).value }) } /** @override */ get code() { return CONDITIONS } get section() { return ROLLDIALOG_SECTION.CONDITIONS } prepareContext(rollData) { const current = this.getCurrent(rollData) current.min = game.settings.get(SYSTEM_RDD, this.settingMin()) current.max = game.settings.get(SYSTEM_RDD, this.settingMax()) current.value = current.value ?? 0 } getAjustements(rollData) { const current = this.getCurrent(rollData) if (current.value != 0) { return [{ label: DESCR_CONDITIONS, diff: current.value }] } return [] } async _onRender(rollDialog, context, options) { const input = rollDialog.element.querySelector(`roll-section[name="${this.code}"] input[name="${this.code}"]`) input?.addEventListener("change", e => { const current = this.getCurrent(rollDialog.rollData) current.value = parseInt(e.currentTarget.value) rollDialog.render() }) } }