Fenêtres Roll V2

Maintenant disponibles pour:
- méditation
- tâches
- soins
This commit is contained in:
2025-10-05 02:24:34 +02:00
parent 47c4478303
commit fa6769fcd7
28 changed files with 359 additions and 102 deletions

View File

@@ -42,10 +42,10 @@ import ChatRollResult from "./chat-roll-result.mjs";
import { renderTemplate } from "../constants.js";
import { RollTypeCuisine } from "./roll-type-cuisine.mjs";
import { RollPartCuisine } from "./roll-part-cuisine.mjs";
import { OptionsAvancees, ROLL_DIALOG_V2_TEST } from "../settings/options-avancees.js";
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api
const doNothing = (dialog) => { }
const ALL_ROLL_TYPES = [
new RollTypeComp(),
@@ -172,6 +172,14 @@ const ROLL_PARTS = [
/* -------------------------------------------- */
export default class RollDialog extends HandlebarsApplicationMixin(ApplicationV2)
{
static onRollDoneDoNothing(dialog) {
dialog.render()
}
static onRollDoneClose(dialog) {
if (!OptionsAvancees.isUsing(ROLL_DIALOG_V2_TEST))
dialog.close()
}
static init() {
}
@@ -275,9 +283,9 @@ export default class RollDialog extends HandlebarsApplicationMixin(ApplicationV2
rollData.options = rollData.options ?? { 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.restore(rollData)
p.loadRefs(rollData)
p.prepareContext(rollData)
})
@@ -307,7 +315,7 @@ export default class RollDialog extends HandlebarsApplicationMixin(ApplicationV2
...(rollOptions.callbacks ?? [])
],
customChatMessage: rollOptions.customChatMessage,
onRollDone: rollOptions.onRollDone ?? doNothing
onRollDone: rollOptions.onRollDone ?? RollDialog.onRollDoneDoNothing
}
this.chatRollResult = new ChatRollResult();
this.selectType()
@@ -328,16 +336,16 @@ export default class RollDialog extends HandlebarsApplicationMixin(ApplicationV2
return ROLL_PARTS.filter(p => p.isActive(rollData))
}
// get title() {
// return this.rollData.title ?? `Jet de dés de ${this.rollData.active.actor.name}`
// }
rollTitle(rollData) {
return rollData.label ?? ROLL_PARTS
const title = rollData.label ?? ROLL_PARTS
.filter(it => it.section == ROLLDIALOG_SECTION.ACTION)
.filter(it => it.isActive(rollData))
.map(it => it.title(rollData))
.reduce(Misc.joining(' '))
.reduce(Misc.joining(' '));
if (this.rollOptions.title) {
return `${this.rollOptions.title} ${title}`
}
return title
}
async _onRender(context, options) {
@@ -428,15 +436,20 @@ export default class RollDialog extends HandlebarsApplicationMixin(ApplicationV2
async roll() {
const roll = RollDialog.saveParts(this.rollData)
const selectedRollType = this.getSelectedType(roll);
RollDialog.loadRollData(roll)
roll.current.resultat = this.rollData.current[PART_TRICHER]?.resultat ?? -1
roll.choix = {}
roll.rolled = await RollDialogAdapter.rollDice(roll, this.rollTitle(roll))
roll.result = this.getSelectedType(roll).getResult(roll)
roll.result = selectedRollType.getResult(roll)
console.info('RollDialog.roll:', roll)
const callbacks = [
...this.rollOptions.callbacks,
...selectedRollType.callbacks(this.rollOptions),
]
await Promise.all(callbacks.map(async callback => await callback(roll)))
await this.chatRollResult.display(roll)
await Promise.all(this.rollOptions.callbacks.map(async callback => await callback(roll)))
this.rollOptions.onRollDone(this)
}