From 13753295411339e1de76b4aea2f5a73a9d271173 Mon Sep 17 00:00:00 2001 From: Nikhil Nagarajan Date: Mon, 5 Jan 2026 14:34:24 -0500 Subject: [PATCH] HBS idea formed. Need to recheck drag drop implementation --- lang/en.json | 3 +- .../sheets-configs/action-base-config.mjs | 2 +- .../sheets-configs/action-settings-config.mjs | 61 +++++++++++++++++++ module/data/action/summonAction.mjs | 31 ++++++++-- module/systemRegistration/handlebars.mjs | 1 + templates/actionTypes/summon.hbs | 53 ++++++++++++---- .../action-settings/configuration.hbs | 3 +- 7 files changed, 133 insertions(+), 21 deletions(-) diff --git a/lang/en.json b/lang/en.json index a000beca..fa0efe8b 100755 --- a/lang/en.json +++ b/lang/en.json @@ -125,7 +125,8 @@ "summon":{ "addSummonEntry": "Add Summon Entry", "actorUUID": "Actor to Summon", - "count": "Count" + "count": "Count", + "hint": "Add Actor(s) and the quantity to summon under this action." } } }, diff --git a/module/applications/sheets-configs/action-base-config.mjs b/module/applications/sheets-configs/action-base-config.mjs index 96790a5b..6a23f538 100644 --- a/module/applications/sheets-configs/action-base-config.mjs +++ b/module/applications/sheets-configs/action-base-config.mjs @@ -85,7 +85,7 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2) } }; - static CLEAN_ARRAYS = ['damage.parts', 'cost', 'effects']; + static CLEAN_ARRAYS = ['damage.parts', 'cost', 'effects','summon']; _getTabs(tabs) { for (const v of Object.values(tabs)) { diff --git a/module/applications/sheets-configs/action-settings-config.mjs b/module/applications/sheets-configs/action-settings-config.mjs index 91b85802..47168f93 100644 --- a/module/applications/sheets-configs/action-settings-config.mjs +++ b/module/applications/sheets-configs/action-settings-config.mjs @@ -6,10 +6,13 @@ export default class DHActionSettingsConfig extends DHActionBaseConfig { this.effects = effects; this.sheetUpdate = sheetUpdate; + + this._dragDrop = this._createDragDropHandlers(); } static DEFAULT_OPTIONS = { ...DHActionBaseConfig.DEFAULT_OPTIONS, + dragDrop: [{ dragSelector: null, dropSelector: '.summon-actor-drop' }], actions: { ...DHActionBaseConfig.DEFAULT_OPTIONS.actions, addEffect: this.addEffect, @@ -18,8 +21,23 @@ export default class DHActionSettingsConfig extends DHActionBaseConfig { } }; + _createDragDropHandlers() { + return this.options.dragDrop.map(d => { + d.callbacks = { + drop: this._onDrop.bind(this) + }; + return new foundry.applications.ux.DragDrop.implementation(d); + }); + } + async _prepareContext(options) { const context = await super._prepareContext(options); + const summonData = this.action.summon || []; + context.summonActors = await Promise.all(summonData.map(async (entry) => { + if (!entry.actorUUID) return null; + const actor = await fromUuid(entry.actorUUID); + return actor ? { name: actor.name, img: actor.img } : { name: "Unknown", img: "icons/svg/mystery-man.svg" }; + })); context.effects = this.effects; context.getEffectDetails = this.getEffectDetails.bind(this); @@ -63,4 +81,47 @@ export default class DHActionSettingsConfig extends DHActionBaseConfig { this.effects = await this.sheetUpdate(this.action.toObject(), { ...updatedEffect, id }); this.render(); } + + //For drag drop implementation for summon actor selection + _onRender(context, options) { + super._onRender(context, options); + this._dragDrop.forEach(d => d.bind(this.element)); + } + + async _onDrop(event) { + const data = TextEditor.getDragEventData(event); + console.log("Daggerheart | Summon Drop Data:", data); + + if (!data || !data.uuid) return; + + const doc = await fromUuid(data.uuid); + if (!doc) return; + + + let actorUuid = null; + + if (doc.documentName === "Actor") { + actorUuid = doc.uuid; + } else if (doc.documentName === "Token" && doc.actor) { + actorUuid = doc.actor.uuid; + } else { + console.warn("Daggerheart | Dropped document is not an Actor:", doc); + return; + } + + const dropZone = event.target.closest('.summon-actor-drop'); + if (!dropZone) return; + + const index = Number(dropZone.dataset.index); + + const actionData = this.action.toObject(); + if (!actionData.summon) actionData.summon = []; + + if (actionData.summon[index]) { + actionData.summon[index].actorUUID = actorUuid; + + // Trigger update + this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(actionData) }); + } + } } diff --git a/module/data/action/summonAction.mjs b/module/data/action/summonAction.mjs index 246b043d..c90c3030 100644 --- a/module/data/action/summonAction.mjs +++ b/module/data/action/summonAction.mjs @@ -6,18 +6,25 @@ export default class DHSummonAction extends DHBaseAction { const fields = foundry.data.fields; return { ...super.defineSchema(), - tokenArray: new fields.ArrayField(new fields.SchemaField({ + 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 }) - }), { required: false }) + count: new fields.NumberField({ required: true, default: 1, min: 1, integer: true }) + }), { required: false, initial: [] }) + }; + } + + get defaultValues() { + return { + summon: { actorUUID: "", count: 1 } }; } async trigger(event, ...args) { if (!this.canSummon || !canvas.scene){ - ui.notifications.error(game.i18n.localize("DAGGERHEART.ACTIONS.TYPES.summon.error")); + ui.notifications.warn(game.i18n.localize("DAGGERHEART.ACTIONS.TYPES.summon.error")); return; } + await this._performAction(); } get canSummon() { @@ -31,6 +38,18 @@ export default class DHSummonAction extends DHBaseAction { //Logic to perform the summon action - incomplete implementation async _performAction(event, ...args) { - return this.summonManager.summonTokens(this.tokenArray); - } + const validSummons = this.summon.filter(entry => entry.actorUUID); + if (validSummons.length === 0) { + ui.notifications.warn("No actors configured for this Summon action."); + return; + } + // FOR NOW: Just log the data to prove the schema working or not + console.group("Summon Action Triggered"); + + for (const entry of validSummons) { + const actor = await fromUuid(entry.actorUUID); + console.log(`- Ready to summon ${entry.count}x [${actor?.name || "Unknown Actor"}]`); + } + console.groupEnd(); + } } diff --git a/module/systemRegistration/handlebars.mjs b/module/systemRegistration/handlebars.mjs index 32e047fd..97769181 100644 --- a/module/systemRegistration/handlebars.mjs +++ b/module/systemRegistration/handlebars.mjs @@ -32,6 +32,7 @@ export const preloadHandlebarsTemplates = async function () { 'systems/daggerheart/templates/actionTypes/effect.hbs', 'systems/daggerheart/templates/actionTypes/beastform.hbs', 'systems/daggerheart/templates/actionTypes/countdown.hbs', + 'systems/daggerheart/templates/actionTypes/summon.hbs', 'systems/daggerheart/templates/settings/components/settings-item-line.hbs', 'systems/daggerheart/templates/ui/tooltip/parts/tooltipChips.hbs', 'systems/daggerheart/templates/ui/tooltip/parts/tooltipTags.hbs', diff --git a/templates/actionTypes/summon.hbs b/templates/actionTypes/summon.hbs index 3a079db5..aabe094d 100644 --- a/templates/actionTypes/summon.hbs +++ b/templates/actionTypes/summon.hbs @@ -1,14 +1,43 @@ -
- {{localize "DAGGERHEART.ACTIONS.TYPES.summon.name"}} -

{{localize "DAGGERHEART.ACTIONS.Settings.summonHint"}}

-
- {{#each source.tokenArray}} -
- {{formField ../fields.documentUUID label=DAGGERHEART.ACTIONS.Settings.summon.actorUUID name="tokenArray.{{@index}}.actorUUID" value=this.actorUUID documentType="Actor"}} - {{formField ../fields.number label=DAGGERHEART.ACTIONS.Settings.summon.count name="tokenArray.{{@index}}.count" value=this.count min=1}} - +
+ + {{localize "DAGGERHEART.ACTIONS.TYPES.summon.name"}} + + +

{{localize "DAGGERHEART.ACTIONS.Settings.summon.hint"}}

+ {{#each source as |entry index|}} +
+ + {{!-- Actor --}} +
+ {{#if entry.actorUUID}} + {{!-- Filled State --}} + {{#with (lookup @root.summonActors index) as |actor|}} +
+ + {{actor.name}} + {{!-- Hidden input to store the actual value --}} + +
+ {{/with}} + {{else}} + {{!-- Empty State --}} +
+ {{localize "DAGGERHEART.GENERAL.missingDragDropThing" thing=(localize "Actor")}} + +
+ {{/if}}
- {{/each}} - -
+ + {{!-- Count --}} + {{formField ../fields.count + label="DAGGERHEART.ACTIONS.Settings.summon.count" + name=(concat "summon." index ".count") + value=entry.count + min=1 + localize=true}} + {{!-- Obtained idea from cost.hbs --}} + + +
+ {{/each}}
\ No newline at end of file diff --git a/templates/sheets-settings/action-settings/configuration.hbs b/templates/sheets-settings/action-settings/configuration.hbs index 51b2a72b..48b08ded 100644 --- a/templates/sheets-settings/action-settings/configuration.hbs +++ b/templates/sheets-settings/action-settings/configuration.hbs @@ -2,7 +2,8 @@ class="tab {{this.tabs.config.cssClass}}" data-group="primary" data-tab="config" -> +> + {{#if fields.summon}}{{> 'systems/daggerheart/templates/actionTypes/summon.hbs' fields=fields.summon.element.fields source=source.summon}}{{/if}} {{> 'systems/daggerheart/templates/actionTypes/uses.hbs' fields=fields.uses.fields source=source.uses}} {{> 'systems/daggerheart/templates/actionTypes/cost.hbs' fields=fields.cost.element.fields source=source.cost costOptions=costOptions}} {{> 'systems/daggerheart/templates/actionTypes/range-target.hbs' fields=(object range=fields.range target=fields.target.fields) source=(object target=source.target range=source.range)}}