From e83202681ecddec76a6dbd33bf098fb9169f176e Mon Sep 17 00:00:00 2001 From: Nikhil Nagarajan Date: Tue, 6 Jan 2026 18:15:27 -0500 Subject: [PATCH] tbd work on summon action type --- module/applications/dialogs/summonDialog.mjs | 48 +++++++++++++++ module/data/fields/action/_module.mjs | 1 + module/data/fields/action/summonField.mjs | 61 ++++++++++++++++++++ templates/dialogs/summon/summonDialog.hbs | 24 ++++++++ 4 files changed, 134 insertions(+) create mode 100644 module/applications/dialogs/summonDialog.mjs create mode 100644 module/data/fields/action/summonField.mjs create mode 100644 templates/dialogs/summon/summonDialog.hbs diff --git a/module/applications/dialogs/summonDialog.mjs b/module/applications/dialogs/summonDialog.mjs new file mode 100644 index 00000000..c5ab7a3d --- /dev/null +++ b/module/applications/dialogs/summonDialog.mjs @@ -0,0 +1,48 @@ +const { ApplicationV2, HandlebarsApplicationMixin } = foundry.applications.api; + +export default class DHSummonDialog extends HandlebarsApplicationMixin(ApplicationV2) { + constructor(summonData) { + super(summonData); + // Initialize summons and index + this.summons = summonData.summons || []; + this.index = 0; + } + + get_title() { + return game.i18n.localize("DAGGERHEART.DIALOGS.SUMMON.title"); + } + + static DEFAULT_OPTIONS= { + ...super.DEFAULT_OPTIONS, + template: 'systems/daggerheart/module/applications/dialogs/summon/summonDialog.hbs', + width: 400, + height: 'auto', + classes: ['daggerheart', 'dialog', 'summon-dialog'], + dragDrop: [{ dragSelector: '.summon-token', dropSelector: null, handler:'onDrop'}] + }; + + async _prepareContext() { + const context = await super._prepareContext(); + context.summons=this.summons; + context.index=this.index; + return context; + } + + getData(options={}) { + const data = super.getData(options); + data.summons=this.summons; + data.index=this.index; + return data; + } + async prepareContext() { + const context = await super.prepareContext(); + return context; + } + + async onDrop(event) {//add to canvas + event.preventDefault(); + const tokenData = JSON.parse(event.dataTransfer.getData('text/plain')); + const position = { x: event.clientX, y: event.clientY }; + await canvas.scene.createEmbeddedDocuments("Token", [tokenData], { temporary: false, x: position.x, y: position.y }); + } +} \ No newline at end of file diff --git a/module/data/fields/action/_module.mjs b/module/data/fields/action/_module.mjs index ef69394a..0bdffca2 100644 --- a/module/data/fields/action/_module.mjs +++ b/module/data/fields/action/_module.mjs @@ -9,3 +9,4 @@ export { default as BeastformField } from './beastformField.mjs'; export { default as DamageField } from './damageField.mjs'; export { default as RollField } from './rollField.mjs'; export { default as MacroField } from './macroField.mjs'; +export { default as SummonField } from './summonField.mjs'; diff --git a/module/data/fields/action/summonField.mjs b/module/data/fields/action/summonField.mjs new file mode 100644 index 00000000..7bcd1145 --- /dev/null +++ b/module/data/fields/action/summonField.mjs @@ -0,0 +1,61 @@ +import DHSummonDialog from '../../../applications/dialogs/summonDialog.mjs'; + +const fields = foundry.data.fields; + +export default class DHSummonField extends fields.SchemaField { + /** + * Action Workflow order + */ + static order = 120; + + constructor(options = {}, context = {}) { + const summonFields = { + summon: new fields.ArrayField(new fields.SchemaField({ + actorUUID: new fields.DocumentUUIDField({ + type: 'Actor', + required: true }), + count: new fields.NumberField({ + required: true, + default: 1, + min: 1, + integer: true }) + }), { required: false, initial: [] }) + }; + super(summonFields, options, context); + } + + /** + * Summon Action Workflow part. + * Must be called within Action context or similar. + * @param {object} config Object that contains workflow datas. Usually made from Action Fields prepareConfig methods. + */ + static async execute(config) { + const selected = await DHSummonDialog.configure(config, this.item); + if (!selected) return false; + return await DHSummonField.summon.call(this, selected); + } + /** + * Update Action Workflow config object. + * Must be called within Action context. + * @param {object} config Object that contains workflow datas. Usually made from Action Fields prepareConfig methods. + */ + prepareConfig(config) { + if (!canvas.scene){ + ui.notifications.warn(game.i18n.localize("DAGGERHEART.ACTIONS.TYPES.summon.error")); + return false; + } + return true; + } + /** + * Logic to perform the summon action - incomplete implementation + */ + + get defaultValues() { + return { + summon: { actorUUID: "", count: 1 } + }; + } + get canSummon() { + return game.user.can('TOKEN_CREATE'); + } +} \ No newline at end of file diff --git a/templates/dialogs/summon/summonDialog.hbs b/templates/dialogs/summon/summonDialog.hbs new file mode 100644 index 00000000..9e03e129 --- /dev/null +++ b/templates/dialogs/summon/summonDialog.hbs @@ -0,0 +1,24 @@ +
+ + {{localize "DAGGERHEART.DIALOGS.Summon.title"}} + +

{{localize "DAGGERHEART.DIALOGS.Summon.hint"}}

+ +
+ {{#each summons as |entry index|}} +
    +
    + + {{#if (gte entry.count 1)}} +

    + {{entry.name}} (x{{entry.count}}) +

    + {{else}} +

    + {{entry.name}} +

    + {{/if}} +
    +
+ {{/each}} +
\ No newline at end of file