From a47b765c6fae4b2301ba30ccd01787950d417dc5 Mon Sep 17 00:00:00 2001 From: Mike Bloy Date: Thu, 29 May 2025 00:12:41 -0500 Subject: [PATCH] start converting main power dialog to applicationv2 --- src/module/powers/basePowers.js | 49 +++++++---------- src/templates/powerDialog.html | 96 +++++++++++++++------------------ 2 files changed, 61 insertions(+), 84 deletions(-) diff --git a/src/module/powers/basePowers.js b/src/module/powers/basePowers.js index 9a9cae7..6ab60d4 100644 --- a/src/module/powers/basePowers.js +++ b/src/module/powers/basePowers.js @@ -40,52 +40,39 @@ function _hashCode(str) { return Math.abs(hash); } -export class PowerFormApplicationV2 extends HandlebarsApplicationMixin(ApplicationV2) { +export class PowerFormApplication extends HandlebarsApplicationMixin(ApplicationV2) { constructor(powerEffect) { - super(); const name = powerEffect.name.replaceAll(/[^a-zA-Z]/g, ''); - this.options.id = `${this.options.id}${name}`; + const id = `${PowerFormApplication.DEFAULT_OPTIONS.id}${name}`; + super({ id }); this.powerEffect = powerEffect; } static DEFAULT_OPTIONS = { - id: ['mbSwadePowerEffectsApplicationV2'], + id: 'mbSwadePowerEffectsApplicationV2', form: { - handler: PowerFormApplicationV2.#onSubmit, + handler: PowerFormApplication.#onSubmit, closeOnSubmit: true, }, tag: 'form', position: { - width: 400, + width: 600, height: 'auto', }, + classes: ['sheet', 'mbSwadeForm', 'mbSwadePowerEffectsForm'], window: { - icon: 'fas fa-gear', + icon: 'fa-solid fa-hand-sparkles', title: 'mbSwade.powerEffectsForm.title', }, }; - static #onSubmit(event, form, formData) {} -} - -export class PowerFormApplication extends FormApplication { - constructor(powerEffect) { - super(); - const name = powerEffect.name.replaceAll(/[^a-zA-Z]/g, ''); - this.options.id = `${this.options.id}${name}`; - this.powerEffect = powerEffect; - } - - static get defaultOptions() { - return foundry.utils.mergeObject(super.defaultOptions, { - classes: ['sheet', 'mbSwadeForm', 'mbSwadePowerEffectsForm'], - popOut: true, - template: templates['powerDialog.html'], - id: ['mbSwadePowerEffectsApplication'], - title: 'Power Effects', - width: 400, - }); - } + static PARTS = { + body: { template: templates['powerDialog.html'] }, + footer: { + template: 'templates/generic/form-footer.hbs', + classes: ['sheet-footer', 'flexrow'], + }, + }; static sortMods(a, b) { if (a.isGlobal !== b.isGlobal) { @@ -100,7 +87,7 @@ export class PowerFormApplication extends FormApplication { return a.name === b.name ? 0 : a.name < b.name ? -1 : 1; } - getData() { + _prepareContext() { let modifiers = foundry.utils.deepClone(this.powerEffect.modifiers); modifiers.sort(PowerFormApplication.sortMods); for (const modifier of modifiers) { @@ -153,8 +140,8 @@ export class PowerFormApplication extends FormApplication { return data; } - async _updateObject(ev, formData) { - formData.submit = ev?.submitter?.value ?? 'cancel'; + static async #onSubmit(event, form, formData) { + formData.submit = event?.submitter?.value ?? 'cancel'; if (formData.submit !== 'cancel') { this.powerEffect.formData = formData; this.powerEffect.applyEffect(); diff --git a/src/templates/powerDialog.html b/src/templates/powerDialog.html index c27bf47..cd68bfa 100644 --- a/src/templates/powerDialog.html +++ b/src/templates/powerDialog.html @@ -1,64 +1,54 @@ -
-
-  +
+
+

{{name}} Effect

Apply the affects of {{name}}.

{{#if extraDescription }} -
- {{{extraDescription}}} -
+
+ {{{extraDescription}}} +
{{/if}} {{#if basePowerPoints}} -

Base Power Points: {{basePowerPoints}} - {{/if}} - {{#if targets.length}} -

- Targets: - {{#each targets}}{{#if @index}}, {{/if}}{{{this}}}{{/each}} - {{#if recipients.cost}} -
({{#if recipients.epic}}⭐ {{/if}}{{recipients.text}} - {{recipients.cost}}pp each × {{recipients.count}} = {{recipients.total}}) - {{/if}} -

+

Base Power Points: {{basePowerPoints}} + {{/if}} + {{#if targets.length}} +

+ Targets: + {{#each targets}}{{#if @index}}, {{/if}}{{{this}}}{{/each}} + {{#if recipients.cost}} +
({{#if recipients.epic}}⭐ {{/if}}{{recipients.text}} + {{recipients.cost}}pp each × {{recipients.count}} = {{recipients.total}}) + {{/if}} +

{{/if}} {{#each modifiers}} -
- {{#if isCheckbox}} - - {{/if}} - {{#if isText}} - - - {{/if}} - {{#if isNumber}} - - - {{/if}} - {{#if isSelect}} - - - {{/if}} - {{#if isRadio}} - {{#if epic}}⭐ {{/if}}{{name}}: {{radioBoxes id choices checked=default}} - {{/if}} -
+
+ {{#if isCheckbox}} + + {{/if}} + {{#if isText}} + + + {{/if}} + {{#if isNumber}} + + + {{/if}} + {{#if isSelect}} + + + {{/if}} + {{#if isRadio}} + {{#if epic}}⭐ {{/if}}{{name}}: {{radioBoxes id choices checked=default}} + {{/if}} +
{{/each}} - - +