update summonCosts application

This commit is contained in:
Mike Bloy 2025-06-09 22:12:42 -05:00
parent cba485285d
commit 3187d625f0
2 changed files with 50 additions and 34 deletions

View File

@ -1,8 +1,10 @@
/* globals Sequencer */ /* globals Sequencer */
import { log, moduleHelpers, moduleName, settingKeys } from '../globals.js'; import { log, moduleName } from '../globals.js';
import { templates } from '../preloadTemplates.js'; import { templates } from '../preloadTemplates.js';
import { ActorFolderEffect } from './basePowers.js'; import { ActorFolderEffect } from './basePowers.js';
const { ApplicationV2, HandlebarsApplicationMixin } = foundry.applications.api;
export class BaseSummonEffect extends ActorFolderEffect { export class BaseSummonEffect extends ActorFolderEffect {
get name() { get name() {
return 'Base Summon'; return 'Base Summon';
@ -62,25 +64,46 @@ export class BaseSummonEffect extends ActorFolderEffect {
} }
} }
export class SummonCostApplication extends FormApplication { export class SummonCostApplication extends HandlebarsApplicationMixin(ApplicationV2) {
constructor(actors, powers) { constructor(actors, powers) {
super(); super();
this.actors = actors; this.actors = actors;
this.powers = powers; this.powers = powers;
this.object = {};
} }
static get defaultOptions() { static DEFAULT_OPTIONS = {
return foundry.utils.mergeObject(super.defaultOptions, { id: 'mbSwadeSummonCostApplication',
classes: ['sheet', 'mbSwade', 'mbSwadeForm', 'mbSwadeSummonCostForm'], form: {
popOut: true, handler: SummonCostApplication.#onSubmit,
closeOnSubmit: true,
},
tag: 'form',
position: {
width: 800,
height: 'auto',
},
classes: ['mbSwade', 'mbSwadeForm', 'mbSwadeSummonCostForm'],
window: {
title: 'Set Summoning Costs',
},
};
static PARTS = {
header: {
template: templates['dialogHeader.html'],
classes: ['mbSwade', 'mbSwadeDialogHeader', 'mbSwadeSummonCostsHeader'],
},
body: {
template: templates['summonCosts.html'], template: templates['summonCosts.html'],
id: ['mbSwadeSummonCostFormApplication'], classes: ['mbSwade', 'mbSwadePowerEffectsBody', 'scrollable'],
title: 'Summoning Costs', },
width: 750, footer: {
}); template: 'templates/generic/form-footer.hbs',
} },
};
getData() { async _prepareContext() {
const actorNames = Object.keys(this.actors).map((k) => { const actorNames = Object.keys(this.actors).map((k) => {
let splitName = k.split(' | '); let splitName = k.split(' | ');
splitName.pop(); splitName.pop();
@ -96,8 +119,15 @@ export class SummonCostApplication extends FormApplication {
return 0; return 0;
}); });
const data = { const data = {
name: 'Set Summon Costs',
formId: foundry.utils.randomID(),
headerTitle: 'Set Summon Costs',
powers: this.powers, powers: this.powers,
actors: [], actors: [],
buttons: [
{ type: 'submit', icon: 'fa-solid fa-save', label: 'SETTINGS.Save' },
{ type: 'cancel', icon: 'fa-solid fa-ban', label: 'SETTINGS.Cancel' },
],
}; };
for (const actor of actorNames) { for (const actor of actorNames) {
const summon = this.actors[actor.fullName].getFlag(moduleName, 'summonData') ?? { const summon = this.actors[actor.fullName].getFlag(moduleName, 'summonData') ?? {
@ -118,12 +148,13 @@ export class SummonCostApplication extends FormApplication {
return data; return data;
} }
async _updateObject(ev, formData) { static async #onSubmit(event, form, formData) {
const submit = ev?.submitter?.value ?? 'cancel'; const submit = event?.submitter?.value ?? 'cancel';
if (submit === 'cancel') { if (submit === 'cancel') {
return; return;
} }
log('FORMDATA |', formData); log('FORMDATA |', formData);
formData = formData.object;
const updates = {}; const updates = {};
for (const key of Object.keys(formData)) { for (const key of Object.keys(formData)) {
const value = formData[key]; const value = formData[key];

View File

@ -1,8 +1,4 @@
<form class='flexcol'> <section>
<!-- vim: set ft=handlebars.html:-->
<header class='sheet-header'>
<h2>Set Summon Parameters</h2>
</header>
<table class="mbForm"> <table class="mbForm">
<thead> <thead>
<tr> <tr>
@ -13,7 +9,7 @@
</tr> </tr>
<tr> <tr>
{{#each powers}} {{#each powers}}
<th>{{this}}?</th> <th>{{this}}?</th>
{{/each}} {{/each}}
</tr> </tr>
</thead> </thead>
@ -22,23 +18,12 @@
<tr> <tr>
<td>{{actor.folder}}</td> <td>{{actor.folder}}</td>
<td>{{actor.name}}</td> <td>{{actor.name}}</td>
<td><input type="number" <td><input type="number" value="{{summon.cost}}" name="{{actor.fullName}}:;:cost" step="1" min="0" /></td>
value="{{summon.cost}}"
name="{{actor.fullName}}:;:cost"
step="1"
min="0"/></td>
{{#each summon.powers}} {{#each summon.powers}}
<td align="center"><input <td align="center"><input type="checkbox" name="{{../actor.fullName}}:;:{{power}}" {{checked value}}></td>
type="checkbox"
name="{{../actor.fullName}}:;:{{power}}"
{{checked value}}></td>
{{/each}} {{/each}}
</tr> </tr>
{{/each}} {{/each}}
</tbody> </tbody>
</table> </table>
<footer class="sheet-footer flexrow"> </section>
<button type="submit" name="submit" value="submit">Submit</button>
<button type="submit" name="submit" value="cancel">Cancel</button>
</footer>
</form>