diff --git a/module/applications/sheets/actors/character.mjs b/module/applications/sheets/actors/character.mjs index 5de6a5fb..199e6de0 100644 --- a/module/applications/sheets/actors/character.mjs +++ b/module/applications/sheets/actors/character.mjs @@ -23,11 +23,8 @@ export default class CharacterSheet extends DHBaseActorSheet { makeDeathMove: CharacterSheet.#makeDeathMove, levelManagement: CharacterSheet.#levelManagement, toggleEquipItem: CharacterSheet.#toggleEquipItem, - useItem: this.useItem, //TODO Fix this - useAction: this.useAction, - toggleResourceDice: this.toggleResourceDice, - handleResourceDice: this.handleResourceDice, - toChat: this.toChat + toggleResourceDice: CharacterSheet.#toggleResourceDice, + handleResourceDice: CharacterSheet.#handleResourceDice, }, window: { resizable: true @@ -505,22 +502,21 @@ export default class CharacterSheet extends DHBaseActorSheet { /* -------------------------------------------- */ /* Application Listener Actions */ /* -------------------------------------------- */ + async updateItemResource(event) { - const item = this.getItem(event.currentTarget); + const item = getDocFromElement(event.currentTarget); if (!item) return; const max = item.system.resource.max ? itemAbleRollParse(item.system.resource.max, this.document, item) : null; const value = max ? Math.min(Number(event.currentTarget.value), max) : event.currentTarget.value; await item.update({ 'system.resource.value': value }); - this.render(); } async updateItemQuantity(event) { - const item = this.getItem(event.currentTarget); + const item = getDocFromElement(event.currentTarget); if (!item) return; await item.update({ 'system.quantity': event.currentTarget.value }); - this.render(); } /* -------------------------------------------- */ @@ -641,53 +637,18 @@ export default class CharacterSheet extends DHBaseActorSheet { await doc?.update({ 'system.inVault': !doc.system.inVault }); } - /** - * Use a item - * @type {ApplicationClickAction} - */ - static async useItem(event, button) { - const item = this.getItem(button); - if (!item) return; - - // Should dandle its actions. Or maybe they'll be separate buttons as per an Issue on the board - if (item.type === 'feature') { - item.use(event); - } else if (item instanceof ActiveEffect) { - item.toChat(this); - } else { - const wasUsed = await item.use(event); - if (wasUsed && item.type === 'weapon') { - Hooks.callAll(CONFIG.DH.HOOKS.characterAttack, {}); - } - } - } - - /** - * Use an action - * @type {ApplicationClickAction} - */ - static async useAction(event, button) { - const item = this.getItem(button); - if (!item) return; - - const action = item.system.actions.find(x => x.id === button.dataset.actionId); - if (!action) return; - - action.use(event); - } - /** * Toggle the used state of a resource dice. * @type {ApplicationClickAction} */ - static async toggleResourceDice(event) { - const target = event.target.closest('.item-resource'); - const item = this.getItem(event); - if (!item) return; + static async #toggleResourceDice(event, target) { + const item = getDocFromElement(target); + + const { dice } = event.target.closest('.item-resource').dataset; + const diceState = item.system.resource.diceStates[dice]; - const diceState = item.system.resource.diceStates[target.dataset.dice]; await item.update({ - [`system.resource.diceStates.${target.dataset.dice}.used`]: diceState?.used ? !diceState.used : true + [`system.resource.diceStates.${dice}.used`]: !diceState.used }); } @@ -695,8 +656,8 @@ export default class CharacterSheet extends DHBaseActorSheet { * Handle the roll values of resource dice. * @type {ApplicationClickAction} */ - static async handleResourceDice(event) { - const item = this.getItem(event); + static async #handleResourceDice(_, target) { + const item = getDocFromElement(target); if (!item) return; const rollValues = await game.system.api.applications.dialogs.ResourceDiceDialog.create(item, this.document); @@ -708,41 +669,11 @@ export default class CharacterSheet extends DHBaseActorSheet { return acc; }, {}) }); - this.render(); - } - - /** - * Send item to Chat - * @type {ApplicationClickAction} - */ - static async toChat(event, button) { - if (button?.dataset?.type === 'experience') { - const experience = this.document.system.experiences[button.dataset.uuid]; - const cls = getDocumentClass('ChatMessage'); - const systemData = { - name: game.i18n.localize('DAGGERHEART.GENERAL.Experience.single'), - description: `${experience.name} ${experience.value.signedString()}` - }; - const msg = new cls({ - type: 'abilityUse', - user: game.user.id, - system: systemData, - content: await foundry.applications.handlebars.renderTemplate( - 'systems/daggerheart/templates/ui/chat/ability-use.hbs', - systemData - ) - }); - - cls.create(msg.toObject()); - } else { - const item = this.getItem(event); - if (!item) return; - item.toChat(this.document.id); - } + //this.render(); } async _onDragStart(event) { - const item = this.getItem(event); + const item = getDocFromElement(event.target); const dragData = { type: item.documentName, diff --git a/module/applications/sheets/api/application-mixin.mjs b/module/applications/sheets/api/application-mixin.mjs index e27ae7a6..3c177241 100644 --- a/module/applications/sheets/api/application-mixin.mjs +++ b/module/applications/sheets/api/application-mixin.mjs @@ -82,6 +82,7 @@ export default function DHApplicationMixin(Base) { deleteDoc: DHSheetV2.#deleteDoc, toChat: DHSheetV2.#toChat, useItem: DHSheetV2.#useItem, + useAction: DHSheetV2.#useAction, toggleEffect: DHSheetV2.#toggleEffect, }, contextMenus: [{ @@ -485,17 +486,29 @@ export default function DHApplicationMixin(Base) { */ static async #useItem(event, target) { let doc = getDocFromElement(target); - // TODO: REDO this if (!doc) { const { actionId } = target.closest('[data-action-id]').dataset; const { actions, attack } = this.document.system; - doc = attack.id === actionId ? attack : actions?.find(a => a.id === actionId); + doc = attack?.id === actionId ? attack : actions?.find(a => a.id === actionId); } await doc.use(event); } + /** + * Use a item + * @type {ApplicationClickAction} + */ + static async #useAction(event, target) { + const doc = getDocFromElement(target); + const { actionId } = target.closest('[data-action-id]').dataset; + const { actions, attack } = doc.system; + const action = attack?.id === actionId ? attack : actions?.find(a => a.id === actionId); + await action.use(event); + } + + /** * Toggle a ActiveEffect * @type {ApplicationClickAction} diff --git a/module/applications/sheets/api/base-item.mjs b/module/applications/sheets/api/base-item.mjs index b8ef102f..3d677ef8 100644 --- a/module/applications/sheets/api/base-item.mjs +++ b/module/applications/sheets/api/base-item.mjs @@ -26,7 +26,6 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) { removeFeature: DHBaseItemSheet.#removeFeature, addResource: DHBaseItemSheet.#addResource, removeResource: DHBaseItemSheet.#removeResource - addFeature: DHBaseItemSheet.#addFeature }, dragDrop: [ { dragSelector: null, dropSelector: '.tab.features .drop-section' }, diff --git a/module/helpers/handlebarsHelper.mjs b/module/helpers/handlebarsHelper.mjs index 407f065e..4193bc37 100644 --- a/module/helpers/handlebarsHelper.mjs +++ b/module/helpers/handlebarsHelper.mjs @@ -8,10 +8,10 @@ export default class RegisterHandlebarsHelpers { times: this.times, damageFormula: this.damageFormula, damageSymbols: this.damageSymbols, - rollParsed: this.rollParsed + rollParsed: this.rollParsed, + hasProperty: foundry.utils.hasProperty, }); } - static add(a, b) { const aNum = Number.parseInt(a); const bNum = Number.parseInt(b); diff --git a/templates/sheets/actors/adversary/effects.hbs b/templates/sheets/actors/adversary/effects.hbs index ad14895d..325610e6 100644 --- a/templates/sheets/actors/adversary/effects.hbs +++ b/templates/sheets/actors/adversary/effects.hbs @@ -6,6 +6,7 @@ isGlassy=true collection=effects.actives canCreate=true + hideResources=true }} {{> 'daggerheart.inventory-items' @@ -14,5 +15,6 @@ isGlassy=true collection=effects.inactives canCreate=true + hideResources=true }} \ No newline at end of file diff --git a/templates/sheets/actors/adversary/features.hbs b/templates/sheets/actors/adversary/features.hbs index 1a379802..e5a304ef 100644 --- a/templates/sheets/actors/adversary/features.hbs +++ b/templates/sheets/actors/adversary/features.hbs @@ -7,6 +7,7 @@ collection=document.system.features hideControls=true canCreate=true + showActions=true }} \ No newline at end of file diff --git a/templates/sheets/actors/adversary/sidebar.hbs b/templates/sheets/actors/adversary/sidebar.hbs index 818e1cdd..ef13efd4 100644 --- a/templates/sheets/actors/adversary/sidebar.hbs +++ b/templates/sheets/actors/adversary/sidebar.hbs @@ -84,6 +84,7 @@ hideTags=true hideDescription=true hideTooltip=true + hideResources=true }} diff --git a/templates/sheets/actors/character/effects.hbs b/templates/sheets/actors/character/effects.hbs index bf2d1d76..4c4fca27 100644 --- a/templates/sheets/actors/character/effects.hbs +++ b/templates/sheets/actors/character/effects.hbs @@ -7,6 +7,7 @@ isGlassy=true collection=effects.actives canCreate=true + hideResources=true }} {{> 'daggerheart.inventory-items' @@ -15,5 +16,6 @@ isGlassy=true collection=effects.inactives canCreate=true + hideResources=true }} \ No newline at end of file diff --git a/templates/sheets/actors/character/features.hbs b/templates/sheets/actors/character/features.hbs index befa4ae8..bc709d83 100644 --- a/templates/sheets/actors/character/features.hbs +++ b/templates/sheets/actors/character/features.hbs @@ -9,6 +9,7 @@ type='feature' collection=category.values canCreate=true + showActions=true }} {{/if}} diff --git a/templates/sheets/actors/character/inventory.hbs b/templates/sheets/actors/character/inventory.hbs index 3238edae..9610d8e2 100644 --- a/templates/sheets/actors/character/inventory.hbs +++ b/templates/sheets/actors/character/inventory.hbs @@ -19,6 +19,7 @@ collection=document.itemTypes.weapon isGlassy=true canCreate=true + hideResources=true }} {{> 'daggerheart.inventory-items' title='TYPES.Item.armor' @@ -26,6 +27,7 @@ collection=document.itemTypes.armor isGlassy=true canCreate=true + hideResources=true }} {{> 'daggerheart.inventory-items' title='TYPES.Item.consumable' diff --git a/templates/sheets/actors/character/sidebar.hbs b/templates/sheets/actors/character/sidebar.hbs index 04df553b..f5109d72 100644 --- a/templates/sheets/actors/character/sidebar.hbs +++ b/templates/sheets/actors/character/sidebar.hbs @@ -88,6 +88,7 @@ type=item.type hideTags=true hideDescription=true + hideResources=true }} {{/if}} {{/each}} @@ -106,6 +107,7 @@ type='domainCard' hideTags=true hideDescription=true + hideResources=true }} {{/each}} diff --git a/templates/sheets/actors/companion/effects.hbs b/templates/sheets/actors/companion/effects.hbs index 007d2041..325610e6 100644 --- a/templates/sheets/actors/companion/effects.hbs +++ b/templates/sheets/actors/companion/effects.hbs @@ -6,7 +6,7 @@ isGlassy=true collection=effects.actives canCreate=true - + hideResources=true }} {{> 'daggerheart.inventory-items' @@ -15,5 +15,6 @@ isGlassy=true collection=effects.inactives canCreate=true + hideResources=true }} \ No newline at end of file diff --git a/templates/sheets/actors/environment/features.hbs b/templates/sheets/actors/environment/features.hbs index c81fddc1..d7f10d56 100644 --- a/templates/sheets/actors/environment/features.hbs +++ b/templates/sheets/actors/environment/features.hbs @@ -10,6 +10,7 @@ collection=document.system.features hideControls=true canCreate=true + showActions=true }} \ No newline at end of file diff --git a/templates/sheets/actors/environment/potentialAdversaries.hbs b/templates/sheets/actors/environment/potentialAdversaries.hbs index 9783972a..cc246312 100644 --- a/templates/sheets/actors/environment/potentialAdversaries.hbs +++ b/templates/sheets/actors/environment/potentialAdversaries.hbs @@ -13,6 +13,7 @@ categoryAdversary=categoryId hideControls=true collection=category.adversaries + hideResources=true }} {{/each}} diff --git a/templates/sheets/global/partials/domain-card-item.hbs b/templates/sheets/global/partials/domain-card-item.hbs index 5932e3b4..beeb41b8 100644 --- a/templates/sheets/global/partials/domain-card-item.hbs +++ b/templates/sheets/global/partials/domain-card-item.hbs @@ -1,17 +1,23 @@ -