From b3ac3cde843540c0c7adfa89b67bcfe18c0b2895 Mon Sep 17 00:00:00 2001 From: Johannes Loher Date: Fri, 26 Feb 2021 01:08:55 +0100 Subject: [PATCH] extract item-list-entry to commonly used partial --- src/module/ds4.ts | 1 + .../actor/partials/item-list-entry.hbs | 46 +++++++ .../actor/partials/item-list-header.hbs | 6 + .../actor/partials/items-overview.hbs | 119 ++++++++---------- .../special-creature-abilities-overview.hbs | 35 +----- .../actor/partials/spells-overview.hbs | 67 +++++----- .../partials/talents-abilities-overview.hbs | 103 +++------------ 7 files changed, 164 insertions(+), 213 deletions(-) create mode 100644 src/templates/actor/partials/item-list-entry.hbs diff --git a/src/module/ds4.ts b/src/module/ds4.ts index ca0eef0d..8927be21 100644 --- a/src/module/ds4.ts +++ b/src/module/ds4.ts @@ -65,6 +65,7 @@ async function registerHandlebarsPartials() { "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", + "systems/ds4/templates/actor/partials/item-list-entry.hbs", ]; return loadTemplates(templatePaths); } diff --git a/src/templates/actor/partials/item-list-entry.hbs b/src/templates/actor/partials/item-list-entry.hbs new file mode 100644 index 00000000..afa82e36 --- /dev/null +++ b/src/templates/actor/partials/item-list-entry.hbs @@ -0,0 +1,46 @@ +{{!-- +!-- Render an item list entry row. +!-- If the partial is called with a partial block, the partial block +!-- content is inserted before the description. + +!-- @param itemData: The data of the item. +!-- @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. +--}} +
  • + {{!-- equipped --}} + {{#if isEquipable}} + + {{/if}} + + {{!-- image --}} +
    + + {{!-- amount --}} + {{#if hasQuantity}} + + {{/if}} + + {{!-- name --}} + + + {{!-- item type specifics --}} + {{#if @partial-block }} + {{> @partial-block}} + {{/if}} + + {{!-- description --}} + {{#unless hideDescription}} +
    + {{{itemData.data.description}}}
    + {{/unless}} + + {{!-- control buttons --}} + {{> systems/ds4/templates/actor/partials/overview-control-buttons.hbs }} +
  • diff --git a/src/templates/actor/partials/item-list-header.hbs b/src/templates/actor/partials/item-list-header.hbs index b81cbb41..b9b1cf9c 100644 --- a/src/templates/actor/partials/item-list-header.hbs +++ b/src/templates/actor/partials/item-list-header.hbs @@ -13,22 +13,28 @@ {{#if isEquipable}}
    {{localize 'DS4.ItemEquippedAbbr'}}
    {{/if}} + {{!-- image --}}
    + {{!-- amount --}} {{#if hasQuantity}}
    #
    {{/if}} + {{!-- name --}}
    {{localize 'DS4.ItemName'}}
    + {{!-- item type specifics --}} {{#if @partial-block }} {{> @partial-block }} {{/if}} + {{!-- description --}} {{#unless hideDescription}}
    {{localize 'DS4.Description'}}
    {{/unless}} + {{!-- control buttons placeholder --}}
    diff --git a/src/templates/actor/partials/items-overview.hbs b/src/templates/actor/partials/items-overview.hbs index e0bbcfa9..a8e8c77c 100644 --- a/src/templates/actor/partials/items-overview.hbs +++ b/src/templates/actor/partials/items-overview.hbs @@ -19,42 +19,6 @@ {{> systems/ds4/templates/actor/partials/overview-add-button.hbs dataType=dataType }} {{/inline}} -{{!-- -!-- Render a list row from a given item. -!-- An equipped checkbox is rendered except for the case item.data.type==='loot'. -!-- The partial assumes a variable item to be given in the context. -!-- If the partial is called with a partial block, the partial block -!-- content is inserted before the description. - -!-- @param item: hand over the item to the partial as hash parameter -!-- @param partial-block: hand over custom children in the partial block. ---}} -{{#*inline "itemListEntry"}} -
  • - {{!-- equipped --}} - {{#if (ne item.type 'loot')}} - - {{/if}} - {{!-- image --}} -
    - {{!-- amount --}} - - {{!-- name --}} - - {{!-- item type specifics --}} - {{> @partial-block}} - {{!-- description --}} -
    - {{{item.data.description}}}
    - {{!-- control buttons --}} - {{> systems/ds4/templates/actor/partials/overview-control-buttons.hbs }} -
  • -{{/inline}} - - {{!-- ======================================================================== --}} {{!-- WEAPONS --}} @@ -62,23 +26,34 @@ {{#> ifHasItemOfType itemsArray=itemsByType.weapon dataType='weapon' }}
      {{#> systems/ds4/templates/actor/partials/item-list-header.hbs isEquipable=true hasQuantity=true}} + {{!-- attack type --}}
      {{localize 'DS4.AttackTypeAbbr'}}
      + + {{!-- weapon bonus --}}
      {{localize 'DS4.WeaponBonusAbbr'}}
      + + {{!-- opponent defense --}}
      {{localize 'DS4.OpponentDefenseAbbr'}}
      {{/systems/ds4/templates/actor/partials/item-list-header.hbs}} - {{#each itemsByType.weapon as |item id|}} - {{#> itemListEntry item=item}} + + {{#each itemsByType.weapon as |itemData id|}} + {{#> systems/ds4/templates/actor/partials/item-list-entry.hbs itemData=itemData isEquipable=true hasQuantity=true}} + {{!-- attack type --}}
      + style="background-image: url('{{lookup ../../config.icons.attackTypes itemData.data.attackType}}')" + title="{{lookup ../../config.i18n.attackTypes itemData.data.attackType}}">
      -
      {{ item.data.weaponBonus}}
      -
      {{ item.data.opponentDefense}}
      - {{/itemListEntry}} + + {{!-- weapon bonus --}} +
      {{ itemData.data.weaponBonus}}
      + + {{!-- opponent defense --}} +
      {{ itemData.data.opponentDefense}}
      + {{/systems/ds4/templates/actor/partials/item-list-entry.hbs}} {{/each}}
    {{/ifHasItemOfType}} @@ -88,22 +63,33 @@ {{#> ifHasItemOfType itemsArray=itemsByType.armor dataType='armor' }}
      {{#> systems/ds4/templates/actor/partials/item-list-header.hbs isEquipable=true hasQuantity=true}} + {{!-- armor material type --}}
      {{localize 'DS4.ArmorMaterialTypeAbbr'}}
      + + {{!-- armor type --}}
      {{localize 'DS4.ArmorTypeAbbr'}}
      + + {{!-- armor value --}}
      {{localize 'DS4.ArmorValueAbbr'}}
      {{/systems/ds4/templates/actor/partials/item-list-header.hbs}} - {{#each itemsByType.armor as |item id|}} - {{#> itemListEntry item=item }} -
      - {{lookup ../../config.i18n.armorMaterialTypesAbbr item.data.armorMaterialType}} + + {{#each itemsByType.armor as |itemData id|}} + {{#> systems/ds4/templates/actor/partials/item-list-entry.hbs itemData=itemData isEquipable=true hasQuantity=true}} + {{!-- armor material type --}} +
      + {{lookup ../../config.i18n.armorMaterialTypesAbbr itemData.data.armorMaterialType}}
      -
      - {{lookup ../../config.i18n.armorTypesAbbr item.data.armorType}} + + {{!-- armor type --}} +
      + {{lookup ../../config.i18n.armorTypesAbbr itemData.dataData.armorType}}
      -
      {{ item.data.armorValue}}
      - {{/itemListEntry}} + + {{!-- armor value --}} +
      {{ itemData.data.armorValue}}
      + {{/systems/ds4/templates/actor/partials/item-list-entry.hbs}} {{/each}}
    {{/ifHasItemOfType}} @@ -114,31 +100,34 @@ {{#> ifHasItemOfType itemsArray=itemsByType.shield dataType='shield' }}
      {{#> systems/ds4/templates/actor/partials/item-list-header.hbs isEquipable=true hasQuantity=true}} + {{!-- armor value --}}
      {{localize 'DS4.ArmorValueAbbr'}}
      {{/systems/ds4/templates/actor/partials/item-list-header.hbs}} - {{#each itemsByType.shield as |item id|}} - {{#> itemListEntry item=item }} -
      {{item.data.armorValue}}
      - {{/itemListEntry}} + {{#each itemsByType.shield as |itemData id|}} + {{#> systems/ds4/templates/actor/partials/item-list-entry.hbs itemData=itemData isEquipable=true hasQuantity=true}} + {{!-- armor value --}} +
      {{itemData.data.armorValue}}
      + {{/systems/ds4/templates/actor/partials/item-list-entry.hbs}} {{/each}}
    {{/ifHasItemOfType}} {{!-- EQUIPMENT --}} -

    {{localize 'DS4.ItemTypeEquipmentPlural'}}

    {{#> ifHasItemOfType itemsArray=itemsByType.equipment dataType='equipment' }}
      {{#> systems/ds4/templates/actor/partials/item-list-header.hbs isEquipable=true hasQuantity=true}} + {{!-- storage location --}}
      {{localize 'DS4.StorageLocation'}}
      {{/systems/ds4/templates/actor/partials/item-list-header.hbs}} - {{#each itemsByType.equipment as |item id|}} - {{#> itemListEntry item=item }} - systems/ds4/templates/actor/partials/item-list-entry.hbs itemData=itemData isEquipable=true hasQuantity=true}} + {{!-- storage location --}} + - {{/itemListEntry}} + {{/systems/ds4/templates/actor/partials/item-list-entry.hbs}} {{/each}}
    {{/ifHasItemOfType}} @@ -148,13 +137,15 @@ {{#> ifHasItemOfType itemsArray=itemsByType.loot dataType='loot' }}
      {{#> systems/ds4/templates/actor/partials/item-list-header.hbs hasQuantity=true}} + {{!-- storage location --}}
      {{localize 'DS4.StorageLocation'}}
      {{/systems/ds4/templates/actor/partials/item-list-header.hbs}} - {{#each itemsByType.loot as |item id|}} - {{#> itemListEntry item=item }} - systems/ds4/templates/actor/partials/item-list-entry.hbs itemData=itemData hasQuantity=true}} + {{!-- storage location --}} + - {{/itemListEntry}} + {{/systems/ds4/templates/actor/partials/item-list-entry.hbs}} {{/each}}
    {{/ifHasItemOfType}} diff --git a/src/templates/actor/partials/special-creature-abilities-overview.hbs b/src/templates/actor/partials/special-creature-abilities-overview.hbs index 9ac5b668..eef96adf 100644 --- a/src/templates/actor/partials/special-creature-abilities-overview.hbs +++ b/src/templates/actor/partials/special-creature-abilities-overview.hbs @@ -1,39 +1,8 @@ -{{!-- TODO: Refactor to avoid code duplication with items-overview and talents-overview --}} - -{{!-- ======================================================================== --}} -{{!-- INLINE PARTIAL DEFINITIONS --}} -{{!-- ======================================================================== --}} - -{{!-- -!-- Render a list row for a base item from a given item. -!-- Base item means it just has an image, a description, and a name (and effects). -!-- It is a flexbox with a child for each item value of interest. -!-- The partial assumes a variable item to be given in the context. -!-- -!-- @param item: hand over the item to the partial as hash parameter ---}} -{{#*inline "itemListEntry"}} -
  • - {{!-- image --}} -
    - {{!-- name --}} - - {{!-- description --}} -
    - {{{item.data.description}}}
    - {{!-- control buttons --}} - {{> systems/ds4/templates/actor/partials/overview-control-buttons.hbs }} -
  • -{{/inline}} - -{{!-- ======================================================================== --}} -
      {{> systems/ds4/templates/actor/partials/item-list-header.hbs }} - {{#each itemsByType.specialCreatureAbility as |item id|}} - {{> itemListEntry item=item}} + {{#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' }} diff --git a/src/templates/actor/partials/spells-overview.hbs b/src/templates/actor/partials/spells-overview.hbs index 6dbfacf5..558a14c9 100644 --- a/src/templates/actor/partials/spells-overview.hbs +++ b/src/templates/actor/partials/spells-overview.hbs @@ -5,30 +5,32 @@ {{!-- !-- Base template to display a value with unit. !-- @param unitDatum: the object to display; must have a value and a unit attribute -!-- @param localizationString +!-- @param titleKey: The key of the localized title to use. !-- @param unitNames: mapping of allowed unitDatum.unit values to localized unit name !-- @param unitAbbrs: mapping of allowed unitDatum.unit values to unit abbreviation --}} {{#*inline "unit"}} -
    +
    {{#if unitDatum.value }} {{unitDatum.value}} {{lookup unitAbbrs unitDatum.unit}} {{else}}-{{/if}}
    {{/inline}} + {{!-- !-- Two templates based on the "unit" template for displaying values with unit. !-- Both accept a `config` object holding the unitNames and unitAbbr instead of !-- directly handing over the latter two. +!-- @param titleKey: The key of the localized title to use. --}} {{#*inline "temporalUnit"}} {{> unit unitNames=config.i18n.temporalUnits unitAbbrs=config.i18n.temporalUnitsAbbr unitDatum=unitDatum -localizationString=localizationString}} +titleKey=titleKey}} {{/inline}} {{#*inline "distanceUnit"}} {{> unit unitNames=config.i18n.distanceUnits unitAbbrs=config.i18n.distanceUnitsAbbr unitDatum=unitDatum -localizationString=localizationString}} +titleKey=titleKey}} {{/inline}} @@ -40,44 +42,43 @@ localizationString=localizationString}} {{#> systems/ds4/templates/actor/partials/item-list-header.hbs isEquipable=true hideDescription=true}} {{!-- spell type --}}
    {{localize 'DS4.SpellTypeAbbr'}}
    + {{!-- spell bonus --}}
    {{localize 'DS4.SpellBonusAbbr'}}
    + {{!-- max. distance --}}
    + {{!-- duration --}}
    + {{!-- cooldown duration --}}
    {{/systems/ds4/templates/actor/partials/item-list-header.hbs}} - {{#each itemsByType.spell as |item id|}} -
  • - - {{!-- image --}} -
    - {{!-- name --}} - - {{!-- spell type --}} -
    -
    - {{!-- spell bonus --}} - - {{!-- max. distance --}} - {{> distanceUnit localizationString='DS4.SpellMaxDistance' unitDatum=item.data.data.maxDistance - config=../config}} - {{!-- duration --}} - {{> temporalUnit localizationString='DS4.SpellDuration' unitDatum=item.data.data.duration config=../config}} - {{!-- cooldown duration --}} - {{> temporalUnit localizationString='DS4.SpellCooldownDuration' unitDatum=item.data.data.cooldownDuration - config=../config}} - {{!-- control buttons --}} - {{> systems/ds4/templates/actor/partials/overview-control-buttons.hbs }} -
  • + {{#each itemsByType.spell as |itemData id|}} + {{#> systems/ds4/templates/actor/partials/item-list-entry.hbs itemData=itemData isEquipable=true + hideDescription=true}} + {{!-- spell type --}} +
    +
    + + {{!-- spell bonus --}} + + + {{!-- max. distance --}} + {{> distanceUnit titleKey='DS4.SpellMaxDistance' unitDatum=itemData.data.maxDistance + config=../../config}} + + {{!-- duration --}} + {{> temporalUnit titleKey='DS4.SpellDuration' unitDatum=itemData.data.duration config=../../config}} + + {{!-- cooldown duration --}} + {{> temporalUnit titleKey='DS4.SpellCooldownDuration' unitDatum=itemData.data.cooldownDuration + config=../../config}} + {{/systems/ds4/templates/actor/partials/item-list-entry.hbs}} {{/each}} {{!-- add button --}} diff --git a/src/templates/actor/partials/talents-abilities-overview.hbs b/src/templates/actor/partials/talents-abilities-overview.hbs index 0d2f5436..e212a5d4 100644 --- a/src/templates/actor/partials/talents-abilities-overview.hbs +++ b/src/templates/actor/partials/talents-abilities-overview.hbs @@ -19,114 +19,51 @@ {{> systems/ds4/templates/actor/partials/overview-add-button.hbs dataType=dataType }} {{/inline}} - -{{!-- -!-- Render a talent list row from a given item. -!-- It is a flexbox with a child for each item value of interest. -!-- The partial assumes a variable item to be given in the context. -!-- -!-- @param item: hand over the item to the partial as hash parameter ---}} -{{#*inline "talentListEntry"}} -
  • - {{!-- image --}} -
    - {{!-- name --}} - - {{!-- talent tank equation --}} - {{> systems/ds4/templates/actor/partials/talent-rank-equation.hbs talentRank=item.data.rank}} - {{!-- description --}} -
    - {{{item.data.description}}}
    - {{!-- control buttons --}} - {{> systems/ds4/templates/actor/partials/overview-control-buttons.hbs }} -
  • -{{/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 "talentListHeader"}} -
  • - {{!-- image --}} -
    - {{!-- name --}} -
    {{localize 'DS4.ItemName'}}
    - {{!-- description --}} -
    {{localize 'DS4.Description'}}
    - {{!-- control buttons placeholder --}} -
    -
  • -{{/inline}} - - -{{!-- -!-- Render a list row for a base item from a given item. -!-- Base item means it just has an image, a description, and a name (and effects). -!-- It is a flexbox with a child for each item value of interest. -!-- The partial assumes a variable item to be given in the context. -!-- -!-- @param item: hand over the item to the partial as hash parameter ---}} -{{#*inline "baseItemListEntry"}} -
  • - {{!-- image --}} -
    - {{!-- name --}} - - {{!-- description --}} -
    - {{{item.data.description}}}
    - {{!-- control buttons --}} - {{> systems/ds4/templates/actor/partials/overview-control-buttons.hbs }} -
  • -{{/inline}} - {{!-- ======================================================================== --}}

    {{localize 'DS4.ItemTypeTalentPlural'}}

    - {{#> ifHasItemOfType itemsArray=itemsByType.talent dataType='talent' }} + {{#> ifHasItemOfType itemsArray=itemsByType.talent dataType='talent'}}
      - {{#> systems/ds4/templates/actor/partials/item-list-header.hbs }} - {{!-- rank info --}} + {{#> systems/ds4/templates/actor/partials/item-list-header.hbs}} + {{!-- rank --}}
      {{localize 'DS4.TalentRank'}}
      {{/systems/ds4/templates/actor/partials/item-list-header.hbs}} - {{#each itemsByType.talent as |item id|}} - {{> talentListEntry item=item}} + {{#each itemsByType.talent as |itemData id|}} + {{#> systems/ds4/templates/actor/partials/item-list-entry.hbs itemData=itemData}} + {{!-- rank --}} + {{> systems/ds4/templates/actor/partials/talent-rank-equation.hbs talentRank=itemData.data.rank}} + {{/systems/ds4/templates/actor/partials/item-list-entry.hbs}} {{/each}}
    {{/ifHasItemOfType}}

    {{localize 'DS4.ItemTypeRacialAbilityPlural'}}

    - {{#> ifHasItemOfType itemsArray=itemsByType.racialAbility dataType='racialAbility' }} + {{#> ifHasItemOfType itemsArray=itemsByType.racialAbility dataType='racialAbility'}}
      - {{> systems/ds4/templates/actor/partials/item-list-header.hbs }} - {{#each itemsByType.racialAbility as |item id|}} - {{> baseItemListEntry item=item}} + {{> 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}}

    {{localize 'DS4.ItemTypeLanguagePlural'}}

    - {{#> ifHasItemOfType itemsArray=itemsByType.language dataType='language' }} + {{#> ifHasItemOfType itemsArray=itemsByType.language dataType='language'}}
      - {{> systems/ds4/templates/actor/partials/item-list-header.hbs }} - {{#each itemsByType.language as |item id|}} - {{> baseItemListEntry item=item}} + {{> 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}}

    {{localize 'DS4.ItemTypeAlphabetPlural'}}

    - {{#> ifHasItemOfType itemsArray=itemsByType.alphabet dataType='alphabet' }} + {{#> ifHasItemOfType itemsArray=itemsByType.alphabet dataType='alphabet'}}
      - {{> systems/ds4/templates/actor/partials/item-list-header.hbs }} - {{#each itemsByType.alphabet as |item id|}} - {{> baseItemListEntry item=item}} + {{> 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}}