mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-18 07:59:03 +01:00
FEAT: getTags and getLabels for weapons items
This commit is contained in:
parent
e6bfe08d83
commit
4d965c5dc2
4 changed files with 124 additions and 56 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -105,6 +105,10 @@
|
|||
align-items: center;
|
||||
justify-content: end;
|
||||
gap: 8px;
|
||||
|
||||
.unequipped {
|
||||
opacity: 0.5;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,22 +19,15 @@ Parameters:
|
|||
data-item-uuid="{{item.uuid}}" data-type="{{type}}" draggable="true">
|
||||
<div class="inventory-item-header" {{#unless noExtensible}}data-action="toggleExtended" {{/unless}}>
|
||||
{{!-- Image --}}
|
||||
<div class="img-portait"
|
||||
data-action='{{ifThen (or (hasProperty item "use") (eq type 'attack')) "useItem" (ifThen (hasProperty item "toChat") "toChat" "editDoc") }}'
|
||||
{{#unless hideTooltip}}
|
||||
{{#if (eq type 'attack')}}
|
||||
data-tooltip="#attack#{{item.actor.uuid}}"
|
||||
{{else}}
|
||||
data-tooltip="#item#{{item.uuid}}"
|
||||
{{/if}}
|
||||
{{/unless}}
|
||||
>
|
||||
<div class="img-portait" data-action='{{ifThen (or (hasProperty item "use") (eq type ' attack')) "useItem" (ifThen
|
||||
(hasProperty item "toChat" ) "toChat" "editDoc" ) }}' {{#unless hideTooltip}} {{#if (eq type 'attack' )}}
|
||||
data-tooltip="#attack#{{item.actor.uuid}}" {{else}} data-tooltip="#item#{{item.uuid}}" {{/if}} {{/unless}}>
|
||||
<img src="{{item.img}}" class="item-img {{#if isActor}}actor-img{{/if}}" />
|
||||
<img class="roll-img" src="systems/daggerheart/assets/icons/dice/default/d20.svg" alt="d20">
|
||||
</div>
|
||||
|
||||
{{!-- Name & Tags --}}
|
||||
<div class="item-label {{#if hideResources}}fullWidth{{/if}}">
|
||||
<div class="item-label">
|
||||
|
||||
{{!-- Item Name --}}
|
||||
<div class="item-name">{{localize item.name}}</div>
|
||||
|
|
@ -56,43 +49,27 @@ Parameters:
|
|||
{{#if (eq type 'weapon')}}
|
||||
{{#if (not hideTags)}}
|
||||
<div class="item-tags">
|
||||
{{#each item.getTags as |tag|}}
|
||||
<div class="tag">
|
||||
{{localize (concat 'DAGGERHEART.CONFIG.Traits.' item.system.attack.roll.trait '.name')}}
|
||||
{{tag}}
|
||||
</div>
|
||||
<div class="tag">
|
||||
{{localize (concat 'DAGGERHEART.CONFIG.Range.' item.system.attack.range '.name')}}
|
||||
</div>
|
||||
<div class="tag">
|
||||
{{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}}
|
||||
)
|
||||
|
||||
</div>
|
||||
<div class="tag">
|
||||
{{localize (concat 'DAGGERHEART.CONFIG.Burden.' item.system.burden)}}
|
||||
</div>
|
||||
</div>
|
||||
{{else if (not hideLabels)}}
|
||||
<div class="item-labels">
|
||||
{{#each item.getLabels as |label|}}
|
||||
<div class="label">
|
||||
{{localize (concat 'DAGGERHEART.CONFIG.Traits.' item.system.attack.roll.trait '.short')}}
|
||||
{{localize (concat 'DAGGERHEART.CONFIG.Range.' item.system.attack.range '.short')}}
|
||||
{{ifThen label.value label.value label}}
|
||||
{{log label.icons}}
|
||||
{{#each label.icons as |icon|}}
|
||||
<i class="fa-solid {{icon}}"></i>
|
||||
{{/each}}
|
||||
|
||||
{{#if (not @last)}}
|
||||
<span>-</span>
|
||||
{{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}}
|
||||
{{#with (lookup @root.config.GENERAL.damageTypes item.system.attack.damage.parts.0.type)}}
|
||||
{{#each icon}}<i class="fa-solid {{this}}"></i>{{/each}}
|
||||
{{/with}}
|
||||
</div>
|
||||
{{/each}}
|
||||
</div>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue