diff --git a/lang/en.json b/lang/en.json index 49196f50..e903ee5c 100755 --- a/lang/en.json +++ b/lang/en.json @@ -20,6 +20,11 @@ } }, "DAGGERHEART": { + "UI": { + "notifications": { + "adversaryMissing": "The linked adversary doesn't exist in the world." + } + }, "Settings": { "Menu": { "Automation": { diff --git a/module/applications/sheets/actors/environment.mjs b/module/applications/sheets/actors/environment.mjs index 1440bb4e..dc0da8e9 100644 --- a/module/applications/sheets/actors/environment.mjs +++ b/module/applications/sheets/actors/environment.mjs @@ -12,7 +12,6 @@ export default class DhpEnvironment extends DaggerheartSheet(ActorSheetV2) { actions: { addAdversary: this.addAdversary, deleteProperty: this.deleteProperty, - viewAdversary: this.viewAdversary, openSettings: this.openSettings, useItem: this.useItem, toChat: this.toChat @@ -103,14 +102,24 @@ export default class DhpEnvironment extends DaggerheartSheet(ActorSheetV2) { this.render(); } - static async viewAdversary(_, button) { - const adversary = await foundry.utils.fromUuid(button.dataset.adversary); + async viewAdversary(_, button) { + const target = button.closest('[data-item-uuid]'); + const adversary = await foundry.utils.fromUuid(target.dataset.itemUuid); + if (!adversary) { + ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.notifications.adversaryMissing')); + return; + } + adversary.sheet.render(true); } - static async useItem(event) { + static async useItem(event, button) { const action = this.getAction(event); - action.use(event); + if (!action) { + await this.viewAdversary(event, button); + } else { + action.use(event); + } } static async toChat(event) { diff --git a/module/applications/sheets/applications/environment-settings.mjs b/module/applications/sheets/applications/environment-settings.mjs index 1f3c33c8..fa58893b 100644 --- a/module/applications/sheets/applications/environment-settings.mjs +++ b/module/applications/sheets/applications/environment-settings.mjs @@ -181,13 +181,20 @@ export default class DHEnvironmentSettings extends HandlebarsApplicationMixin(Ap static async #viewAdversary(_, button) { const adversary = await foundry.utils.fromUuid(button.dataset.adversary); + if (!adversary) { + ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.notifications.adversaryMissing')); + return; + } + adversary.sheet.render(true); } static async #deleteAdversary(event, target) { const adversaryKey = target.dataset.adversary; const path = `system.potentialAdversaries.${target.dataset.potentialAdversary}.adversaries`; - const newAdversaries = foundry.utils.getProperty(this.actor, path).filter(x => x.uuid !== adversaryKey); + const newAdversaries = foundry.utils + .getProperty(this.actor, path) + .filter(x => x && (x?.uuid ?? x) !== adversaryKey); await this.actor.update({ [path]: newAdversaries }); this.render(); } diff --git a/templates/sheets/global/partials/inventory-item.hbs b/templates/sheets/global/partials/inventory-item.hbs index 7c91f032..b69f1a2d 100644 --- a/templates/sheets/global/partials/inventory-item.hbs +++ b/templates/sheets/global/partials/inventory-item.hbs @@ -1,4 +1,4 @@ -