mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-18 16:09: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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,8 +74,8 @@ export default class DHItem extends foundry.documents.Item {
|
||||||
isInventoryItem === true
|
isInventoryItem === true
|
||||||
? 'Inventory Items' //TODO localize
|
? 'Inventory Items' //TODO localize
|
||||||
: isInventoryItem === false
|
: isInventoryItem === false
|
||||||
? 'Character Items' //TODO localize
|
? 'Character Items' //TODO localize
|
||||||
: 'Other'; //TODO localize
|
: 'Other'; //TODO localize
|
||||||
|
|
||||||
return { value: type, label, group };
|
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) {
|
async use(event) {
|
||||||
const actions = new Set(this.system.actionsList);
|
const actions = new Set(this.system.actionsList);
|
||||||
if (actions?.size) {
|
if (actions?.size) {
|
||||||
|
|
@ -115,10 +137,10 @@ export default class DHItem extends foundry.documents.Item {
|
||||||
this.type === 'ancestry'
|
this.type === 'ancestry'
|
||||||
? game.i18n.localize('DAGGERHEART.UI.Chat.foundationCard.ancestryTitle')
|
? game.i18n.localize('DAGGERHEART.UI.Chat.foundationCard.ancestryTitle')
|
||||||
: this.type === 'community'
|
: this.type === 'community'
|
||||||
? game.i18n.localize('DAGGERHEART.UI.Chat.foundationCard.communityTitle')
|
? game.i18n.localize('DAGGERHEART.UI.Chat.foundationCard.communityTitle')
|
||||||
: this.type === 'feature'
|
: this.type === 'feature'
|
||||||
? game.i18n.localize('TYPES.Item.feature')
|
? game.i18n.localize('TYPES.Item.feature')
|
||||||
: game.i18n.localize('DAGGERHEART.UI.Chat.foundationCard.subclassFeatureTitle'),
|
: game.i18n.localize('DAGGERHEART.UI.Chat.foundationCard.subclassFeatureTitle'),
|
||||||
origin: origin,
|
origin: origin,
|
||||||
img: this.img,
|
img: this.img,
|
||||||
name: this.name,
|
name: this.name,
|
||||||
|
|
|
||||||
|
|
@ -105,6 +105,10 @@
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: end;
|
justify-content: end;
|
||||||
gap: 8px;
|
gap: 8px;
|
||||||
|
|
||||||
|
.unequipped {
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,40 +15,33 @@ Parameters:
|
||||||
- showActions {boolean} : If true show feature's actions.
|
- showActions {boolean} : If true show feature's actions.
|
||||||
--}}
|
--}}
|
||||||
|
|
||||||
<li class="inventory-item" {{#if (or (eq type 'action' ) (eq type 'attack'))}}data-action-id="{{item.id}}" {{/if}}
|
<li class="inventory-item" {{#if (or (eq type 'action' ) (eq type 'attack' ))}}data-action-id="{{item.id}}" {{/if}}
|
||||||
data-item-uuid="{{item.uuid}}" data-type="{{type}}" draggable="true">
|
data-item-uuid="{{item.uuid}}" data-type="{{type}}" draggable="true">
|
||||||
<div class="inventory-item-header" {{#unless noExtensible}}data-action="toggleExtended" {{/unless}}>
|
<div class="inventory-item-header" {{#unless noExtensible}}data-action="toggleExtended" {{/unless}}>
|
||||||
{{!-- Image --}}
|
{{!-- Image --}}
|
||||||
<div class="img-portait"
|
<div class="img-portait" data-action='{{ifThen (or (hasProperty item "use") (eq type ' attack')) "useItem" (ifThen
|
||||||
data-action='{{ifThen (or (hasProperty item "use") (eq type 'attack')) "useItem" (ifThen (hasProperty item "toChat") "toChat" "editDoc") }}'
|
(hasProperty item "toChat" ) "toChat" "editDoc" ) }}' {{#unless hideTooltip}} {{#if (eq type 'attack' )}}
|
||||||
{{#unless hideTooltip}}
|
data-tooltip="#attack#{{item.actor.uuid}}" {{else}} data-tooltip="#item#{{item.uuid}}" {{/if}} {{/unless}}>
|
||||||
{{#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 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">
|
<img class="roll-img" src="systems/daggerheart/assets/icons/dice/default/d20.svg" alt="d20">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{!-- Name & Tags --}}
|
{{!-- Name & Tags --}}
|
||||||
<div class="item-label {{#if hideResources}}fullWidth{{/if}}">
|
<div class="item-label">
|
||||||
|
|
||||||
{{!-- Item Name --}}
|
{{!-- Item Name --}}
|
||||||
<div class="item-name">{{localize item.name}}</div>
|
<div class="item-name">{{localize item.name}}</div>
|
||||||
|
|
||||||
{{!-- Attack Block Start --}}
|
{{!-- Attack Block Start --}}
|
||||||
{{#if (eq type 'attack')}}
|
{{#if (eq type 'attack')}}
|
||||||
<div class="item-tags">
|
<div class="item-tags">
|
||||||
<div class="tag">
|
<div class="tag">
|
||||||
{{localize 'DAGGERHEART.GENERAL.unarmed'}}
|
{{localize 'DAGGERHEART.GENERAL.unarmed'}}
|
||||||
</div>
|
</div>
|
||||||
<div class="tag">
|
<div class="tag">
|
||||||
{{localize 'DAGGERHEART.CONFIG.ActionType.action'}}
|
{{localize 'DAGGERHEART.CONFIG.ActionType.action'}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{!-- Attack Block End --}}
|
{{!-- Attack Block End --}}
|
||||||
|
|
||||||
|
|
@ -56,43 +49,27 @@ Parameters:
|
||||||
{{#if (eq type 'weapon')}}
|
{{#if (eq type 'weapon')}}
|
||||||
{{#if (not hideTags)}}
|
{{#if (not hideTags)}}
|
||||||
<div class="item-tags">
|
<div class="item-tags">
|
||||||
|
{{#each item.getTags as |tag|}}
|
||||||
<div class="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>
|
||||||
|
{{/each}}
|
||||||
</div>
|
</div>
|
||||||
{{else if (not hideLabels)}}
|
{{else if (not hideLabels)}}
|
||||||
<div class="item-labels">
|
<div class="item-labels">
|
||||||
|
{{#each item.getLabels as |label|}}
|
||||||
<div class="label">
|
<div class="label">
|
||||||
{{localize (concat 'DAGGERHEART.CONFIG.Traits.' item.system.attack.roll.trait '.short')}}
|
{{ifThen label.value label.value label}}
|
||||||
{{localize (concat 'DAGGERHEART.CONFIG.Range.' item.system.attack.range '.short')}}
|
{{log label.icons}}
|
||||||
<span> - </span>
|
{{#each label.icons as |icon|}}
|
||||||
{{item.system.attack.damage.parts.0.value.dice}}
|
<i class="fa-solid {{icon}}"></i>
|
||||||
{{#if item.system.attack.damage.parts.0.value.bonus}} +
|
{{/each}}
|
||||||
{{item.system.attack.damage.parts.0.value.bonus}}
|
|
||||||
|
{{#if (not @last)}}
|
||||||
|
<span>-</span>
|
||||||
{{/if}}
|
{{/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>
|
</div>
|
||||||
|
{{/each}}
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue