Action Refactor Part #1

This commit is contained in:
Dapoolp 2025-07-22 20:35:11 +02:00
parent 42a705a870
commit 5243260b4d
23 changed files with 435 additions and 248 deletions

View file

@ -23,6 +23,23 @@ export default class DhpActor extends Actor {
return this.system.metadata.isNPC;
}
/** @inheritDoc */
getEmbeddedDocument(embeddedName, id, options) {
let doc;
switch ( embeddedName ) {
case "Action":
doc = this.system.actions?.get(id);
if(!doc && this.system.attack?.id === id) doc = this.system.attack;
break;
default:
return super.getEmbeddedDocument(embeddedName, id, options);
}
if ( options?.strict && !doc ) {
throw new Error(`The key ${id} does not exist in the ${embeddedName} Collection`);
}
return doc;
}
async _preCreate(data, options, user) {
if ((await super._preCreate(data, options, user)) === false) return false;

View file

@ -9,6 +9,23 @@ export default class DHItem extends foundry.documents.Item {
for (const action of this.system.actions ?? []) action.prepareData();
}
/** @inheritDoc */
getEmbeddedDocument(embeddedName, id, options) {
let doc;
switch ( embeddedName ) {
case "Action":
doc = this.system.actions?.get(id);
if(!doc && this.system.attack?.id === id) doc = this.system.attack;
break;
default:
return super.getEmbeddedDocument(embeddedName, id, options);
}
if ( options?.strict && !doc ) {
throw new Error(`The key ${id} does not exist in the ${embeddedName} Collection`);
}
return doc;
}
/**
* @inheritdoc
* @param {object} options - Options which modify the getRollData method.

View file

@ -9,7 +9,7 @@ export default class DhTooltipManager extends foundry.helpers.interaction.Toolti
const actionId = splitValues.length > 1 ? splitValues[1] : null;
const baseItem = await foundry.utils.fromUuid(itemUuid);
const item = actionId ? baseItem.system.actions.find(x => x.id === actionId) : baseItem;
const item = actionId ? baseItem.system.actions.get(actionId) : baseItem;
if (item) {
const type = actionId ? 'action' : item.type;
const description = await TextEditor.enrichHTML(item.system.description);