From dc2d09956599c836c947f64c1a1d2ae7e459ef09 Mon Sep 17 00:00:00 2001 From: Gesina Schwalbe Date: Sat, 9 Jan 2021 01:11:55 +0100 Subject: [PATCH] implemented dynamic headers of item lists --- .../actor/partials/items-overview.hbs | 29 +++++++++++++++++++ .../actor/partials/talents-overview.hbs | 25 ++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/src/templates/actor/partials/items-overview.hbs b/src/templates/actor/partials/items-overview.hbs index e41d6f98..676a9bfc 100644 --- a/src/templates/actor/partials/items-overview.hbs +++ b/src/templates/actor/partials/items-overview.hbs @@ -6,6 +6,22 @@ {{!-- ======================================================================== --}} +{{!-- +!-- Render the given partial block only if the given itemsArray has length > 0, +!-- else only an add button. +!-- +!-- @param itemsArray: the array with the items to check the length of +!-- @param dataType: the string type of the item +--}} +{{#*inline "ifHasItemOfType"}} +{{#if (and (ne itemsArray undefined) (gt itemsArray.length 0))}} + {{> @partial-block}} +{{else}} + {{> systems/ds4/templates/actor/partials/overview-add-button.hbs dataType=dataType }} +{{/if}} +{{/inline}} + + {{!-- !-- Render a header row for a given data type. !-- It is a flexbox with a child for each column head. @@ -83,6 +99,8 @@ {{!-- WEAPONS --}}

{{localize 'DS4.ItemTypeWeaponPlural'}}

+ {{!-- {{#if (and (ne itemsByType.weapon undefined) (gt itemsByType.weapon.length 0)) }} --}} + {{#> ifHasItemOfType itemsArray=itemsByType.weapon dataType='weapon' }}
    {{#> itemListHeader dataType='weapon'}}
    {{localize 'DS4.AttackTypeAbbr'}}
    @@ -104,9 +122,13 @@ {{/itemListEntry}} {{/each}}
+ {{!-- {{else}} + {{> systems/ds4/templates/actor/partials/overview-add-button.hbs dataType='weapon' }} --}} + {{/ifHasItemOfType}} {{!-- ARMOR --}}

{{localize 'DS4.ItemTypeArmorPlural'}}

+ {{#> ifHasItemOfType itemsArray=itemsByType.armor dataType='armor' }}
    {{#> itemListHeader dataType='armor'}}
    {{localize 'DS4.ArmorMaterialTypeAbbr'}}
    @@ -127,10 +149,12 @@ {{/itemListEntry}} {{/each}}
+ {{/ifHasItemOfType}} {{!-- SHIELD --}}

{{localize 'DS4.ItemTypeShieldPlural'}}

{{!-- SPECIFIC --}} + {{#> ifHasItemOfType itemsArray=itemsByType.shield dataType='shield' }}
    {{#> itemListHeader dataType='shield' }}
    @@ -143,9 +167,11 @@ {{/itemListEntry}} {{/each}}
+ {{/ifHasItemOfType}} {{!-- TRINKET --}}

{{localize 'DS4.ItemTypeTrinketPlural'}}

+ {{#> ifHasItemOfType itemsArray=itemsByType.trinket dataType='trinket' }}
    {{#> itemListHeader dataType='trinket'}}
    {{localize 'DS4.StorageLocation'}}
    @@ -157,9 +183,11 @@ {{/itemListEntry}} {{/each}}
+ {{/ifHasItemOfType}} {{!-- EQUIPMENT --}}

{{localize 'DS4.ItemTypeEquipmentPlural'}}

+ {{#> ifHasItemOfType itemsArray=itemsByType.equipment dataType='equipment' }}
    {{#> itemListHeader dataType='equipment'}}
    {{localize 'DS4.StorageLocation'}}
    @@ -171,4 +199,5 @@ {{/itemListEntry}} {{/each}}
+ {{/ifHasItemOfType}} \ No newline at end of file diff --git a/src/templates/actor/partials/talents-overview.hbs b/src/templates/actor/partials/talents-overview.hbs index 7aa194e5..f4a06005 100644 --- a/src/templates/actor/partials/talents-overview.hbs +++ b/src/templates/actor/partials/talents-overview.hbs @@ -4,6 +4,23 @@ {{!-- TODO: remove duplicate add and delete button definition --}} + +{{!-- +!-- Render the given partial block only if the given itemsArray has length > 0, +!-- else only an add button. +!-- +!-- @param itemsArray: the array with the items to check the length of +!-- @param dataType: the string type of the item +--}} +{{#*inline "ifHasItemOfType"}} +{{#if (and (ne itemsArray undefined) (gt itemsArray.length 0))}} + {{> @partial-block}} +{{else}} + {{> systems/ds4/templates/actor/partials/overview-add-button.hbs dataType=dataType }} +{{/if}} +{{/inline}} + + {{!-- !-- Render an input element for a rank value property of an item. !-- @@ -105,6 +122,7 @@

{{localize 'DS4.ItemTypeTalentPlural'}}

+ {{#> ifHasItemOfType itemsArray=itemsByType.talent dataType='talent' }}
  1. {{!-- image --}} @@ -122,28 +140,35 @@ {{> talentListEntry item=item}} {{/each}}
+ {{/ifHasItemOfType}}

{{localize 'DS4.ItemTypeRacialAbilityPlural'}}

+ {{#> ifHasItemOfType itemsArray=itemsByType.racialAbility dataType='racialAbility' }}
    {{> baseItemListHeader dataType='racialAbility' }} {{#each itemsByType.racialAbility as |item id|}} {{> baseItemListEntry item=item}} {{/each}}
+ {{/ifHasItemOfType}}

{{localize 'DS4.ItemTypeLanguagePlural'}}

+ {{#> ifHasItemOfType itemsArray=itemsByType.language dataType='language' }}
    {{> baseItemListHeader dataType='language' }} {{#each itemsByType.language as |item id|}} {{> baseItemListEntry item=item}} {{/each}}
+ {{/ifHasItemOfType}}

{{localize 'DS4.ItemTypeAlphabetPlural'}}

+ {{#> ifHasItemOfType itemsArray=itemsByType.alphabet dataType='alphabet' }}
    {{> baseItemListHeader dataType='alphabet' }} {{#each itemsByType.alphabet as |item id|}} {{> baseItemListEntry item=item}} {{/each}}
+ {{/ifHasItemOfType}}
\ No newline at end of file