import { CrucibleUtility } from "./crucible-utility.js"; export class CrucibleRollDialog extends Dialog { /* -------------------------------------------- */ static async create(actor, rollData) { let options = { classes: ["CrucibleDialog"], width: 620, height: 480, 'z-index': 99999 }; let html = await renderTemplate('systems/fvtt-crucible-rpg/templates/roll-dialog-generic.html', rollData); return new CrucibleRollDialog(actor, rollData, html, options); } /* -------------------------------------------- */ constructor(actor, rollData, html, options, close = undefined) { let conf = { title: (rollData.mode == "skill") ? "Skill" : "Roll", content: html, buttons: { roll: { icon: '', label: "Roll !", callback: () => { this.roll() } }, cancel: { icon: '', label: "Cancel", callback: () => { this.close() } } }, close: close } super(conf, options); this.actor = actor; this.rollData = rollData; } /* -------------------------------------------- */ roll() { CrucibleUtility.rollCrucible(this.rollData) } /* -------------------------------------------- */ async refreshDialog() { const content = await renderTemplate("systems/fvtt-crucible-rpg/templates/roll-dialog-generic.html", this.rollData) this.data.content = content this.render(true) } /* -------------------------------------------- */ activateListeners(html) { super.activateListeners(html); var dialog = this; function onLoad() { } $(function () { onLoad(); }); html.find('#statDicesLevel').change((event) => { this.rollData.statDicesLevel = Number(event.currentTarget.value) }); html.find('#specDicesLevel').change(async (event) => { this.rollData.specDicesLevel = Number(event.currentTarget.value) CrucibleUtility.updateSpecDicePool(this.rollData) this.refreshDialog() }); html.find('.effect-clicked').change(async (event) => { let toggled = event.currentTarget.checked let effectIdx = $(event.currentTarget).data("effect-idx") this.manageEffects(effectIdx, toggled) this.refreshDialog() }); html.find('.armor-clicked').change((event) => { let toggled = event.currentTarget.checked let armorIdx = $(event.currentTarget).data("armor-idx") this.manageArmors(armorIdx, toggled) this.refreshDialog() }); html.find('.weapon-clicked').change((event) => { let toggled = event.currentTarget.checked let weaponIdx = $(event.currentTarget).data("weapon-idx") this.manageWeapons(weaponIdx, toggled) this.refreshDialog() }); html.find('.equip-clicked').change((event) => { let toggled = event.currentTarget.checked let equipIdx = $(event.currentTarget).data("equip-idx") this.manageEquip(equipIdx, toggled) }) html.find('.pool-add-dice').click(async (event) => { let diceKey = $(event.currentTarget).data("dice-key") let diceLevel = $(event.currentTarget).data("dice-level") CrucibleUtility.addDicePool(this.rollData, diceKey, diceLevel) this.refreshDialog() }) html.find('.pool-remove-dice').click(async (event) => { let idx = $(event.currentTarget).data("dice-idx") CrucibleUtility.removeFromDicePool(this.rollData, idx) this.refreshDialog() }) } }