Extract item-list-header to common partial used by all item lists

This commit is contained in:
Johannes Loher 2021-02-25 23:30:45 +01:00
parent 276a70a70a
commit 9573a6595d
6 changed files with 69 additions and 108 deletions

View file

@ -64,6 +64,7 @@ async function registerHandlebarsPartials() {
"systems/ds4/templates/actor/partials/character-inventory.hbs",
"systems/ds4/templates/actor/partials/creature-inventory.hbs",
"systems/ds4/templates/actor/partials/talent-rank-equation.hbs",
"systems/ds4/templates/actor/partials/item-list-header.hbs",
];
return loadTemplates(templatePaths);
}

View file

@ -0,0 +1,34 @@
{{!--
!-- Render an item list header row.
!-- If the partial is called with a partial block, the partial block
!-- content is inserted before the description heading.
!--
!-- @param isEquipable: A flag to enable the equipped column.
!-- @param hasQuantity: A flag to enable the quantity column.
!-- @param hideDescription: A flag to disable the description column.
!-- @param @partial-block: Custom column headers can be passed using the partial block.
--}}
<li class="ds4-item-list__row ds4-item-list__row--header">
{{!-- equipped --}}
{{#if isEquipable}}
<div title="{{localize 'DS4.ItemEquipped'}}">{{localize 'DS4.ItemEquippedAbbr'}}</div>
{{/if}}
{{!-- image --}}
<div></div>
{{!-- amount --}}
{{#if hasQuantity}}
<div title="{{localize 'DS4.Quantity'}}">#</div>
{{/if}}
{{!-- name --}}
<div>{{localize 'DS4.ItemName'}}</div>
{{!-- item type specifics --}}
{{#if @partial-block }}
{{> @partial-block }}
{{/if}}
{{!-- description --}}
{{#unless hideDescription}}
<div>{{localize 'DS4.Description'}}</div>
{{/unless}}
{{!-- control buttons placeholder --}}
<div></div>
</li>

View file

@ -19,38 +19,6 @@
{{> systems/ds4/templates/actor/partials/overview-add-button.hbs dataType=dataType }}
{{/inline}}
{{!--
!-- Render a header row for a given data type.
!-- An "equipped" heading is rendered except for the case dataType==='loot'.
!-- The partial assumes a variable dataType to be given in the context.
!-- If the partial is called with a partial block, the partial block
!-- content is inserted before the description heading.
!-- @param datType: hand over the dataType to the partial as hash parameter
!-- @param partial-block: hand over custom children in the partial block.
--}}
{{#*inline "itemListHeader" }}
<li class="ds4-item-list__row ds4-item-list__row--header">
{{!-- equipped --}}
{{#if (ne dataType 'loot')}}
<div title="{{localize 'DS4.ItemEquipped'}}">{{localize 'DS4.ItemEquippedAbbr'}}</div>
{{/if}}
{{!-- image --}}
<div></div>
{{!-- amount --}}
<div title="{{localize 'DS4.Quantity'}}">#</div>
{{!-- name --}}
<div>{{localize 'DS4.ItemName'}}</div>
{{!-- item type specifics --}}
{{> @partial-block }}
{{!-- description --}}
<div>{{localize 'DS4.Description'}}</div>
{{!-- control buttons placeholder --}}
<div></div>
</li>
{{/inline}}
{{!--
!-- Render a list row from a given item.
!-- An equipped checkbox is rendered except for the case item.data.type==='loot'.
@ -93,7 +61,7 @@
<h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeWeaponPlural'}}</h4>
{{#> ifHasItemOfType itemsArray=itemsByType.weapon dataType='weapon' }}
<ol class="ds4-item-list ds4-item-list--weapon item-list">
{{#> itemListHeader dataType='weapon'}}
{{#> systems/ds4/templates/actor/partials/item-list-header.hbs isEquipable=true hasQuantity=true}}
<div class="ds4-item-list__image" title="{{localize 'DS4.AttackType'}}">{{localize 'DS4.AttackTypeAbbr'}}</div>
<div title="{{localize 'DS4.WeaponBonus'}}">
{{localize 'DS4.WeaponBonusAbbr'}}
@ -101,7 +69,7 @@
<div title="{{localize 'DS4.OpponentDefense'}}">
{{localize 'DS4.OpponentDefenseAbbr'}}
</div>
{{/itemListHeader}}
{{/systems/ds4/templates/actor/partials/item-list-header.hbs}}
{{#each itemsByType.weapon as |item id|}}
{{#> itemListEntry item=item}}
<div class="ds4-item-list__image"
@ -119,13 +87,13 @@
<h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeArmorPlural'}}</h4>
{{#> ifHasItemOfType itemsArray=itemsByType.armor dataType='armor' }}
<ol class="ds4-item-list ds4-item-list--armor item-list">
{{#> itemListHeader dataType='armor'}}
{{#> systems/ds4/templates/actor/partials/item-list-header.hbs isEquipable=true hasQuantity=true}}
<div title="{{localize 'DS4.ArmorMaterialType'}}">{{localize 'DS4.ArmorMaterialTypeAbbr'}}</div>
<div title="{{localize 'DS4.ArmorType'}}">{{localize 'DS4.ArmorTypeAbbr'}}</div>
<div title="{{localize 'DS4.ArmorValue'}}">
{{localize 'DS4.ArmorValueAbbr'}}
</div>
{{/itemListHeader}}
{{/systems/ds4/templates/actor/partials/item-list-header.hbs}}
{{#each itemsByType.armor as |item id|}}
{{#> itemListEntry item=item }}
<div title="{{lookup ../../config.i18n.armorMaterialTypes item.data.armorMaterialType}}">
@ -145,11 +113,11 @@
<h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeShieldPlural'}}</h4>
{{#> ifHasItemOfType itemsArray=itemsByType.shield dataType='shield' }}
<ol class="ds4-item-list ds4-item-list--shield item-list">
{{#> itemListHeader dataType='shield' }}
{{#> systems/ds4/templates/actor/partials/item-list-header.hbs isEquipable=true hasQuantity=true}}
<div title="{{localize 'DS4.ArmorValue'}}">
{{localize 'DS4.ArmorValueAbbr'}}
</div>
{{/itemListHeader}}
{{/systems/ds4/templates/actor/partials/item-list-header.hbs}}
{{#each itemsByType.shield as |item id|}}
{{#> itemListEntry item=item }}
<div>{{item.data.armorValue}}</div>
@ -163,9 +131,9 @@
<h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeEquipmentPlural'}}</h4>
{{#> ifHasItemOfType itemsArray=itemsByType.equipment dataType='equipment' }}
<ol class="ds4-item-list ds4-item-list--equipment item-list">
{{#> itemListHeader dataType='equipment'}}
{{#> systems/ds4/templates/actor/partials/item-list-header.hbs isEquipable=true hasQuantity=true}}
<div>{{localize 'DS4.StorageLocation'}}</div>
{{/itemListHeader}}
{{/systems/ds4/templates/actor/partials/item-list-header.hbs}}
{{#each itemsByType.equipment as |item id|}}
{{#> itemListEntry item=item }}
<input class="ds4-item-list__editable item-change" type="text" value="{{item.data.storageLocation}}"
@ -179,9 +147,9 @@
<h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeLootPlural'}}</h4>
{{#> ifHasItemOfType itemsArray=itemsByType.loot dataType='loot' }}
<ol class="ds4-item-list ds4-item-list--loot item-list">
{{#> itemListHeader dataType='loot'}}
{{#> systems/ds4/templates/actor/partials/item-list-header.hbs hasQuantity=true}}
<div>{{localize 'DS4.StorageLocation'}}</div>
{{/itemListHeader}}
{{/systems/ds4/templates/actor/partials/item-list-header.hbs}}
{{#each itemsByType.loot as |item id|}}
{{#> itemListEntry item=item }}
<input class="ds4-item-list__editable item-change" type="text" value="{{item.data.storageLocation}}"

View file

@ -27,29 +27,11 @@
</li>
{{/inline}}
{{!--
!-- Render a list header for a base item list entries from a given item.
--}}
{{#*inline "itemListHeader"}}
<li class="ds4-item-list__row ds4-item-list__row--header">
{{!-- image --}}
<div></div>
{{!-- name --}}
<div>{{localize 'DS4.ItemName'}}</div>
{{!-- description --}}
<div class="flex3">{{localize 'DS4.Description'}}</div>
{{!-- control buttons placeholder --}}
<div></div>
</li>
{{/inline}}
{{!-- ======================================================================== --}}
<div class="tab special-creature-abilities" data-group="primary" data-tab="special-creature-abilities">
<ol class="ds4-item-list ds4-item-list--special-creature-ability item-list">
{{> itemListHeader }}
{{> systems/ds4/templates/actor/partials/item-list-header.hbs }}
{{#each itemsByType.specialCreatureAbility as |item id|}}
{{> itemListEntry item=item}}
{{/each}}

View file

@ -37,30 +37,22 @@ localizationString=localizationString}}
<div class="tab spells" data-group="primary" data-tab="spells">
<ol class="ds4-item-list ds4-item-list--spell item-list">
<li class="ds4-item-list__row ds4-item-list__row--header">
{{!-- equipped --}}
<div title="{{localize 'DS4.ItemEquipped'}}">{{localize 'DS4.ItemEquippedAbbr'}}</div>
{{!-- image --}}
<div></div>
{{!-- name --}}
<div>{{localize 'DS4.ItemName'}}</div>
{{!-- spell type --}}
<div title="{{localize 'DS4.SpellType'}}">{{localize 'DS4.SpellTypeAbbr'}}</div>
{{!-- spell bonus --}}
<div title="{{localize 'DS4.SpellBonus'}}">{{localize 'DS4.SpellBonusAbbr'}}</div>
{{!-- max. distance --}}
<div title="{{localize 'DS4.SpellMaxDistance'}}"><i class="fas fa-ruler"></i></div>
{{!-- duration --}}
<div title="{{localize 'DS4.SpellDuration'}}"><i class="far fa-clock"></i></div>
{{!-- cooldown duration --}}
<div title="{{localize 'DS4.SpellCooldownDuration'}}"><i class="fas fa-hourglass-half"></i></div>
{{!-- control buttons placeholder --}}
<div></div>
</li>
{{#> systems/ds4/templates/actor/partials/item-list-header.hbs isEquipable=true hideDescription=true}}
{{!-- spell type --}}
<div title="{{localize 'DS4.SpellType'}}">{{localize 'DS4.SpellTypeAbbr'}}</div>
{{!-- spell bonus --}}
<div title="{{localize 'DS4.SpellBonus'}}">{{localize 'DS4.SpellBonusAbbr'}}</div>
{{!-- max. distance --}}
<div title="{{localize 'DS4.SpellMaxDistance'}}"><i class="fas fa-ruler"></i></div>
{{!-- duration --}}
<div title="{{localize 'DS4.SpellDuration'}}"><i class="far fa-clock"></i></div>
{{!-- cooldown duration --}}
<div title="{{localize 'DS4.SpellCooldownDuration'}}"><i class="fas fa-hourglass-half"></i></div>
{{/systems/ds4/templates/actor/partials/item-list-header.hbs}}
{{#each itemsByType.spell as |item id|}}
<li class="ds4-item-list__row item" data-item-id="{{item._id}}">
<input class="ds4-item-list__editable ds4-item-list__editable--checkbox item-change" type="checkbox" {{checked
item.data.data.equipped}} data-dtype="Boolean" data-property="data.equipped"
<input class="ds4-item-list__editable ds4-item-list__editable--checkbox item-change" type="checkbox"
{{checked item.data.data.equipped}} data-dtype="Boolean" data-property="data.equipped"
title="{{localize 'DS4.ItemEquipped'}}">
{{!-- image --}}
<div class="ds4-item-list__image" style="background-image: url('{{item.img}}')" title="{{item.name}}"></div>
@ -73,8 +65,8 @@ localizationString=localizationString}}
title="{{lookup ../config.i18n.spellTypes item.data.data.spellType}}">
</div>
{{!-- spell bonus --}}
<input class="ds4-item-list__editable item-change" type="text" data-dtype="String" data-property="data.bonus"
value="{{item.data.data.bonus}}" title="{{localize 'DS4.SpellBonus'}}" />
<input class="ds4-item-list__editable item-change" type="text" data-dtype="String"
data-property="data.bonus" value="{{item.data.data.bonus}}" title="{{localize 'DS4.SpellBonus'}}" />
{{!-- max. distance --}}
{{> distanceUnit localizationString='DS4.SpellMaxDistance' unitDatum=item.data.data.maxDistance
config=../config}}

View file

@ -54,8 +54,6 @@
<div></div>
{{!-- name --}}
<div>{{localize 'DS4.ItemName'}}</div>
{{!-- rank info --}}
<div>{{localize 'DS4.TalentRank'}}</div>
{{!-- description --}}
<div>{{localize 'DS4.Description'}}</div>
{{!-- control buttons placeholder --}}
@ -87,30 +85,16 @@
</li>
{{/inline}}
{{!--
!-- Render a list header for a base item list entry from a given item.
!-- The partial assumes a variable dataType to be given in the context.
--}}
{{#*inline "baseItemListHeader"}}
<li class="ds4-item-list__row ds4-item-list__row--header">
{{!-- image --}}
<div></div>
{{!-- name --}}
<div>{{localize 'DS4.ItemName'}}</div>
{{!-- description --}}
<div>{{localize 'DS4.Description'}}</div>
{{!-- control buttons placeholder --}}
<div></div>
</li>
{{/inline}}
{{!-- ======================================================================== --}}
<div class="tab talents-abilities" data-group="primary" data-tab="talents-abilities">
<h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeTalentPlural'}}</h4>
{{#> ifHasItemOfType itemsArray=itemsByType.talent dataType='talent' }}
<ol class="ds4-item-list ds4-item-list--talent item-list">
{{> talentListHeader}}
{{#> systems/ds4/templates/actor/partials/item-list-header.hbs }}
{{!-- rank info --}}
<div>{{localize 'DS4.TalentRank'}}</div>
{{/systems/ds4/templates/actor/partials/item-list-header.hbs}}
{{#each itemsByType.talent as |item id|}}
{{> talentListEntry item=item}}
{{/each}}
@ -120,7 +104,7 @@
<h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeRacialAbilityPlural'}}</h4>
{{#> ifHasItemOfType itemsArray=itemsByType.racialAbility dataType='racialAbility' }}
<ol class="ds4-item-list ds4-item-list--racial-ability item-list">
{{> baseItemListHeader}}
{{> systems/ds4/templates/actor/partials/item-list-header.hbs }}
{{#each itemsByType.racialAbility as |item id|}}
{{> baseItemListEntry item=item}}
{{/each}}
@ -130,7 +114,7 @@
<h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeLanguagePlural'}}</h4>
{{#> ifHasItemOfType itemsArray=itemsByType.language dataType='language' }}
<ol class="ds4-item-list ds4-item-list--language item-list">
{{> baseItemListHeader}}
{{> systems/ds4/templates/actor/partials/item-list-header.hbs }}
{{#each itemsByType.language as |item id|}}
{{> baseItemListEntry item=item}}
{{/each}}
@ -140,7 +124,7 @@
<h4 class="ds4-item-list-title">{{localize 'DS4.ItemTypeAlphabetPlural'}}</h4>
{{#> ifHasItemOfType itemsArray=itemsByType.alphabet dataType='alphabet' }}
<ol class="ds4-item-list ds4-item-list--alphabet item-list">
{{> baseItemListHeader}}
{{> systems/ds4/templates/actor/partials/item-list-header.hbs }}
{{#each itemsByType.alphabet as |item id|}}
{{> baseItemListEntry item=item}}
{{/each}}