From 4d965c5dc2fbac8a54636483a80586b05f5ed49e Mon Sep 17 00:00:00 2001 From: Joaquin Pereyra Date: Mon, 28 Jul 2025 23:37:19 -0300 Subject: [PATCH] FEAT: getTags and getLabels for weapons items --- module/data/item/weapon.mjs | 65 ++++++++++++++++ module/documents/item.mjs | 34 ++++++-- styles/less/global/inventory-item.less | 4 + .../global/partials/inventory-item-V2.hbs | 77 +++++++------------ 4 files changed, 124 insertions(+), 56 deletions(-) diff --git a/module/data/item/weapon.mjs b/module/data/item/weapon.mjs index 71d1e08d..0e266849 100644 --- a/module/data/item/weapon.mjs +++ b/module/data/item/weapon.mjs @@ -145,4 +145,69 @@ export default class DHWeapon extends AttachableItem { } } } + + /** + * Generates a list of localized tags based on this item's type-specific properties. + * @returns {string[]} An array of localized tag strings. + */ + getTags() { + const { attack, burden } = this; + const tags = []; + + const traitTag = game.i18n.localize(`DAGGERHEART.CONFIG.Traits.${attack.roll.trait}.name`); + const rangeTag = game.i18n.localize(`DAGGERHEART.CONFIG.Range.${attack.range}.name`); + const burdenTag = game.i18n.localize(`DAGGERHEART.CONFIG.Burden.${burden}`); + + tags.push(traitTag, rangeTag, burdenTag); + + for (const { value, type } of attack.damage.parts) { + const parts = [value.dice]; + if (value.bonus) parts.push(value.bonus.signedString()); + + if (type.size > 0) { + const typeTags = Array.from(type) + .map(t => game.i18n.localize(`DAGGERHEART.CONFIG.DamageType.${t}.abbreviation`)) + .join(" | "); + parts.push(` (${typeTags})`); // Add a space in front and put it inside a (). + } + + tags.push(parts.join("")); + } + + + return tags; + } + + /** + * Generate a localized label array for this item subtype. + * @returns {(string | { value: string, icons: string[] })[]} An array of localized strings and damage label objects. + */ + getLabels() { + const labels = []; + + const { roll, range, damage } = this.attack; + labels.push(game.i18n.localize(`DAGGERHEART.CONFIG.Traits.${roll.trait}.short`)); + labels.push(game.i18n.localize(`DAGGERHEART.CONFIG.Range.${range}.short`)); + + for (const { value, type } of damage.parts) { + const str = [value.dice]; + if (value.bonus) str.push(value.bonus.signedString()); + + const icons = Array.from(type) + .map(t => CONFIG.DH.GENERAL.damageTypes[t]?.icon) + .filter(Boolean); + + const labelValue = str.join(""); + if (icons.length === 0) { + labels.push(labelValue); + } else { + labels.push({ value: labelValue, icons }); + } + } + + return labels; + } + + + } diff --git a/module/documents/item.mjs b/module/documents/item.mjs index a05a7ff0..3e44e846 100644 --- a/module/documents/item.mjs +++ b/module/documents/item.mjs @@ -74,8 +74,8 @@ export default class DHItem extends foundry.documents.Item { isInventoryItem === true ? 'Inventory Items' //TODO localize : isInventoryItem === false - ? 'Character Items' //TODO localize - : 'Other'; //TODO localize + ? 'Character Items' //TODO localize + : 'Other'; //TODO localize return { value: type, label, group }; } @@ -96,6 +96,28 @@ export default class DHItem extends foundry.documents.Item { }); } + /* -------------------------------------------- */ + + /** + * Generate an array of localized tag. + * @returns {string[]} An array of localized tag strings. + */ + getTags() { + const tags = []; + if (this.system.getTags) tags.push(...this.system.getTags()); + return tags; + } + + /** + * Generate a localized label array for this item. + * @returns {(string | { value: string, icons: string[] })[]} An array of localized strings and damage label objects. + */ + getLabels() { + const labels = []; + if (this.system.getLabels) labels.push(...this.system.getLabels()); + return labels; + } + async use(event) { const actions = new Set(this.system.actionsList); if (actions?.size) { @@ -115,10 +137,10 @@ export default class DHItem extends foundry.documents.Item { this.type === 'ancestry' ? game.i18n.localize('DAGGERHEART.UI.Chat.foundationCard.ancestryTitle') : this.type === 'community' - ? game.i18n.localize('DAGGERHEART.UI.Chat.foundationCard.communityTitle') - : this.type === 'feature' - ? game.i18n.localize('TYPES.Item.feature') - : game.i18n.localize('DAGGERHEART.UI.Chat.foundationCard.subclassFeatureTitle'), + ? game.i18n.localize('DAGGERHEART.UI.Chat.foundationCard.communityTitle') + : this.type === 'feature' + ? game.i18n.localize('TYPES.Item.feature') + : game.i18n.localize('DAGGERHEART.UI.Chat.foundationCard.subclassFeatureTitle'), origin: origin, img: this.img, name: this.name, diff --git a/styles/less/global/inventory-item.less b/styles/less/global/inventory-item.less index 452d997b..6a820a31 100644 --- a/styles/less/global/inventory-item.less +++ b/styles/less/global/inventory-item.less @@ -105,6 +105,10 @@ align-items: center; justify-content: end; gap: 8px; + + .unequipped { + opacity: 0.5; + } } } diff --git a/templates/sheets/global/partials/inventory-item-V2.hbs b/templates/sheets/global/partials/inventory-item-V2.hbs index 10ff20eb..39f7d0b4 100644 --- a/templates/sheets/global/partials/inventory-item-V2.hbs +++ b/templates/sheets/global/partials/inventory-item-V2.hbs @@ -15,40 +15,33 @@ Parameters: - showActions {boolean} : If true show feature's actions. --}} -
  • {{!-- Image --}} -
    +
    d20
    {{!-- Name & Tags --}} -
    +
    {{!-- Item Name --}}
    {{localize item.name}}
    {{!-- Attack Block Start --}} - {{#if (eq type 'attack')}} -
    -
    - {{localize 'DAGGERHEART.GENERAL.unarmed'}} -
    -
    - {{localize 'DAGGERHEART.CONFIG.ActionType.action'}} -
    -
    + {{#if (eq type 'attack')}} +
    +
    + {{localize 'DAGGERHEART.GENERAL.unarmed'}} +
    +
    + {{localize 'DAGGERHEART.CONFIG.ActionType.action'}} +
    +
    {{/if}} {{!-- Attack Block End --}} @@ -56,43 +49,27 @@ Parameters: {{#if (eq type 'weapon')}} {{#if (not hideTags)}}
    + {{#each item.getTags as |tag|}}
    - {{localize (concat 'DAGGERHEART.CONFIG.Traits.' item.system.attack.roll.trait '.name')}} -
    -
    - {{localize (concat 'DAGGERHEART.CONFIG.Range.' item.system.attack.range '.name')}} -
    -
    - {{item.system.attack.damage.parts.0.value.dice}} - {{#if item.system.attack.damage.parts.0.value.bonus}} + - {{item.system.attack.damage.parts.0.value.bonus}}{{/if}} - ( - {{#each item.system.attack.damage.parts.0.type as |type|}} - - {{localize (concat 'DAGGERHEART.CONFIG.DamageType.' type '.abbreviation')}} - {{#unless @last}}|{{/unless}} - {{/each}} - ) - -
    -
    - {{localize (concat 'DAGGERHEART.CONFIG.Burden.' item.system.burden)}} + {{tag}}
    + {{/each}}
    {{else if (not hideLabels)}}
    + {{#each item.getLabels as |label|}}
    - {{localize (concat 'DAGGERHEART.CONFIG.Traits.' item.system.attack.roll.trait '.short')}} - {{localize (concat 'DAGGERHEART.CONFIG.Range.' item.system.attack.range '.short')}} - - - {{item.system.attack.damage.parts.0.value.dice}} - {{#if item.system.attack.damage.parts.0.value.bonus}} + - {{item.system.attack.damage.parts.0.value.bonus}} + {{ifThen label.value label.value label}} + {{log label.icons}} + {{#each label.icons as |icon|}} + + {{/each}} + + {{#if (not @last)}} + - {{/if}} - {{#with (lookup @root.config.GENERAL.damageTypes item.system.attack.damage.parts.0.type)}} - {{#each icon}}{{/each}} - {{/with}}
    + {{/each}}
    {{/if}} {{/if}}