forked from GitHub-Mirrors/foundry-sw5e
Add files via upload
This commit is contained in:
parent
848158b9e8
commit
28ab1fb404
6 changed files with 606 additions and 0 deletions
64
module/apps/ability-use-dialog.js
Normal file
64
module/apps/ability-use-dialog.js
Normal file
|
@ -0,0 +1,64 @@
|
|||
/**
|
||||
* A specialized Dialog subclass for ability usage
|
||||
* @type {Dialog}
|
||||
*/
|
||||
export class AbilityUseDialog extends Dialog {
|
||||
constructor(item, dialogData={}, options={}) {
|
||||
super(dialogData, options);
|
||||
this.options.classes = ["sw5e", "dialog"];
|
||||
|
||||
/**
|
||||
* Store a reference to the Item entity being used
|
||||
* @type {Item5e}
|
||||
*/
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* Rendering */
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/**
|
||||
* A constructor function which displays the Power Cast Dialog app for a given Actor and Item.
|
||||
* Returns a Promise which resolves to the dialog FormData once the workflow has been completed.
|
||||
* @param {Item5e} item
|
||||
* @return {Promise}
|
||||
*/
|
||||
static async create(item) {
|
||||
|
||||
const uses = item.data.data.uses;
|
||||
const recharge = item.data.data.recharge;
|
||||
const recharges = !!recharge.value;
|
||||
|
||||
// Render the ability usage template
|
||||
const html = await renderTemplate("systems/sw5e/templates/apps/ability-use.html", {
|
||||
item: item.data,
|
||||
canUse: recharges ? recharge.charged : uses.value > 0,
|
||||
consume: true,
|
||||
uses: uses,
|
||||
recharges: !!recharge.value,
|
||||
isCharged: recharge.charged,
|
||||
hasPlaceableTemplate: game.user.can("TEMPLATE_CREATE") && item.hasAreaTarget,
|
||||
perLabel: CONFIG.SW5E.limitedUsePeriods[uses.per]
|
||||
});
|
||||
|
||||
// Create the Dialog and return as a Promise
|
||||
return new Promise((resolve) => {
|
||||
let formData = null;
|
||||
const dlg = new this(item, {
|
||||
title: `${item.name}: Ability Configuration`,
|
||||
content: html,
|
||||
buttons: {
|
||||
use: {
|
||||
icon: '<i class="fas fa-fist-raised"></i>',
|
||||
label: "Use Ability",
|
||||
callback: html => formData = new FormData(html[0].querySelector("#ability-use-form"))
|
||||
}
|
||||
},
|
||||
default: "use",
|
||||
close: () => resolve(formData)
|
||||
});
|
||||
dlg.render(true);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue