diff --git a/lang/en.json b/lang/en.json index fa0efe8b..7f359f09 100755 --- a/lang/en.json +++ b/lang/en.json @@ -70,7 +70,8 @@ "summon": { "name": "Summon", "tooltip": "Create tokens in the scene.", - "error": "You do not have permission to summon tokens or there is no active scene." + "error": "You do not have permission to summon tokens or there is no active scene.", + "invalidDrop": "You can only drop Actor entities to summon." } }, "Config": { @@ -125,6 +126,7 @@ "summon":{ "addSummonEntry": "Add Summon Entry", "actorUUID": "Actor to Summon", + "actor": "Actor", "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 6a23f538..a2a08c39 100644 --- a/module/applications/sheets-configs/action-base-config.mjs +++ b/module/applications/sheets-configs/action-base-config.mjs @@ -35,7 +35,8 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2) handler: this.updateForm, submitOnChange: true, closeOnSubmit: false - } + }, + dragDrop: [{ dragSelector: null, dropSelector: '.summon-actor-drop'}] }; static PARTS = { @@ -233,4 +234,15 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2) this.tabGroups.primary = 'base'; await super.close(options); } + + /** Implementation for dragdrop for summon actor selection **/ + async _onDrop(event) { + const data = foundry.applications.ux.TextEditor.getDragEventData(event); + const item=await foundry.utils.fromUuid(data.uuid); + if (!(item instanceof game.system.api.documents.DhpActor)) { + ui.notifications.warn(game.i18n.localize("DAGGERHEART.ACTIONS.TYPES.summon.invalidDrop")); + return; + } + } + } diff --git a/module/applications/sheets-configs/action-settings-config.mjs b/module/applications/sheets-configs/action-settings-config.mjs index 47168f93..91b85802 100644 --- a/module/applications/sheets-configs/action-settings-config.mjs +++ b/module/applications/sheets-configs/action-settings-config.mjs @@ -6,13 +6,10 @@ 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, @@ -21,23 +18,8 @@ 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); @@ -81,47 +63,4 @@ 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 c90c3030..56e0446c 100644 --- a/module/data/action/summonAction.mjs +++ b/module/data/action/summonAction.mjs @@ -1,4 +1,3 @@ -import { ui } from '../../applications/_module.mjs'; import DHBaseAction from './baseAction.mjs'; export default class DHSummonAction extends DHBaseAction { diff --git a/templates/actionTypes/summon.hbs b/templates/actionTypes/summon.hbs index aabe094d..f32486be 100644 --- a/templates/actionTypes/summon.hbs +++ b/templates/actionTypes/summon.hbs @@ -6,38 +6,8 @@

{{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}} -
- - {{!-- 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 --}} - - + {{formField ../fields.actorUUID label="DAGGERHEART.ACTIONS.Settings.summon.actor" value=entry.actorUUID name=(concat "summon." index ".actorUUID") localize=true classes="summon-actor-drop"}} + {{formField ../fields.count label="DAGGERHEART.ACTIONS.Settings.summon.count" value=entry.count name=(concat "summon." index ".count") localize=true}}
{{/each}} \ No newline at end of file