import { PegasusUtility } from "./pegasus-utility.js"; export class PegasusRollDialog extends Dialog { /* -------------------------------------------- */ static async create(actor, rollData) { let options = { classes: ["PegasusDialog"], width: 620, height: 'fit-content', 'z-index': 99999 }; let html = await renderTemplate('systems/fvtt-pegasus-rpg/templates/roll-dialog-generic.html', rollData); return new PegasusRollDialog(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() { for(let i=0; i { this.rollData.selectedSpec = event.currentTarget.value let spec = this.rollData.specList.find(item => item._id == this.rollData.selectedSpec) if (spec) { this.rollData.specDicesLevel = spec.system.level this.rollData.specName = spec.name $('#specDicesLevel').val(this.rollData.specDicesLevel) } else { this.rollData.specName = undefined this.rollData.specDicesLevel = 0 $('#specDicesLevel').val(0) } PegasusUtility.updateSpecDicePool(this.rollData) this.refreshDialog() }); html.find('#statDicesLevel').change((event) => { this.rollData.statDicesLevel = Number(event.currentTarget.value) }); html.find('#specDicesLevel').change(async (event) => { if (event.currentTarget.value == "none") { this.rollData.specDicesLevel = 0 } else { this.rollData.specDicesLevel = Number(event.currentTarget.value) } PegasusUtility.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('.vehicle-weapon-clicked').change((event) => { let toggled = event.currentTarget.checked let weaponIdx = $(event.currentTarget).data("vehicle-weapon-idx") this.manageVehicleWeapon(weaponIdx, toggled) this.refreshDialog() }) html.find('.vehicle-shield-clicked').change((event) => { let toggled = event.currentTarget.checked let shieldIdx = $(event.currentTarget).data("vehicle-shield-idx") this.manageVehicleShield(shieldIdx, toggled) this.refreshDialog() }) html.find('#modifiers').change(async (event) => { let diceKey = event.currentTarget.value if ( !diceKey.includes("none")) { let diceLevel = PegasusUtility.getLevelFromDice(diceKey) PegasusUtility.addDicePool(this.rollData, diceKey, diceLevel) this.refreshDialog() } }) html.find('.pool-add-dice').click(async (event) => { let diceKey = $(event.currentTarget).data("dice-key") let diceLevel = $(event.currentTarget).data("dice-level") PegasusUtility.addDicePool(this.rollData, diceKey, diceLevel) this.refreshDialog() }) html.find('.pool-remove-dice').click(async (event) => { let idx = $(event.currentTarget).data("dice-idx") PegasusUtility.removeFromDicePool(this.rollData, idx) this.refreshDialog() }) } }