FEAT: getTags and getLabels for weapons items

This commit is contained in:
Joaquin Pereyra 2025-07-28 23:37:19 -03:00
parent e6bfe08d83
commit 4d965c5dc2
4 changed files with 124 additions and 56 deletions

View file

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