start converting main power dialog to applicationv2

This commit is contained in:
Mike Bloy 2025-05-29 00:12:41 -05:00
parent 669c3799a0
commit a47b765c6f
2 changed files with 61 additions and 84 deletions

View File

@ -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();

View File

@ -1,6 +1,6 @@
<form class="flexcol"><!-- vim: set ft=handlebars.html: -->
<header class="sheet-header flexrow">
<img src="{{icon}}" height="64" width="64" title="{{name}} Effect" alt=" " />
<div class="standard-form"><!-- vim: set ft=handlebars.html: -->
<header class="flexrow">
<img src="{{icon}}" height="64" width="64" class="flex0" title="{{name}} Effect" alt=" " />
<section class="flexcol">
<h2>{{name}} Effect</h2>
<p>Apply the affects of {{name}}.</p>
@ -39,16 +39,11 @@
{{/if}}
{{#if isNumber}}
<label for="{{id}}">{{#if epic}}⭐ {{/if}}{{name}}:</label>
<input name="{{id}}"
type="number"
value="{{default}}"
{{#if step}}step="{{step}}"{{/if}}
{{#if min}}min="{{min}}"{{/if}}
{{#if max}}max="{{max}}"{{/if}}
>
<input name="{{id}}" type="number" value="{{default}}" {{#if step}}step="{{step}}" {{/if}} {{#if min}}min="{{min}}"
{{/if}} {{#if max}}max="{{max}}" {{/if}}>
{{/if}}
{{#if isSelect}}
<label>{{#if epic}}⭐ {{/if}}{{name}}:</label>
<label for="{{id}}">{{#if epic}}⭐ {{/if}}{{name}}:</label>
<select name="{{id}}">{{selectOptions choices selected=default}}</select>
{{/if}}
{{#if isRadio}}
@ -56,9 +51,4 @@
{{/if}}
</div>
{{/each}}
<footer class="sheet-footer flexrow">
{{#each buttons}}
<button type="submit" name="submit" value="{{value}}">{{label}}</button>
{{/each}}
</footer>
</form>
</div>