diff --git a/src/module/handlebars-helpers.ts b/src/module/handlebars-helpers.ts index 2790ea43..95144da3 100644 --- a/src/module/handlebars-helpers.ts +++ b/src/module/handlebars-helpers.ts @@ -1,6 +1,10 @@ -export default { htmlToPlainText }; +export default { htmlToPlainText, isEmpty }; function htmlToPlainText(input: string | null | undefined): string | null | undefined { if (!input) return; return $(input).text(); } + +function isEmpty(input: Array | null | undefined): boolean { + return (input?.length ?? 0) === 0; +} diff --git a/src/templates/actor/partials/items-overview.hbs b/src/templates/actor/partials/items-overview.hbs index a8e8c77c..c3544805 100644 --- a/src/templates/actor/partials/items-overview.hbs +++ b/src/templates/actor/partials/items-overview.hbs @@ -1,29 +1,6 @@ -{{!-- TODO: Refactor to avoid code duplication with special-creature-abilites-overview and talents-overview --}} - -{{!-- ======================================================================== --}} -{{!-- INLINE PARTIAL DEFINITIONS --}} -{{!-- ======================================================================== --}} - - -{{!-- -!-- 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}} -{{/if}} -{{> systems/ds4/templates/actor/partials/overview-add-button.hbs dataType=dataType }} -{{/inline}} - -{{!-- ======================================================================== --}} - {{!-- WEAPONS --}}

{{localize 'DS4.ItemTypeWeaponPlural'}}

-{{#> ifHasItemOfType itemsArray=itemsByType.weapon dataType='weapon' }} +{{#unless (isEmpty itemsByType.weapon)}}
    {{#> systems/ds4/templates/actor/partials/item-list-header.hbs isEquipable=true hasQuantity=true}} {{!-- attack type --}} @@ -56,11 +33,12 @@ {{/systems/ds4/templates/actor/partials/item-list-entry.hbs}} {{/each}}
-{{/ifHasItemOfType}} +{{/unless}} +{{> systems/ds4/templates/actor/partials/overview-add-button.hbs dataType='weapon'}} {{!-- ARMOR --}}

{{localize 'DS4.ItemTypeArmorPlural'}}

-{{#> ifHasItemOfType itemsArray=itemsByType.armor dataType='armor' }} +{{#unless (isEmpty itemsByType.armor)}}
    {{#> systems/ds4/templates/actor/partials/item-list-header.hbs isEquipable=true hasQuantity=true}} {{!-- armor material type --}} @@ -92,12 +70,12 @@ {{/systems/ds4/templates/actor/partials/item-list-entry.hbs}} {{/each}}
-{{/ifHasItemOfType}} - +{{/unless}} +{{> systems/ds4/templates/actor/partials/overview-add-button.hbs dataType='armor'}} {{!-- SHIELD --}}

{{localize 'DS4.ItemTypeShieldPlural'}}

-{{#> ifHasItemOfType itemsArray=itemsByType.shield dataType='shield' }} +{{#unless (isEmpty itemsByType.shield)}}
    {{#> systems/ds4/templates/actor/partials/item-list-header.hbs isEquipable=true hasQuantity=true}} {{!-- armor value --}} @@ -112,11 +90,12 @@ {{/systems/ds4/templates/actor/partials/item-list-entry.hbs}} {{/each}}
-{{/ifHasItemOfType}} +{{/unless}} +{{> systems/ds4/templates/actor/partials/overview-add-button.hbs dataType='shield'}} {{!-- EQUIPMENT --}}

{{localize 'DS4.ItemTypeEquipmentPlural'}}

-{{#> ifHasItemOfType itemsArray=itemsByType.equipment dataType='equipment' }} +{{#unless (isEmpty itemsByType.equipment)}}
    {{#> systems/ds4/templates/actor/partials/item-list-header.hbs isEquipable=true hasQuantity=true}} {{!-- storage location --}} @@ -130,11 +109,12 @@ {{/systems/ds4/templates/actor/partials/item-list-entry.hbs}} {{/each}}
-{{/ifHasItemOfType}} +{{/unless}} +{{> systems/ds4/templates/actor/partials/overview-add-button.hbs dataType='equipment'}} {{!-- LOOT --}}

{{localize 'DS4.ItemTypeLootPlural'}}

-{{#> ifHasItemOfType itemsArray=itemsByType.loot dataType='loot' }} +{{#unless (isEmpty itemsByType.loot)}}
    {{#> systems/ds4/templates/actor/partials/item-list-header.hbs hasQuantity=true}} {{!-- storage location --}} @@ -148,4 +128,5 @@ {{/systems/ds4/templates/actor/partials/item-list-entry.hbs}} {{/each}}
-{{/ifHasItemOfType}} +{{/unless}} +{{> systems/ds4/templates/actor/partials/overview-add-button.hbs dataType='loot'}} diff --git a/src/templates/actor/partials/special-creature-abilities-overview.hbs b/src/templates/actor/partials/special-creature-abilities-overview.hbs index eef96adf..cf6a4a55 100644 --- a/src/templates/actor/partials/special-creature-abilities-overview.hbs +++ b/src/templates/actor/partials/special-creature-abilities-overview.hbs @@ -1,9 +1,11 @@
+ {{#unless (isEmpty itemsByType.specialCreatureAbility)}}
    - {{> systems/ds4/templates/actor/partials/item-list-header.hbs }} + {{> systems/ds4/templates/actor/partials/item-list-header.hbs}} {{#each itemsByType.specialCreatureAbility as |itemData id|}} {{> systems/ds4/templates/actor/partials/item-list-entry.hbs itemData=itemData}} {{/each}}
- {{> systems/ds4/templates/actor/partials/overview-add-button.hbs dataType='specialCreatureAbility' }} + {{/unless}} + {{> systems/ds4/templates/actor/partials/overview-add-button.hbs dataType='specialCreatureAbility'}}
diff --git a/src/templates/actor/partials/spells-overview.hbs b/src/templates/actor/partials/spells-overview.hbs index 558a14c9..e9861c77 100644 --- a/src/templates/actor/partials/spells-overview.hbs +++ b/src/templates/actor/partials/spells-overview.hbs @@ -38,6 +38,7 @@ titleKey=titleKey}}
+ {{#unless (isEmpty itemsByType.spell)}}
    {{#> systems/ds4/templates/actor/partials/item-list-header.hbs isEquipable=true hideDescription=true}} {{!-- spell type --}} @@ -81,6 +82,6 @@ titleKey=titleKey}} {{/systems/ds4/templates/actor/partials/item-list-entry.hbs}} {{/each}}
- {{!-- add button --}} + {{/unless}} {{> systems/ds4/templates/actor/partials/overview-add-button.hbs dataType='spell' }}
diff --git a/src/templates/actor/partials/talents-abilities-overview.hbs b/src/templates/actor/partials/talents-abilities-overview.hbs index e212a5d4..9ec53331 100644 --- a/src/templates/actor/partials/talents-abilities-overview.hbs +++ b/src/templates/actor/partials/talents-abilities-overview.hbs @@ -1,29 +1,7 @@ -{{!-- TODO: Refactor to avoid code duplication with creature-special-abilities-overview and talents-overview --}} - -{{!-- ======================================================================== --}} -{{!-- INLINE PARTIAL DEFINITIONS --}} -{{!-- ======================================================================== --}} - - -{{!-- -!-- 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}} -{{/if}} -{{> systems/ds4/templates/actor/partials/overview-add-button.hbs dataType=dataType }} -{{/inline}} - -{{!-- ======================================================================== --}} -
+ {{!-- TALENT --}}

{{localize 'DS4.ItemTypeTalentPlural'}}

- {{#> ifHasItemOfType itemsArray=itemsByType.talent dataType='talent'}} + {{#unless (isEmpty itemsByType.talent)}}
    {{#> systems/ds4/templates/actor/partials/item-list-header.hbs}} {{!-- rank --}} @@ -36,35 +14,42 @@ {{/systems/ds4/templates/actor/partials/item-list-entry.hbs}} {{/each}}
- {{/ifHasItemOfType}} + {{/unless}} + {{> systems/ds4/templates/actor/partials/overview-add-button.hbs dataType='talent'}} + {{!-- RACIAL ABILITY --}}

{{localize 'DS4.ItemTypeRacialAbilityPlural'}}

- {{#> ifHasItemOfType itemsArray=itemsByType.racialAbility dataType='racialAbility'}} + {{#unless (isEmpty itemsByType.racialAbility)}}
    {{> systems/ds4/templates/actor/partials/item-list-header.hbs}} {{#each itemsByType.racialAbility as |itemData id|}} {{> systems/ds4/templates/actor/partials/item-list-entry.hbs itemData=itemData}} {{/each}}
- {{/ifHasItemOfType}} + {{/unless}} + {{> systems/ds4/templates/actor/partials/overview-add-button.hbs dataType='racialAbility'}} + {{!-- LANGUAGE --}}

{{localize 'DS4.ItemTypeLanguagePlural'}}

- {{#> ifHasItemOfType itemsArray=itemsByType.language dataType='language'}} + {{#unless (isEmpty itemsByType.language)}}
    {{> systems/ds4/templates/actor/partials/item-list-header.hbs}} {{#each itemsByType.language as |itemData id|}} {{> systems/ds4/templates/actor/partials/item-list-entry.hbs itemData=itemData}} {{/each}}
- {{/ifHasItemOfType}} + {{/unless}} + {{> systems/ds4/templates/actor/partials/overview-add-button.hbs dataType='language'}} + {{!-- ALPHABET --}}

{{localize 'DS4.ItemTypeAlphabetPlural'}}

- {{#> ifHasItemOfType itemsArray=itemsByType.alphabet dataType='alphabet'}} + {{#unless (isEmpty itemsByType.alphabet)}}
    {{> systems/ds4/templates/actor/partials/item-list-header.hbs}} {{#each itemsByType.alphabet as |itemData id|}} {{> systems/ds4/templates/actor/partials/item-list-entry.hbs itemData=itemData}} {{/each}}
- {{/ifHasItemOfType}} + {{/unless}} + {{> systems/ds4/templates/actor/partials/overview-add-button.hbs dataType='alphabet'}}