phase 1 complete

This commit is contained in:
Nikhil Nagarajan 2026-01-06 14:49:23 -05:00
parent e07d0204b2
commit 6cbe753552
4 changed files with 38 additions and 5 deletions

View file

@ -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
}

View file

@ -35,6 +35,7 @@
data-action='removeElement'
data-target="summon"
data-uuid="{{entry.uuid}}"
data-index="{{index}}"
data-tooltip='{{localize "CONTROLS.CommonDelete"}}'
>
<i class='fas fa-trash'></i>

View file

@ -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)}}

View file

@ -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}}
</section>