diff --git a/module/applications/sheets-configs/action-base-config.mjs b/module/applications/sheets-configs/action-base-config.mjs index c75bc585..76965275 100644 --- a/module/applications/sheets-configs/action-base-config.mjs +++ b/module/applications/sheets-configs/action-base-config.mjs @@ -29,7 +29,8 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2) removeElement: this.removeElement, editEffect: this.editEffect, addDamage: this.addDamage, - removeDamage: this.removeDamage + removeDamage: this.removeDamage, + editDoc: this.editDoc }, form: { handler: this.updateForm, @@ -216,12 +217,33 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2) static removeElement(event, button) { event.stopPropagation(); const data = this.action.toObject(), - key = event.target.closest('[data-key]').dataset.key, - index = button.dataset.index; + key = event.target.closest('[data-key]').dataset.key; + + // Prefer explicit index, otherwise find by uuid + let index = button?.dataset.index; + if (index === undefined || index === null || index === '') { + const uuid = button?.dataset.uuid ?? button?.dataset.itemUuid; + index = data[key].findIndex(e => (e?.actorUUID ?? e?.uuid) === uuid); + if (index === -1) return; + } else index = Number(index); + data[key].splice(index, 1); this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(data) }); } + static async editDoc(event, button) { + event.stopPropagation(); + const uuid = button?.dataset.itemUuid ?? button?.dataset.uuid; // Obtain uuid from dataset + if (!uuid) return; + //Try catching errors + try { + const doc = await foundry.utils.fromUuid(uuid); + if (doc?.sheet) return doc.sheet.render({ force: true }); + } catch (err) { + console.warn("editDoc action failed for", uuid, err); + } + } + static addDamage(_event) { if (!this.action.damage.parts) return; const data = this.action.toObject(), @@ -259,7 +281,17 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2) } //Add to summon array const actionData = this.action.toObject(); // Get current action data - actionData.summon.push({ actorUUID: data.uuid, count: 1 });// Add new summon entry + //checking to see if actor is already in summon list add 1 to count instead of adding new entry + let countvalue = 1; + for (const entry of actionData.summon) { + if (entry.actorUUID === data.uuid) { + entry.count += 1; + countvalue = entry.count; + await this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(actionData) }); + return; + } + } + actionData.summon.push({ actorUUID: data.uuid, count: countvalue });// Add new summon entry await this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(actionData) }); // Update the form with new data } diff --git a/templates/actionTypes/summon.hbs b/templates/actionTypes/summon.hbs index 278037fb..d313fb4c 100644 --- a/templates/actionTypes/summon.hbs +++ b/templates/actionTypes/summon.hbs @@ -35,6 +35,7 @@ data-action='removeElement' data-target="summon" data-uuid="{{entry.uuid}}" + data-index="{{index}}" data-tooltip='{{localize "CONTROLS.CommonDelete"}}' > diff --git a/templates/sheets-settings/action-settings/configuration.hbs b/templates/sheets-settings/action-settings/configuration.hbs index 48b08ded..5bd29e39 100644 --- a/templates/sheets-settings/action-settings/configuration.hbs +++ b/templates/sheets-settings/action-settings/configuration.hbs @@ -3,7 +3,6 @@ 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)}} diff --git a/templates/sheets-settings/action-settings/effect.hbs b/templates/sheets-settings/action-settings/effect.hbs index bf2f3aa1..e94f4328 100644 --- a/templates/sheets-settings/action-settings/effect.hbs +++ b/templates/sheets-settings/action-settings/effect.hbs @@ -9,5 +9,6 @@ {{#if fields.macro}}{{> 'systems/daggerheart/templates/actionTypes/macro.hbs' fields=fields.macro source=source.macro}}{{/if}} {{#if fields.effects}}{{> 'systems/daggerheart/templates/actionTypes/effect.hbs' fields=fields.effects.element.fields source=source.effects}}{{/if}} {{#if fields.beastform}}{{> 'systems/daggerheart/templates/actionTypes/beastform.hbs' fields=fields.beastform.fields source=source.beastform}}{{/if}} + {{#if fields.summon}}{{> 'systems/daggerheart/templates/actionTypes/summon.hbs' fields=fields.summon.element.fields source=source.summon}}{{/if}} {{#if fields.countdown}}{{> 'systems/daggerheart/templates/actionTypes/countdown.hbs' fields=fields.countdown.element.fields source=source.countdown}}{{/if}} \ No newline at end of file