gestion des appels à la chance pour tout jet V2 correction de soucis forçage du jet continuation des messages de défense
76 lines
2.2 KiB
JavaScript
76 lines
2.2 KiB
JavaScript
import { SYSTEM_RDD } from "../constants.js";
|
|
import { Misc } from "../misc.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 = Misc.inRange(current.value ?? 0, current.min, current.max)
|
|
}
|
|
|
|
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("input", e => this.onInputChange(e, rollDialog))
|
|
}
|
|
|
|
onInputChange(event, rollDialog) {
|
|
this.getCurrent(rollDialog.rollData).value = parseInt(event.currentTarget.value)
|
|
rollDialog.render()
|
|
}
|
|
|
|
} |