Get rid of ifHasItemOfType

This commit is contained in:
Johannes Loher 2021-02-26 01:38:53 +01:00
parent b3ac3cde84
commit 315261bf4f
5 changed files with 42 additions and 69 deletions

View file

@ -1,6 +1,10 @@
export default { htmlToPlainText }; export default { htmlToPlainText, isEmpty };
function htmlToPlainText(input: string | null | undefined): string | null | undefined { function htmlToPlainText(input: string | null | undefined): string | null | undefined {
if (!input) return; if (!input) return;
return $(input).text(); return $(input).text();
} }
function isEmpty(input: Array<unknown> | null | undefined): boolean {
return (input?.length ?? 0) === 0;
}

View file

@ -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 --}} {{!-- WEAPONS --}}
<h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeWeaponPlural'}}</h4> <h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeWeaponPlural'}}</h4>
{{#> ifHasItemOfType itemsArray=itemsByType.weapon dataType='weapon' }} {{#unless (isEmpty itemsByType.weapon)}}
<ol class="ds4-item-list ds4-item-list--weapon item-list"> <ol class="ds4-item-list ds4-item-list--weapon item-list">
{{#> systems/ds4/templates/actor/partials/item-list-header.hbs isEquipable=true hasQuantity=true}} {{#> systems/ds4/templates/actor/partials/item-list-header.hbs isEquipable=true hasQuantity=true}}
{{!-- attack type --}} {{!-- attack type --}}
@ -56,11 +33,12 @@
{{/systems/ds4/templates/actor/partials/item-list-entry.hbs}} {{/systems/ds4/templates/actor/partials/item-list-entry.hbs}}
{{/each}} {{/each}}
</ol> </ol>
{{/ifHasItemOfType}} {{/unless}}
{{> systems/ds4/templates/actor/partials/overview-add-button.hbs dataType='weapon'}}
{{!-- ARMOR --}} {{!-- ARMOR --}}
<h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeArmorPlural'}}</h4> <h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeArmorPlural'}}</h4>
{{#> ifHasItemOfType itemsArray=itemsByType.armor dataType='armor' }} {{#unless (isEmpty itemsByType.armor)}}
<ol class="ds4-item-list ds4-item-list--armor item-list"> <ol class="ds4-item-list ds4-item-list--armor item-list">
{{#> systems/ds4/templates/actor/partials/item-list-header.hbs isEquipable=true hasQuantity=true}} {{#> systems/ds4/templates/actor/partials/item-list-header.hbs isEquipable=true hasQuantity=true}}
{{!-- armor material type --}} {{!-- armor material type --}}
@ -92,12 +70,12 @@
{{/systems/ds4/templates/actor/partials/item-list-entry.hbs}} {{/systems/ds4/templates/actor/partials/item-list-entry.hbs}}
{{/each}} {{/each}}
</ol> </ol>
{{/ifHasItemOfType}} {{/unless}}
{{> systems/ds4/templates/actor/partials/overview-add-button.hbs dataType='armor'}}
{{!-- SHIELD --}} {{!-- SHIELD --}}
<h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeShieldPlural'}}</h4> <h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeShieldPlural'}}</h4>
{{#> ifHasItemOfType itemsArray=itemsByType.shield dataType='shield' }} {{#unless (isEmpty itemsByType.shield)}}
<ol class="ds4-item-list ds4-item-list--shield item-list"> <ol class="ds4-item-list ds4-item-list--shield item-list">
{{#> systems/ds4/templates/actor/partials/item-list-header.hbs isEquipable=true hasQuantity=true}} {{#> systems/ds4/templates/actor/partials/item-list-header.hbs isEquipable=true hasQuantity=true}}
{{!-- armor value --}} {{!-- armor value --}}
@ -112,11 +90,12 @@
{{/systems/ds4/templates/actor/partials/item-list-entry.hbs}} {{/systems/ds4/templates/actor/partials/item-list-entry.hbs}}
{{/each}} {{/each}}
</ol> </ol>
{{/ifHasItemOfType}} {{/unless}}
{{> systems/ds4/templates/actor/partials/overview-add-button.hbs dataType='shield'}}
{{!-- EQUIPMENT --}} {{!-- EQUIPMENT --}}
<h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeEquipmentPlural'}}</h4> <h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeEquipmentPlural'}}</h4>
{{#> ifHasItemOfType itemsArray=itemsByType.equipment dataType='equipment' }} {{#unless (isEmpty itemsByType.equipment)}}
<ol class="ds4-item-list ds4-item-list--equipment item-list"> <ol class="ds4-item-list ds4-item-list--equipment item-list">
{{#> systems/ds4/templates/actor/partials/item-list-header.hbs isEquipable=true hasQuantity=true}} {{#> systems/ds4/templates/actor/partials/item-list-header.hbs isEquipable=true hasQuantity=true}}
{{!-- storage location --}} {{!-- storage location --}}
@ -130,11 +109,12 @@
{{/systems/ds4/templates/actor/partials/item-list-entry.hbs}} {{/systems/ds4/templates/actor/partials/item-list-entry.hbs}}
{{/each}} {{/each}}
</ol> </ol>
{{/ifHasItemOfType}} {{/unless}}
{{> systems/ds4/templates/actor/partials/overview-add-button.hbs dataType='equipment'}}
{{!-- LOOT --}} {{!-- LOOT --}}
<h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeLootPlural'}}</h4> <h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeLootPlural'}}</h4>
{{#> ifHasItemOfType itemsArray=itemsByType.loot dataType='loot' }} {{#unless (isEmpty itemsByType.loot)}}
<ol class="ds4-item-list ds4-item-list--loot item-list"> <ol class="ds4-item-list ds4-item-list--loot item-list">
{{#> systems/ds4/templates/actor/partials/item-list-header.hbs hasQuantity=true}} {{#> systems/ds4/templates/actor/partials/item-list-header.hbs hasQuantity=true}}
{{!-- storage location --}} {{!-- storage location --}}
@ -148,4 +128,5 @@
{{/systems/ds4/templates/actor/partials/item-list-entry.hbs}} {{/systems/ds4/templates/actor/partials/item-list-entry.hbs}}
{{/each}} {{/each}}
</ol> </ol>
{{/ifHasItemOfType}} {{/unless}}
{{> systems/ds4/templates/actor/partials/overview-add-button.hbs dataType='loot'}}

View file

@ -1,9 +1,11 @@
<div class="tab special-creature-abilities" data-group="primary" data-tab="special-creature-abilities"> <div class="tab special-creature-abilities" data-group="primary" data-tab="special-creature-abilities">
{{#unless (isEmpty itemsByType.specialCreatureAbility)}}
<ol class="ds4-item-list ds4-item-list--special-creature-ability item-list"> <ol class="ds4-item-list ds4-item-list--special-creature-ability item-list">
{{> systems/ds4/templates/actor/partials/item-list-header.hbs}} {{> systems/ds4/templates/actor/partials/item-list-header.hbs}}
{{#each itemsByType.specialCreatureAbility as |itemData id|}} {{#each itemsByType.specialCreatureAbility as |itemData id|}}
{{> systems/ds4/templates/actor/partials/item-list-entry.hbs itemData=itemData}} {{> systems/ds4/templates/actor/partials/item-list-entry.hbs itemData=itemData}}
{{/each}} {{/each}}
</ol> </ol>
{{/unless}}
{{> systems/ds4/templates/actor/partials/overview-add-button.hbs dataType='specialCreatureAbility'}} {{> systems/ds4/templates/actor/partials/overview-add-button.hbs dataType='specialCreatureAbility'}}
</div> </div>

View file

@ -38,6 +38,7 @@ titleKey=titleKey}}
<div class="tab spells" data-group="primary" data-tab="spells"> <div class="tab spells" data-group="primary" data-tab="spells">
{{#unless (isEmpty itemsByType.spell)}}
<ol class="ds4-item-list ds4-item-list--spell item-list"> <ol class="ds4-item-list ds4-item-list--spell item-list">
{{#> systems/ds4/templates/actor/partials/item-list-header.hbs isEquipable=true hideDescription=true}} {{#> systems/ds4/templates/actor/partials/item-list-header.hbs isEquipable=true hideDescription=true}}
{{!-- spell type --}} {{!-- spell type --}}
@ -81,6 +82,6 @@ titleKey=titleKey}}
{{/systems/ds4/templates/actor/partials/item-list-entry.hbs}} {{/systems/ds4/templates/actor/partials/item-list-entry.hbs}}
{{/each}} {{/each}}
</ol> </ol>
{{!-- add button --}} {{/unless}}
{{> systems/ds4/templates/actor/partials/overview-add-button.hbs dataType='spell' }} {{> systems/ds4/templates/actor/partials/overview-add-button.hbs dataType='spell' }}
</div> </div>

View file

@ -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}}
{{!-- ======================================================================== --}}
<div class="tab talents-abilities" data-group="primary" data-tab="talents-abilities"> <div class="tab talents-abilities" data-group="primary" data-tab="talents-abilities">
{{!-- TALENT --}}
<h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeTalentPlural'}}</h4> <h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeTalentPlural'}}</h4>
{{#> ifHasItemOfType itemsArray=itemsByType.talent dataType='talent'}} {{#unless (isEmpty itemsByType.talent)}}
<ol class="ds4-item-list ds4-item-list--talent item-list"> <ol class="ds4-item-list ds4-item-list--talent item-list">
{{#> systems/ds4/templates/actor/partials/item-list-header.hbs}} {{#> systems/ds4/templates/actor/partials/item-list-header.hbs}}
{{!-- rank --}} {{!-- rank --}}
@ -36,35 +14,42 @@
{{/systems/ds4/templates/actor/partials/item-list-entry.hbs}} {{/systems/ds4/templates/actor/partials/item-list-entry.hbs}}
{{/each}} {{/each}}
</ol> </ol>
{{/ifHasItemOfType}} {{/unless}}
{{> systems/ds4/templates/actor/partials/overview-add-button.hbs dataType='talent'}}
{{!-- RACIAL ABILITY --}}
<h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeRacialAbilityPlural'}}</h4> <h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeRacialAbilityPlural'}}</h4>
{{#> ifHasItemOfType itemsArray=itemsByType.racialAbility dataType='racialAbility'}} {{#unless (isEmpty itemsByType.racialAbility)}}
<ol class="ds4-item-list ds4-item-list--racial-ability item-list"> <ol class="ds4-item-list ds4-item-list--racial-ability item-list">
{{> systems/ds4/templates/actor/partials/item-list-header.hbs}} {{> systems/ds4/templates/actor/partials/item-list-header.hbs}}
{{#each itemsByType.racialAbility as |itemData id|}} {{#each itemsByType.racialAbility as |itemData id|}}
{{> systems/ds4/templates/actor/partials/item-list-entry.hbs itemData=itemData}} {{> systems/ds4/templates/actor/partials/item-list-entry.hbs itemData=itemData}}
{{/each}} {{/each}}
</ol> </ol>
{{/ifHasItemOfType}} {{/unless}}
{{> systems/ds4/templates/actor/partials/overview-add-button.hbs dataType='racialAbility'}}
{{!-- LANGUAGE --}}
<h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeLanguagePlural'}}</h4> <h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeLanguagePlural'}}</h4>
{{#> ifHasItemOfType itemsArray=itemsByType.language dataType='language'}} {{#unless (isEmpty itemsByType.language)}}
<ol class="ds4-item-list ds4-item-list--language item-list"> <ol class="ds4-item-list ds4-item-list--language item-list">
{{> systems/ds4/templates/actor/partials/item-list-header.hbs}} {{> systems/ds4/templates/actor/partials/item-list-header.hbs}}
{{#each itemsByType.language as |itemData id|}} {{#each itemsByType.language as |itemData id|}}
{{> systems/ds4/templates/actor/partials/item-list-entry.hbs itemData=itemData}} {{> systems/ds4/templates/actor/partials/item-list-entry.hbs itemData=itemData}}
{{/each}} {{/each}}
</ol> </ol>
{{/ifHasItemOfType}} {{/unless}}
{{> systems/ds4/templates/actor/partials/overview-add-button.hbs dataType='language'}}
{{!-- ALPHABET --}}
<h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeAlphabetPlural'}}</h4> <h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeAlphabetPlural'}}</h4>
{{#> ifHasItemOfType itemsArray=itemsByType.alphabet dataType='alphabet'}} {{#unless (isEmpty itemsByType.alphabet)}}
<ol class="ds4-item-list ds4-item-list--alphabet item-list"> <ol class="ds4-item-list ds4-item-list--alphabet item-list">
{{> systems/ds4/templates/actor/partials/item-list-header.hbs}} {{> systems/ds4/templates/actor/partials/item-list-header.hbs}}
{{#each itemsByType.alphabet as |itemData id|}} {{#each itemsByType.alphabet as |itemData id|}}
{{> systems/ds4/templates/actor/partials/item-list-entry.hbs itemData=itemData}} {{> systems/ds4/templates/actor/partials/item-list-entry.hbs itemData=itemData}}
{{/each}} {{/each}}
</ol> </ol>
{{/ifHasItemOfType}} {{/unless}}
{{> systems/ds4/templates/actor/partials/overview-add-button.hbs dataType='alphabet'}}
</div> </div>