Utilise RdDRoll pour les caracs

ajout d'un callback dédié à l'expérience
limite de la table de résolution à 60 (rêve actuel jusqu'à 3x limite)
This commit is contained in:
2020-12-06 23:31:23 +01:00
parent 9275f61a08
commit d081dbf230
5 changed files with 109 additions and 72 deletions

View File

@ -10,22 +10,23 @@ import { RdDResolutionTable } from "./rdd-resolution-table.js";
export class RdDRoll extends Dialog {
static async create(htmlTemplate, actor, rollData, ...actions) {
RdDRoll._ensureCorrectActions(actions);
static async create(actor, rollData, dialogConfig, ...actions) {
RdDRoll._ensureCorrectActions(actions);
RdDRoll._setDefaultOptions(actor, rollData);
const html = await renderTemplate(htmlTemplate, rollData);
const html = await renderTemplate(dialogConfig.html, rollData);
return new RdDRoll(actor, rollData, html, {
classes: ["rdddialog"],
width: 600, height: 500, 'z-index': 99999
}, actions);
let options = { classes: ["rdddialog"], width: 600, height: 500, 'z-index': 99999 };
if (dialogConfig.options) {
mergeObject(options, dialogConfig.options, { overwrite: true })
}
return new RdDRoll(actor, rollData, html, options, actions);
}
static _setDefaultOptions(actor, rollData) {
mergeObject(rollData,
mergeObject(rollData,
{
ajustementsConditions: CONFIG.RDD.ajustementsConditions,
difficultesLibres: CONFIG.RDD.difficultesLibres,
@ -44,12 +45,12 @@ export class RdDRoll extends Dialog {
}
static _ensureCorrectActions(actions) {
if (actions.length==0) {
if (actions.length == 0) {
throw 'No action defined';
}
actions.forEach(action => {
if (action.callbacks == undefined) {
action.callbacks = [{action: r => console.log(action.name, r)}];
action.callbacks = [{ action: r => console.log(action.name, r) }];
}
});
}
@ -74,11 +75,11 @@ export class RdDRoll extends Dialog {
async onAction(action, html) {
await RdDResolutionTable.rollData(this.rollData);
if (action.callbacks)
for (let callback of action.callbacks) {
if (callback.condition == undefined || callback.condition(this.rollData.rolled)) {
callback.action(this.rollData);
for (let callback of action.callbacks) {
if (callback.condition == undefined || callback.condition(this.rollData)) {
callback.action(this.rollData);
}
}
}
}
/* -------------------------------------------- */