forked from public/foundryvtt-reve-de-dragon
Nouveau roll-dialog: mode attaque / defense
This commit is contained in:
@@ -187,7 +187,12 @@ export default class RollDialog extends HandlebarsApplicationMixin(ApplicationV2
|
||||
foundry.applications.handlebars.loadTemplates(ROLL_PARTS.map(p => p.template))
|
||||
ROLL_PARTS.forEach(p => p.onReady())
|
||||
|
||||
Handlebars.registerHelper('roll-centered-array', (base, show) => RollDialog.centeredArray(base, show))
|
||||
Handlebars.registerHelper('roll-centered-array', (base, show) => {
|
||||
show = Math.abs(show)
|
||||
const start = base - show
|
||||
return [...Array(2 * show + 1).keys()].map(it => start + it)
|
||||
})
|
||||
|
||||
Handlebars.registerHelper('roll-list-item-value', (list, key, path = undefined) => {
|
||||
const selected = list.find(p => p.key == key)
|
||||
if (selected && path && path != '') {
|
||||
@@ -195,6 +200,7 @@ export default class RollDialog extends HandlebarsApplicationMixin(ApplicationV2
|
||||
}
|
||||
return selected
|
||||
})
|
||||
|
||||
Handlebars.registerHelper('roll-part-context', (rollData, code) => {
|
||||
const rollPart = ROLL_PARTS.find(it => it.code == code)
|
||||
if (rollPart == undefined) {
|
||||
@@ -211,12 +217,7 @@ export default class RollDialog extends HandlebarsApplicationMixin(ApplicationV2
|
||||
})
|
||||
}
|
||||
|
||||
static centeredArray(base, show) {
|
||||
show = Math.abs(show)
|
||||
const start = base - show
|
||||
return [...Array(2 * show + 1).keys()].map(it => start + it)
|
||||
}
|
||||
|
||||
|
||||
static async create(rollData, rollOptions = {}) {
|
||||
const rollDialog = new RollDialog(rollData, rollOptions)
|
||||
rollDialog.render(true)
|
||||
@@ -267,30 +268,33 @@ export default class RollDialog extends HandlebarsApplicationMixin(ApplicationV2
|
||||
/** pre-configure les paramètres des différentes parties de la fenêtre (par exemple, prépare les listes de caractéristiques/compétences */
|
||||
$loadParts() {
|
||||
const rollData = this.rollData;
|
||||
const loadedMode = rollData.mode?.current
|
||||
rollData.current = rollData.current ?? {}
|
||||
rollData.selected = rollData.selected ?? {}
|
||||
rollData.mode = rollData.mode ?? {}
|
||||
rollData.mode.retry = rollData.mode.retry ?? false
|
||||
BASIC_PARTS.restore(rollData)
|
||||
|
||||
const loadedMode = ROLL_MODE_TABS.find(m => m.code == rollData.mode?.current)?.code
|
||||
const allowedModes = ROLL_MODE_TABS.filter(m => m.isAllowed(rollData) && m.visible(rollData)).map(m => m.code)
|
||||
|
||||
rollData.mode.allowed = rollData.mode.retry ? [loadedMode] : rollData.mode.allowed ?? ROLL_MODE_TABS.map(m => m.code)
|
||||
rollData.mode.current = loadedMode ?? ROLL_MODE_TABS.find(m => m.isAllowed(rollData) && m.visible(rollData))?.code ?? ROLL_MODE_COMP
|
||||
rollData.mode.current = allowedModes.find(m => m == rollData.mode?.current) ?? (allowedModes.length > 0 ? allowedModes[0] : ROLL_MODE_COMP)
|
||||
|
||||
this.getSelectedMode().setRollDataMode(rollData)
|
||||
|
||||
|
||||
rollData.refs = this.$prepareRefs(rollData)
|
||||
rollData.options = rollData.options ?? { showDice: true, rollMode: game.settings.get("core", "rollMode") }
|
||||
|
||||
|
||||
ROLL_PARTS.forEach(p => p.initialize(rollData))
|
||||
ROLL_PARTS.forEach(p => p.restore(rollData))
|
||||
ROLL_PARTS.filter(p => p.isValid(rollData))
|
||||
.forEach(p => {
|
||||
p.loadRefs(rollData)
|
||||
p.prepareContext(rollData)
|
||||
})
|
||||
.forEach(p => {
|
||||
p.loadRefs(rollData)
|
||||
p.prepareContext(rollData)
|
||||
})
|
||||
this.selectMode();
|
||||
}
|
||||
|
||||
|
||||
selectMode() {
|
||||
this.rollData.mode.label = this.getSelectedMode().title(this.rollData)
|
||||
this.getSelectedMode().setRollDataMode(this.rollData)
|
||||
@@ -360,7 +364,7 @@ export default class RollDialog extends HandlebarsApplicationMixin(ApplicationV2
|
||||
this.setModeTitle()
|
||||
|
||||
const visibleRollParts = this.getActiveParts()
|
||||
visibleRollParts.forEach(p => p.setExternalFilter(visibleRollParts, rollData))
|
||||
visibleRollParts.forEach(p => p.applyExternalImpacts(visibleRollParts, rollData))
|
||||
|
||||
this.setSpecialComp(visibleRollParts);
|
||||
|
||||
|
Reference in New Issue
Block a user