From e39d245affa22ea97c61f9961dd47209034afd8e Mon Sep 17 00:00:00 2001 From: Johannes Loher Date: Tue, 20 Jul 2021 02:16:43 +0200 Subject: [PATCH 01/18] WIP: Add effects tab to actor sheets --- src/lang/de.json | 17 +++-- src/lang/en.json | 17 +++-- src/module/actor/sheets/actor-sheet.ts | 40 ++++++++++- src/module/handlebars/handlebars-partials.ts | 5 +- src/module/item/item-sheet.ts | 1 + src/scss/components/_effect_list.scss | 68 +++++++++++++++++++ src/scss/ds4.scss | 1 + .../sheets/actor/character-sheet.hbs | 4 ++ .../sheets/actor/components/add-button.hbs | 19 ++++++ .../actor/components/effect-list-entry.hbs | 31 +++++++++ .../actor/components/effect-list-header.hbs | 26 +++++++ .../actor/components/items-overview.hbs | 15 ++-- .../actor/components/overview-add-button.hbs | 17 ----- .../components/overview-control-buttons.hbs | 5 +- src/templates/sheets/actor/creature-sheet.hbs | 4 ++ src/templates/sheets/actor/tabs/abilities.hbs | 12 ++-- src/templates/sheets/actor/tabs/effects.hbs | 19 ++++++ .../actor/tabs/special-creature-abilities.hbs | 3 +- src/templates/sheets/actor/tabs/spells.hbs | 3 +- src/templates/sheets/item/tabs/effects.hbs | 9 +-- 20 files changed, 267 insertions(+), 49 deletions(-) create mode 100644 src/scss/components/_effect_list.scss create mode 100644 src/templates/sheets/actor/components/add-button.hbs create mode 100644 src/templates/sheets/actor/components/effect-list-entry.hbs create mode 100644 src/templates/sheets/actor/components/effect-list-header.hbs delete mode 100644 src/templates/sheets/actor/components/overview-add-button.hbs create mode 100644 src/templates/sheets/actor/tabs/effects.hbs diff --git a/src/lang/de.json b/src/lang/de.json index 2d37befb..a268faa3 100644 --- a/src/lang/de.json +++ b/src/lang/de.json @@ -1,10 +1,11 @@ { - "DS4.UserInteractionAddItem": "Neu", - "DS4.UserInteractionEditItem": "Bearbeiten", - "DS4.UserInteractionDeleteItem": "Löschen", - "DS4.UserInteractionAddEffect": "Neuer Effekt", - "DS4.UserInteractionEditEffect": "Effekt bearbeiten", - "DS4.UserInteractionDeleteEffect": "Effekt löschen", + "DS4.UserInteractionAdd": "Neu", + "DS4.UserInteractionAddItemTitle": "Item Erstellen", + "DS4.UserInteractionEditItemTitle": "Item Bearbeiten", + "DS4.UserInteractionDeleteItemTitle": "Item Löschen", + "DS4.UserInteractionAddEffectTitle": "Effekt Erstellen", + "DS4.UserInteractionEditEffectTitle": "Effekt Bearbeiten", + "DS4.UserInteractionDeleteEffectTitle": "Effekt Löschen", "DS4.DocumentImageAltText": "Bild von {name}", "DS4.RollableImageRollableTitle": "Für {name} würfeln", "DS4.DiceOverlayImageAltText": "Bild eines W20", @@ -121,6 +122,10 @@ "DS4.SpellMinimumLevelsSorcerer": "Zugangsstufe für Schwarzmagier", "DS4.SpellMinimumLevelsSorcererAbbr": "Zugangsstufe Sch", "DS4.SpellPrice": "Preis (Gold)", + "DS4.EffectEnabled": "Aktiv", + "DS4.EffectEnabledAbbr": "A", + "DS4.EffectLabel": "Bezeichnung", + "DS4.EffectSource": "Quelle", "DS4.ActorName": "Name", "DS4.ActorImageAltText": "Bild des Aktors", "DS4.ActorTypeCharacter": "Charakter", diff --git a/src/lang/en.json b/src/lang/en.json index 60f638ac..1b94e0cc 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -1,10 +1,11 @@ { - "DS4.UserInteractionAddItem": "Add item", - "DS4.UserInteractionEditItem": "Edit item", - "DS4.UserInteractionDeleteItem": "Delete item", - "DS4.UserInteractionAddEffect": "Add Effect", - "DS4.UserInteractionEditEffect": "Edit Effect", - "DS4.UserInteractionDeleteEffect": "Delete Effect", + "DS4.UserInteractionAdd": "Add", + "DS4.UserInteractionAddItemTitle": "Create Item", + "DS4.UserInteractionEditItemTitle": "Edit Item", + "DS4.UserInteractionDeleteItemTitle": "Delete Item", + "DS4.UserInteractionAddEffectTitle": "Create Effect", + "DS4.UserInteractionEditEffectTitle": "Edit Effect", + "DS4.UserInteractionDeleteEffectTitle": "Delete Effect", "DS4.DocumentImageAltText": "Image of {name}", "DS4.RollableImageRollableTitle": "Roll for {name}", "DS4.DiceOverlayImageAltText": "Image of a d20", @@ -121,6 +122,10 @@ "DS4.SpellMinimumLevelsSorcerer": "Minimum level for Sorcerers", "DS4.SpellMinimumLevelsSorcererAbbr": "Min lvl SRC", "DS4.SpellPrice": "Price (Gold)", + "DS4.EffectEnabled": "Enabled", + "DS4.EffectEnabledAbbr": "E", + "DS4.EffectLabel": "Label", + "DS4.EffectSource": "Source", "DS4.ActorName": "Name", "DS4.ActorImageAltText": "Image of the Actor", "DS4.ActorTypeCharacter": "Character", diff --git a/src/module/actor/sheets/actor-sheet.ts b/src/module/actor/sheets/actor-sheet.ts index c254ee97..859c3821 100644 --- a/src/module/actor/sheets/actor-sheet.ts +++ b/src/module/actor/sheets/actor-sheet.ts @@ -11,6 +11,7 @@ import { getCanvas, getGame } from "../../helpers"; import { DS4Item } from "../../item/item"; import { DS4Settings, getDS4Settings } from "../../settings"; import notifications from "../../ui/notifications"; +import { DS4Actor } from "../actor"; import { isCheck } from "../actor-data-properties"; /** @@ -30,6 +31,7 @@ export class DS4ActorSheet extends ActorSheet item.data).sort((a, b) => (a.sort || 0) - (b.sort || 0))]; }), ); + + const enrichedEffectPromises = this.actor.effects.toObject().map(async (effect) => { + const originatingDocument = effect.origin !== undefined ? await fromUuid(effect.origin) : undefined; + const source = + (originatingDocument instanceof DS4Actor || originatingDocument instanceof DS4Item + ? originatingDocument.name + : null) ?? undefined; + + return { + ...effect, + source, + }; + }); + const enrichedEffects = await Promise.all(enrichedEffectPromises); + const data = { ...this.addTooltipsToData(await super.getData()), - // Add the localization config to the data: config: DS4, - // Add the items explicitly sorted by type to the data: itemsByType, + enrichedEffects, settings: getDS4Settings(), }; return data; @@ -121,6 +137,8 @@ export class DS4ActorSheet extends ActorSheet { config: typeof DS4; itemsByType: Record; + enrichedEffects: EnrichedActiveEffectDataSource[]; settings: DS4Settings; } + +type ActiveEffectDataSource = foundry.data.ActiveEffectData["_source"]; + +interface EnrichedActiveEffectDataSource extends ActiveEffectDataSource { + source?: string; +} diff --git a/src/module/handlebars/handlebars-partials.ts b/src/module/handlebars/handlebars-partials.ts index 738cf21b..3215a7e6 100644 --- a/src/module/handlebars/handlebars-partials.ts +++ b/src/module/handlebars/handlebars-partials.ts @@ -8,6 +8,7 @@ export default async function registerHandlebarsPartials(): Promise { const templatePaths = [ "systems/ds4/templates/sheets/actor/components/actor-header.hbs", "systems/ds4/templates/sheets/actor/components/actor-progression.hbs", + "systems/ds4/templates/sheets/actor/components/add-button.hbs", "systems/ds4/templates/sheets/actor/components/biography.hbs", "systems/ds4/templates/sheets/actor/components/character-properties.hbs", "systems/ds4/templates/sheets/actor/components/check.hbs", @@ -18,10 +19,11 @@ export default async function registerHandlebarsPartials(): Promise { "systems/ds4/templates/sheets/actor/components/core-values.hbs", "systems/ds4/templates/sheets/actor/components/creature-properties.hbs", "systems/ds4/templates/sheets/actor/components/currency.hbs", + "systems/ds4/templates/sheets/actor/components/effect-list-entry.hbs", + "systems/ds4/templates/sheets/actor/components/effect-list-header.hbs", "systems/ds4/templates/sheets/actor/components/item-list-entry.hbs", "systems/ds4/templates/sheets/actor/components/item-list-header.hbs", "systems/ds4/templates/sheets/actor/components/items-overview.hbs", - "systems/ds4/templates/sheets/actor/components/overview-add-button.hbs", "systems/ds4/templates/sheets/actor/components/overview-control-buttons.hbs", "systems/ds4/templates/sheets/actor/components/profile.hbs", "systems/ds4/templates/sheets/actor/components/rollable-image.hbs", @@ -31,6 +33,7 @@ export default async function registerHandlebarsPartials(): Promise { "systems/ds4/templates/sheets/actor/tabs/character-inventory.hbs", "systems/ds4/templates/sheets/actor/tabs/creature-inventory.hbs", "systems/ds4/templates/sheets/actor/tabs/description.hbs", + "systems/ds4/templates/sheets/actor/tabs/effects.hbs", "systems/ds4/templates/sheets/actor/tabs/special-creature-abilities.hbs", "systems/ds4/templates/sheets/actor/tabs/spells.hbs", "systems/ds4/templates/sheets/actor/tabs/values.hbs", diff --git a/src/module/item/item-sheet.ts b/src/module/item/item-sheet.ts index d604df7f..7fc5f8e5 100644 --- a/src/module/item/item-sheet.ts +++ b/src/module/item/item-sheet.ts @@ -101,6 +101,7 @@ export class DS4ItemSheet extends ItemSheet const createData = { label: "New Effect", icon: "icons/svg/aura.svg", + origin: this.item.uuid, }; return ActiveEffect.create(createData, { parent: this.item }); diff --git a/src/scss/components/_effect_list.scss b/src/scss/components/_effect_list.scss new file mode 100644 index 00000000..06e18d36 --- /dev/null +++ b/src/scss/components/_effect_list.scss @@ -0,0 +1,68 @@ +/* + * SPDX-FileCopyrightText: 2021 Johannes Loher + * SPDX-FileCopyrightText: 2021 Gesina Schwalbe + * + * SPDX-License-Identifier: MIT + */ + +@use "../utils/mixins"; +@use "../utils/variables"; + +.ds4-effect-list { + @include mixins.mark-invalid-or-disabled-input; + + $row-height: 1.75em; + + align-items: center; + display: grid; + grid-column-gap: 0.5em; + grid-row-gap: 0.2em; + grid-template-columns: $row-height $row-height 3fr 2fr 5ch; + margin: 0.5em 0; + overflow-y: auto; + padding: 0; + + :nth-child(5n + 1) { + justify-self: center; + } + + &__row { + display: contents; // TODO: Once chromium supports `grid-template-columns: subgrid` (https://bugs.chromium.org/p/chromium/issues/detail?id=618969), switch to `display: grid; grid: 1/-1; grid-template-columns: subgrid` + + &--header { + font-weight: bold; + } + + > * { + height: $row-height; + line-height: $row-height; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + } + } + + &__image { + border: none; + } + + &__editable { + background-color: transparent; + border: 0; + padding: 0; + + &--checkbox { + width: 100%; + height: 100%; + margin: 0px; + } + } + + &__control-buttons { + display: grid; + grid-template-columns: 1fr 1fr; + text-align: center; + width: 100%; + padding: 0 calc(1em / 3); + } +} diff --git a/src/scss/ds4.scss b/src/scss/ds4.scss index a6afe386..c49150b5 100644 --- a/src/scss/ds4.scss +++ b/src/scss/ds4.scss @@ -33,6 +33,7 @@ @include meta.load-css("components/core_values"); @include meta.load-css("components/currency"); @include meta.load-css("components/description"); + @include meta.load-css("components/effect_list"); @include meta.load-css("components/forms"); @include meta.load-css("components/item_list"); @include meta.load-css("components/profile"); diff --git a/src/templates/sheets/actor/character-sheet.hbs b/src/templates/sheets/actor/character-sheet.hbs index 99ff588c..8dcc5a2a 100644 --- a/src/templates/sheets/actor/character-sheet.hbs +++ b/src/templates/sheets/actor/character-sheet.hbs @@ -18,6 +18,7 @@ SPDX-License-Identifier: MIT {{localize 'DS4.HeadingInventory'}} {{localize 'DS4.HeadingSpells'}} {{localize 'DS4.HeadingAbilities'}} + {{localize 'DS4.HeadingEffects'}} {{localize 'DS4.HeadingBiography'}} @@ -37,6 +38,9 @@ SPDX-License-Identifier: MIT {{!-- Abilities Tab --}} {{> systems/ds4/templates/sheets/actor/tabs/abilities.hbs}} +{{!-- Effects Tab --}} +{{> systems/ds4/templates/sheets/actor/tabs/effects.hbs}} + {{!-- Biography Tab --}} {{> systems/ds4/templates/sheets/actor/tabs/biography.hbs}} diff --git a/src/templates/sheets/actor/components/add-button.hbs b/src/templates/sheets/actor/components/add-button.hbs new file mode 100644 index 00000000..916a0eee --- /dev/null +++ b/src/templates/sheets/actor/components/add-button.hbs @@ -0,0 +1,19 @@ +{{!-- +SPDX-FileCopyrightText: 2021 Johannes Loher +SPDX-FileCopyrightText: 2021 Gesina Schwalbe + +SPDX-License-Identifier: MIT +--}} + +{{! +!-- Render an "add" button. +!-- @param class: The css class to use for the link element +!-- @param title: The title to use for the link element (will be localized) +!-- @param type: An optional property to use as data-type attribute +}} + diff --git a/src/templates/sheets/actor/components/effect-list-entry.hbs b/src/templates/sheets/actor/components/effect-list-entry.hbs new file mode 100644 index 00000000..2fa4f334 --- /dev/null +++ b/src/templates/sheets/actor/components/effect-list-entry.hbs @@ -0,0 +1,31 @@ +{{!-- +SPDX-FileCopyrightText: 2021 Johannes Loher +SPDX-FileCopyrightText: 2021 Gesina Schwalbe + +SPDX-License-Identifier: MIT +--}} + +{{!-- +!-- Render an effect list entry row. +!-- @param effectData: The data of the item. +--}} +
  • + {{!-- enabled --}} + + + {{!-- icon --}} + {{> systems/ds4/templates/sheets/actor/components/rollable-image.hbs rollable=false src=effectData.icon + alt=(localize "DS4.EffectIconAltText" label=effectData.label) title=effectData.label}} + + {{!-- label --}} +
    {{effectData.label}}
    + + {{!-- source --}} +
    {{effectData.source}}
    + + {{!-- control buttons --}} + {{> systems/ds4/templates/sheets/actor/components/overview-control-buttons.hbs + class="ds4-effect-list__control-buttons" }} +
  • diff --git a/src/templates/sheets/actor/components/effect-list-header.hbs b/src/templates/sheets/actor/components/effect-list-header.hbs new file mode 100644 index 00000000..3256c9b2 --- /dev/null +++ b/src/templates/sheets/actor/components/effect-list-header.hbs @@ -0,0 +1,26 @@ +{{!-- +SPDX-FileCopyrightText: 2021 Johannes Loher +SPDX-FileCopyrightText: 2021 Gesina Schwalbe + +SPDX-License-Identifier: MIT +--}} + +{{!-- +!-- Render an effect list header row. +--}} +
  • + {{!-- enabled --}} +
    {{localize 'DS4.EffectEnabledAbbr'}}
    + + {{!-- icon --}} +
    + + {{!-- label --}} +
    {{localize 'DS4.EffectLabel'}}
    + + {{!-- origin --}} +
    {{localize 'DS4.EffectSource'}}
    + + {{!-- control buttons placeholder --}} +
    +
  • diff --git a/src/templates/sheets/actor/components/items-overview.hbs b/src/templates/sheets/actor/components/items-overview.hbs index e3d4d292..ce44395a 100644 --- a/src/templates/sheets/actor/components/items-overview.hbs +++ b/src/templates/sheets/actor/components/items-overview.hbs @@ -41,7 +41,8 @@ SPDX-License-Identifier: MIT {{/each}} {{/unless}} -{{> systems/ds4/templates/sheets/actor/components/overview-add-button.hbs dataType='weapon'}} +{{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle' +class='item-create' type='weapon'}} {{!-- ARMOR --}}

    {{localize 'DS4.ItemTypeArmorPlural'}}

    @@ -79,7 +80,8 @@ SPDX-License-Identifier: MIT {{/each}} {{/unless}} -{{> systems/ds4/templates/sheets/actor/components/overview-add-button.hbs dataType='armor'}} +{{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle' +class='item-create' type='armor'}} {{!-- SHIELD --}}

    {{localize 'DS4.ItemTypeShieldPlural'}}

    @@ -100,7 +102,8 @@ SPDX-License-Identifier: MIT {{/each}} {{/unless}} -{{> systems/ds4/templates/sheets/actor/components/overview-add-button.hbs dataType='shield'}} +{{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle' +class='item-create' type='shield'}} {{!-- EQUIPMENT --}}

    {{localize 'DS4.ItemTypeEquipmentPlural'}}

    @@ -120,7 +123,8 @@ SPDX-License-Identifier: MIT {{/each}} {{/unless}} -{{> systems/ds4/templates/sheets/actor/components/overview-add-button.hbs dataType='equipment'}} +{{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle' +class='item-create' type='equipment'}} {{!-- LOOT --}}

    {{localize 'DS4.ItemTypeLootPlural'}}

    @@ -139,4 +143,5 @@ SPDX-License-Identifier: MIT {{/each}} {{/unless}} -{{> systems/ds4/templates/sheets/actor/components/overview-add-button.hbs dataType='loot'}} +{{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle' +class='item-create' type='loot'}} diff --git a/src/templates/sheets/actor/components/overview-add-button.hbs b/src/templates/sheets/actor/components/overview-add-button.hbs deleted file mode 100644 index a041ac9b..00000000 --- a/src/templates/sheets/actor/components/overview-add-button.hbs +++ /dev/null @@ -1,17 +0,0 @@ -{{!-- -SPDX-FileCopyrightText: 2021 Johannes Loher -SPDX-FileCopyrightText: 2021 Gesina Schwalbe - -SPDX-License-Identifier: MIT ---}} - -{{! -!-- Render an "add" button for adding an item of given data type. -!-- @param dataType: hand over the dataType to the partial as hash parameter -}} - diff --git a/src/templates/sheets/actor/components/overview-control-buttons.hbs b/src/templates/sheets/actor/components/overview-control-buttons.hbs index e3078224..07c3b8d5 100644 --- a/src/templates/sheets/actor/components/overview-control-buttons.hbs +++ b/src/templates/sheets/actor/components/overview-control-buttons.hbs @@ -11,7 +11,8 @@ SPDX-License-Identifier: MIT !-- @param class: Additional CSS class(es) for the controls --}}
    - - +
    diff --git a/src/templates/sheets/actor/creature-sheet.hbs b/src/templates/sheets/actor/creature-sheet.hbs index 12e78d61..de12472b 100644 --- a/src/templates/sheets/actor/creature-sheet.hbs +++ b/src/templates/sheets/actor/creature-sheet.hbs @@ -20,6 +20,7 @@ SPDX-License-Identifier: MIT {{localize 'DS4.HeadingSpecialCreatureAbilities'}} {{localize 'DS4.HeadingSpells'}} + {{localize 'DS4.HeadingEffects'}} {{localize 'DS4.HeadingDescription'}} @@ -37,6 +38,9 @@ SPDX-License-Identifier: MIT {{!-- Spells Tab --}} {{> systems/ds4/templates/sheets/actor/tabs/spells.hbs}} + {{!-- Effects Tab --}} + {{> systems/ds4/templates/sheets/actor/tabs/effects.hbs}} + {{!-- Description Tab --}} {{> systems/ds4/templates/sheets/actor/tabs/description.hbs}} diff --git a/src/templates/sheets/actor/tabs/abilities.hbs b/src/templates/sheets/actor/tabs/abilities.hbs index 99217df6..5163fb94 100644 --- a/src/templates/sheets/actor/tabs/abilities.hbs +++ b/src/templates/sheets/actor/tabs/abilities.hbs @@ -22,7 +22,8 @@ SPDX-License-Identifier: MIT {{/each}} {{/unless}} - {{> systems/ds4/templates/sheets/actor/components/overview-add-button.hbs dataType='talent'}} + {{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle' + class='item-create' type='talent'}} {{!-- RACIAL ABILITY --}}

    {{localize 'DS4.ItemTypeRacialAbilityPlural'}}

    @@ -34,7 +35,8 @@ SPDX-License-Identifier: MIT {{/each}} {{/unless}} - {{> systems/ds4/templates/sheets/actor/components/overview-add-button.hbs dataType='racialAbility'}} + {{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle' + class='item-create' type='racialAbility'}} {{!-- LANGUAGE --}}

    {{localize 'DS4.ItemTypeLanguagePlural'}}

    @@ -46,7 +48,8 @@ SPDX-License-Identifier: MIT {{/each}} {{/unless}} - {{> systems/ds4/templates/sheets/actor/components/overview-add-button.hbs dataType='language'}} + {{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle' + class='item-create' type='language'}} {{!-- ALPHABET --}}

    {{localize 'DS4.ItemTypeAlphabetPlural'}}

    @@ -58,5 +61,6 @@ SPDX-License-Identifier: MIT {{/each}} {{/unless}} - {{> systems/ds4/templates/sheets/actor/components/overview-add-button.hbs dataType='alphabet'}} + {{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle' + class='item-create' type='alphabet'}} diff --git a/src/templates/sheets/actor/tabs/effects.hbs b/src/templates/sheets/actor/tabs/effects.hbs new file mode 100644 index 00000000..8e3e4353 --- /dev/null +++ b/src/templates/sheets/actor/tabs/effects.hbs @@ -0,0 +1,19 @@ +{{!-- +SPDX-FileCopyrightText: 2021 Johannes Loher +SPDX-FileCopyrightText: 2021 Gesina Schwalbe + +SPDX-License-Identifier: MIT +--}} + +
    + {{#unless (isEmpty data.effects)}} +
      + {{> systems/ds4/templates/sheets/actor/components/effect-list-header.hbs}} + {{#each enrichedEffects as |effectData id| }} + {{> systems/ds4/templates/sheets/actor/components/effect-list-entry.hbs effectData=effectData}} + {{/each}} +
    + {{/unless}} + {{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddEffectTitle' + class='effect-create'}} +
    diff --git a/src/templates/sheets/actor/tabs/special-creature-abilities.hbs b/src/templates/sheets/actor/tabs/special-creature-abilities.hbs index 6782d481..15d52d56 100644 --- a/src/templates/sheets/actor/tabs/special-creature-abilities.hbs +++ b/src/templates/sheets/actor/tabs/special-creature-abilities.hbs @@ -14,5 +14,6 @@ SPDX-License-Identifier: MIT {{/each}} {{/unless}} - {{> systems/ds4/templates/sheets/actor/components/overview-add-button.hbs dataType='specialCreatureAbility'}} + {{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle' + class='item-create' type='specialCreatureAbility'}} diff --git a/src/templates/sheets/actor/tabs/spells.hbs b/src/templates/sheets/actor/tabs/spells.hbs index 4dac5d28..5b5b44e4 100644 --- a/src/templates/sheets/actor/tabs/spells.hbs +++ b/src/templates/sheets/actor/tabs/spells.hbs @@ -93,5 +93,6 @@ titleKey=titleKey}} {{/each}} {{/unless}} - {{> systems/ds4/templates/sheets/actor/components/overview-add-button.hbs dataType='spell' }} + {{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle' + class='item-create' type='spell'}} diff --git a/src/templates/sheets/item/tabs/effects.hbs b/src/templates/sheets/item/tabs/effects.hbs index 2fd894a1..0404d749 100644 --- a/src/templates/sheets/item/tabs/effects.hbs +++ b/src/templates/sheets/item/tabs/effects.hbs @@ -12,17 +12,18 @@ SPDX-License-Identifier: MIT
    Name
    {{#each item.effects as |effect id|}}
  • {{effect.data.label}}

  • From 4d2a7d1686b657346b7304af7d0141972b7c2d4f Mon Sep 17 00:00:00 2001 From: Johannes Loher Date: Tue, 20 Jul 2021 02:35:55 +0200 Subject: [PATCH 02/18] Simplify getting the source name of effects --- src/lang/de.json | 2 +- src/lang/en.json | 2 +- src/module/active-effect.ts | 7 +++++++ src/module/actor/sheets/actor-sheet.ts | 15 ++++----------- .../sheets/actor/components/effect-list-entry.hbs | 4 ++-- .../actor/components/effect-list-header.hbs | 4 ++-- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/lang/de.json b/src/lang/de.json index a268faa3..5a6b293c 100644 --- a/src/lang/de.json +++ b/src/lang/de.json @@ -125,7 +125,7 @@ "DS4.EffectEnabled": "Aktiv", "DS4.EffectEnabledAbbr": "A", "DS4.EffectLabel": "Bezeichnung", - "DS4.EffectSource": "Quelle", + "DS4.EffectSourceName": "Quelle", "DS4.ActorName": "Name", "DS4.ActorImageAltText": "Bild des Aktors", "DS4.ActorTypeCharacter": "Charakter", diff --git a/src/lang/en.json b/src/lang/en.json index 1b94e0cc..9ce4238a 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -125,7 +125,7 @@ "DS4.EffectEnabled": "Enabled", "DS4.EffectEnabledAbbr": "E", "DS4.EffectLabel": "Label", - "DS4.EffectSource": "Source", + "DS4.EffectSourceName": "Source", "DS4.ActorName": "Name", "DS4.ActorImageAltText": "Image of the Actor", "DS4.ActorTypeCharacter": "Character", diff --git a/src/module/active-effect.ts b/src/module/active-effect.ts index 1ae6eccc..6ae292d6 100644 --- a/src/module/active-effect.ts +++ b/src/module/active-effect.ts @@ -21,4 +21,11 @@ export class DS4ActiveEffect extends ActiveEffect { } return super.apply(actor, change); } + + /** + * A public wrapper for {@link ActiveEffect#_getSourceName}. + */ + async getSourceName(): Promise { + return this._getSourceName(); + } } diff --git a/src/module/actor/sheets/actor-sheet.ts b/src/module/actor/sheets/actor-sheet.ts index 859c3821..7f111cdc 100644 --- a/src/module/actor/sheets/actor-sheet.ts +++ b/src/module/actor/sheets/actor-sheet.ts @@ -11,7 +11,6 @@ import { getCanvas, getGame } from "../../helpers"; import { DS4Item } from "../../item/item"; import { DS4Settings, getDS4Settings } from "../../settings"; import notifications from "../../ui/notifications"; -import { DS4Actor } from "../actor"; import { isCheck } from "../actor-data-properties"; /** @@ -61,16 +60,10 @@ export class DS4ActorSheet extends ActorSheet { - const originatingDocument = effect.origin !== undefined ? await fromUuid(effect.origin) : undefined; - const source = - (originatingDocument instanceof DS4Actor || originatingDocument instanceof DS4Item - ? originatingDocument.name - : null) ?? undefined; - + const enrichedEffectPromises = this.actor.effects.map(async (effect) => { return { - ...effect, - source, + ...effect.toObject(), + sourceName: await effect.getSourceName(), }; }); const enrichedEffects = await Promise.all(enrichedEffectPromises); @@ -335,5 +328,5 @@ interface DS4ActorSheetData extends ActorSheet.Data { type ActiveEffectDataSource = foundry.data.ActiveEffectData["_source"]; interface EnrichedActiveEffectDataSource extends ActiveEffectDataSource { - source?: string; + sourceName: string; } diff --git a/src/templates/sheets/actor/components/effect-list-entry.hbs b/src/templates/sheets/actor/components/effect-list-entry.hbs index 2fa4f334..99419a5b 100644 --- a/src/templates/sheets/actor/components/effect-list-entry.hbs +++ b/src/templates/sheets/actor/components/effect-list-entry.hbs @@ -22,8 +22,8 @@ SPDX-License-Identifier: MIT {{!-- label --}}
    {{effectData.label}}
    - {{!-- source --}} -
    {{effectData.source}}
    + {{!-- source name --}} +
    {{effectData.sourceName}}
    {{!-- control buttons --}} {{> systems/ds4/templates/sheets/actor/components/overview-control-buttons.hbs diff --git a/src/templates/sheets/actor/components/effect-list-header.hbs b/src/templates/sheets/actor/components/effect-list-header.hbs index 3256c9b2..87ef2326 100644 --- a/src/templates/sheets/actor/components/effect-list-header.hbs +++ b/src/templates/sheets/actor/components/effect-list-header.hbs @@ -18,8 +18,8 @@ SPDX-License-Identifier: MIT {{!-- label --}}
    {{localize 'DS4.EffectLabel'}}
    - {{!-- origin --}} -
    {{localize 'DS4.EffectSource'}}
    + {{!-- source name --}} +
    {{localize 'DS4.EffectSourceName'}}
    {{!-- control buttons placeholder --}}
    From 808dab7f5ad72cf9a5ff819d7353c66f68a5e683 Mon Sep 17 00:00:00 2001 From: Johannes Loher Date: Thu, 22 Jul 2021 02:02:35 +0200 Subject: [PATCH 03/18] Add possibility to delete and edit effects in the actor sheet --- src/module/actor/sheets/actor-sheet.ts | 33 +++++++++++++++++-- src/module/handlebars/handlebars-partials.ts | 2 +- .../components/_control_button_group.scss | 17 ++++++++++ src/scss/components/_item_list.scss | 8 ----- src/scss/ds4.scss | 1 + .../sheets/actor/components/add-button.hbs | 5 +-- .../actor/components/control-button-group.hbs | 20 +++++++++++ .../actor/components/effect-list-entry.hbs | 8 ++--- .../actor/components/item-list-entry.hbs | 6 ++-- .../actor/components/items-overview.hbs | 10 +++--- .../components/overview-control-buttons.hbs | 18 ---------- src/templates/sheets/actor/tabs/abilities.hbs | 8 ++--- src/templates/sheets/actor/tabs/effects.hbs | 2 +- .../actor/tabs/special-creature-abilities.hbs | 2 +- src/templates/sheets/actor/tabs/spells.hbs | 2 +- 15 files changed, 91 insertions(+), 51 deletions(-) create mode 100644 src/scss/components/_control_button_group.scss create mode 100644 src/templates/sheets/actor/components/control-button-group.hbs delete mode 100644 src/templates/sheets/actor/components/overview-control-buttons.hbs diff --git a/src/module/actor/sheets/actor-sheet.ts b/src/module/actor/sheets/actor-sheet.ts index 7f111cdc..d68d29e2 100644 --- a/src/module/actor/sheets/actor-sheet.ts +++ b/src/module/actor/sheets/actor-sheet.ts @@ -130,7 +130,7 @@ export class DS4ActorSheet extends ActorSheet this.render(false)); + } + /** * Handle clickable item rolls. * @param event - The originating click event diff --git a/src/module/handlebars/handlebars-partials.ts b/src/module/handlebars/handlebars-partials.ts index 3215a7e6..478c4a5a 100644 --- a/src/module/handlebars/handlebars-partials.ts +++ b/src/module/handlebars/handlebars-partials.ts @@ -15,6 +15,7 @@ export default async function registerHandlebarsPartials(): Promise { "systems/ds4/templates/sheets/actor/components/checks.hbs", "systems/ds4/templates/sheets/actor/components/combat-value.hbs", "systems/ds4/templates/sheets/actor/components/combat-values.hbs", + "systems/ds4/templates/sheets/actor/components/control-button-group.hbs", "systems/ds4/templates/sheets/actor/components/core-value.hbs", "systems/ds4/templates/sheets/actor/components/core-values.hbs", "systems/ds4/templates/sheets/actor/components/creature-properties.hbs", @@ -24,7 +25,6 @@ export default async function registerHandlebarsPartials(): Promise { "systems/ds4/templates/sheets/actor/components/item-list-entry.hbs", "systems/ds4/templates/sheets/actor/components/item-list-header.hbs", "systems/ds4/templates/sheets/actor/components/items-overview.hbs", - "systems/ds4/templates/sheets/actor/components/overview-control-buttons.hbs", "systems/ds4/templates/sheets/actor/components/profile.hbs", "systems/ds4/templates/sheets/actor/components/rollable-image.hbs", "systems/ds4/templates/sheets/actor/components/talent-rank-equation.hbs", diff --git a/src/scss/components/_control_button_group.scss b/src/scss/components/_control_button_group.scss new file mode 100644 index 00000000..e38c2e48 --- /dev/null +++ b/src/scss/components/_control_button_group.scss @@ -0,0 +1,17 @@ +/* + * SPDX-FileCopyrightText: 2021 Johannes Loher + * + * SPDX-License-Identifier: MIT + */ +@use "../utils/variables"; + +.ds4-control-button-group { + display: flex; + text-align: center; + width: 100%; + padding: 0 calc(1em / 3); + + &__button { + flex: 1; + } +} diff --git a/src/scss/components/_item_list.scss b/src/scss/components/_item_list.scss index 7c16a34f..0b7700a3 100644 --- a/src/scss/components/_item_list.scss +++ b/src/scss/components/_item_list.scss @@ -96,14 +96,6 @@ text-overflow: ellipsis; } } - - &__control-buttons { - display: grid; - grid-template-columns: 1fr 1fr; - text-align: center; - width: 100%; - padding: 0 calc(1em / 3); - } } .ds4-item-list-title { diff --git a/src/scss/ds4.scss b/src/scss/ds4.scss index c49150b5..8203eb62 100644 --- a/src/scss/ds4.scss +++ b/src/scss/ds4.scss @@ -29,6 +29,7 @@ @include meta.load-css("components/checks"); @include meta.load-css("components/combat_value"); @include meta.load-css("components/combat_values"); + @include meta.load-css("components/control_button_group"); @include meta.load-css("components/core_value"); @include meta.load-css("components/core_values"); @include meta.load-css("components/currency"); diff --git a/src/templates/sheets/actor/components/add-button.hbs b/src/templates/sheets/actor/components/add-button.hbs index 916a0eee..61dd303f 100644 --- a/src/templates/sheets/actor/components/add-button.hbs +++ b/src/templates/sheets/actor/components/add-button.hbs @@ -7,12 +7,13 @@ SPDX-License-Identifier: MIT {{! !-- Render an "add" button. -!-- @param class: The css class to use for the link element +!-- @param documentType: The type of document this button controls, item or effect !-- @param title: The title to use for the link element (will be localized) !-- @param type: An optional property to use as data-type attribute }}
    - + {{localize "DS4.UserInteractionAdd"}} diff --git a/src/templates/sheets/actor/components/control-button-group.hbs b/src/templates/sheets/actor/components/control-button-group.hbs new file mode 100644 index 00000000..263a028e --- /dev/null +++ b/src/templates/sheets/actor/components/control-button-group.hbs @@ -0,0 +1,20 @@ +{{!-- +SPDX-FileCopyrightText: 2021 Johannes Loher +SPDX-FileCopyrightText: 2021 Gesina Schwalbe + +SPDX-License-Identifier: MIT +--}} + +{{!-- +!-- Render a group of an "edit" and a "delete" button. +!-- The current item is defined by the data-item-id HTML property of the parent li element. +!-- @param documentType: The type of document that is controlled by this button group, item or effect +!-- @param editTitle: The title to use for the edit link element (will be localized) +!-- @param deleteTitle: The title to use for the delete link element (will be localized) +--}} +
    + + +
    diff --git a/src/templates/sheets/actor/components/effect-list-entry.hbs b/src/templates/sheets/actor/components/effect-list-entry.hbs index 99419a5b..e43b832a 100644 --- a/src/templates/sheets/actor/components/effect-list-entry.hbs +++ b/src/templates/sheets/actor/components/effect-list-entry.hbs @@ -9,7 +9,7 @@ SPDX-License-Identifier: MIT !-- Render an effect list entry row. !-- @param effectData: The data of the item. --}} -
  • +
  • {{!-- enabled --}} {{effectData.sourceName}}
  • - {{!-- control buttons --}} - {{> systems/ds4/templates/sheets/actor/components/overview-control-buttons.hbs - class="ds4-effect-list__control-buttons" }} + {{!-- control button group --}} + {{> systems/ds4/templates/sheets/actor/components/control-button-group.hbs documentType="effect" + editTitle="DS4.UserInteractionEditEffectTitle" deleteTitle="DS4.UserInteractionDeleteEffectTitle"}} diff --git a/src/templates/sheets/actor/components/item-list-entry.hbs b/src/templates/sheets/actor/components/item-list-entry.hbs index 0992d45c..d4331243 100644 --- a/src/templates/sheets/actor/components/item-list-entry.hbs +++ b/src/templates/sheets/actor/components/item-list-entry.hbs @@ -49,7 +49,7 @@ SPDX-License-Identifier: MIT {{{itemData.data.description}}} {{/unless}} - {{!-- control buttons --}} - {{> systems/ds4/templates/sheets/actor/components/overview-control-buttons.hbs - class="ds4-item-list__control-buttons" }} + {{!-- control button group --}} + {{> systems/ds4/templates/sheets/actor/components/control-button-group.hbs documentType="item" + editTitle="DS4.UserInteractionEditItemTitle" deleteTitle="DS4.UserInteractionDeleteItemTitle"}} diff --git a/src/templates/sheets/actor/components/items-overview.hbs b/src/templates/sheets/actor/components/items-overview.hbs index ce44395a..cdabde8f 100644 --- a/src/templates/sheets/actor/components/items-overview.hbs +++ b/src/templates/sheets/actor/components/items-overview.hbs @@ -42,7 +42,7 @@ SPDX-License-Identifier: MIT {{/unless}} {{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle' -class='item-create' type='weapon'}} +documentType='item' type='weapon'}} {{!-- ARMOR --}}

    {{localize 'DS4.ItemTypeArmorPlural'}}

    @@ -81,7 +81,7 @@ class='item-create' type='weapon'}} {{/unless}} {{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle' -class='item-create' type='armor'}} +documentType='item' type='armor'}} {{!-- SHIELD --}}

    {{localize 'DS4.ItemTypeShieldPlural'}}

    @@ -103,7 +103,7 @@ class='item-create' type='armor'}} {{/unless}} {{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle' -class='item-create' type='shield'}} +documentType='item' type='shield'}} {{!-- EQUIPMENT --}}

    {{localize 'DS4.ItemTypeEquipmentPlural'}}

    @@ -124,7 +124,7 @@ class='item-create' type='shield'}} {{/unless}} {{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle' -class='item-create' type='equipment'}} +documentType='item' type='equipment'}} {{!-- LOOT --}}

    {{localize 'DS4.ItemTypeLootPlural'}}

    @@ -144,4 +144,4 @@ class='item-create' type='equipment'}} {{/unless}} {{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle' -class='item-create' type='loot'}} +documentType='item' type='loot'}} diff --git a/src/templates/sheets/actor/components/overview-control-buttons.hbs b/src/templates/sheets/actor/components/overview-control-buttons.hbs deleted file mode 100644 index 07c3b8d5..00000000 --- a/src/templates/sheets/actor/components/overview-control-buttons.hbs +++ /dev/null @@ -1,18 +0,0 @@ -{{!-- -SPDX-FileCopyrightText: 2021 Johannes Loher -SPDX-FileCopyrightText: 2021 Gesina Schwalbe - -SPDX-License-Identifier: MIT ---}} - -{{!-- -!-- Render a group of an "edit" and a "delete" button for the current item. -!-- The current item is defined by the data-item-id HTML property of the parent li element. -!-- @param class: Additional CSS class(es) for the controls ---}} -
    - - -
    diff --git a/src/templates/sheets/actor/tabs/abilities.hbs b/src/templates/sheets/actor/tabs/abilities.hbs index 5163fb94..699bc704 100644 --- a/src/templates/sheets/actor/tabs/abilities.hbs +++ b/src/templates/sheets/actor/tabs/abilities.hbs @@ -23,7 +23,7 @@ SPDX-License-Identifier: MIT {{/unless}} {{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle' - class='item-create' type='talent'}} + documentType='item' type='talent'}} {{!-- RACIAL ABILITY --}}

    {{localize 'DS4.ItemTypeRacialAbilityPlural'}}

    @@ -36,7 +36,7 @@ SPDX-License-Identifier: MIT {{/unless}} {{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle' - class='item-create' type='racialAbility'}} + documentType='item' type='racialAbility'}} {{!-- LANGUAGE --}}

    {{localize 'DS4.ItemTypeLanguagePlural'}}

    @@ -49,7 +49,7 @@ SPDX-License-Identifier: MIT {{/unless}} {{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle' - class='item-create' type='language'}} + documentType='item' type='language'}} {{!-- ALPHABET --}}

    {{localize 'DS4.ItemTypeAlphabetPlural'}}

    @@ -62,5 +62,5 @@ SPDX-License-Identifier: MIT {{/unless}} {{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle' - class='item-create' type='alphabet'}} + documentType='item' type='alphabet'}} diff --git a/src/templates/sheets/actor/tabs/effects.hbs b/src/templates/sheets/actor/tabs/effects.hbs index 8e3e4353..8b2320eb 100644 --- a/src/templates/sheets/actor/tabs/effects.hbs +++ b/src/templates/sheets/actor/tabs/effects.hbs @@ -15,5 +15,5 @@ SPDX-License-Identifier: MIT {{/unless}} {{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddEffectTitle' - class='effect-create'}} + documentType='effect'}} diff --git a/src/templates/sheets/actor/tabs/special-creature-abilities.hbs b/src/templates/sheets/actor/tabs/special-creature-abilities.hbs index 15d52d56..81c627f0 100644 --- a/src/templates/sheets/actor/tabs/special-creature-abilities.hbs +++ b/src/templates/sheets/actor/tabs/special-creature-abilities.hbs @@ -15,5 +15,5 @@ SPDX-License-Identifier: MIT {{/unless}} {{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle' - class='item-create' type='specialCreatureAbility'}} + documentType='item' type='specialCreatureAbility'}} diff --git a/src/templates/sheets/actor/tabs/spells.hbs b/src/templates/sheets/actor/tabs/spells.hbs index 5b5b44e4..d683f340 100644 --- a/src/templates/sheets/actor/tabs/spells.hbs +++ b/src/templates/sheets/actor/tabs/spells.hbs @@ -94,5 +94,5 @@ titleKey=titleKey}} {{/unless}} {{> systems/ds4/templates/sheets/actor/components/add-button.hbs title='DS4.UserInteractionAddItemTitle' - class='item-create' type='spell'}} + documentType='item' type='spell'}} From bb67788abcb14ca9fc1dae2eb8c84dede4edffa5 Mon Sep 17 00:00:00 2001 From: Johannes Loher Date: Thu, 22 Jul 2021 02:20:17 +0200 Subject: [PATCH 04/18] Localize names / labels of newly created embedded items / effects --- src/lang/de.json | 15 ++++++++++++++- src/lang/en.json | 15 ++++++++++++++- src/module/actor/sheets/actor-sheet.ts | 4 ++-- src/module/item/item-sheet.ts | 2 +- 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/lang/de.json b/src/lang/de.json index 5a6b293c..62b6bd36 100644 --- a/src/lang/de.json +++ b/src/lang/de.json @@ -258,6 +258,7 @@ "DS4.ErrorActorDoesNotHaveItem": "Der Aktor '{actor}' hat kein Item mit der ID '{id}'.", "DS4.ErrorUnexpectedError": "Es gab einen unerwarteten Fehler im Dungeonslayers 4 System. Für mehr Details schauen Sie bitte in die Konsole (F12).", "DS4.ErrorItemDoesNotHaveEffect": "Das Item '{item}' hat keinen Effekt mit der ID '{id}'.", + "DS4.ErrorActorDoesNotHaveEffect": "Der Aktor '{actor}' hat keinen Effekt mit der ID '{id}'.", "DS4.DialogRollOptionsCheckTargetNumberLabel": "Probenwert", "DS4.DialogRollOptionsGMModifierLabel": "SL-Modifikator", "DS4.DialogRollOptionsMaximumCoupResultLabel": "Immersieg bis", @@ -300,5 +301,17 @@ "DS4.ChecksWorkMechanism": "Mechanismus Öffnen", "DS4.ActorCheckFlavor": "{actor} würfelt eine {check} Probe.", "DS4.ActorGenericCheckFlavor": "{actor} würfelt eine Probe gegen {attribute} + {trait}.", - "DS4.CheckTooltip": "{check} Probe würfeln" + "DS4.CheckTooltip": "{check} Probe würfeln", + "DS4.NewWeaponName": "Neue Waffe", + "DS4.NewArmorName": "Neue Panzerung", + "DS4.NewShieldName": "Neuer Schild", + "DS4.NewSpellName": "Neuer Zauberspruch", + "DS4.NewEquipmentName": "Neue Ausrüstung", + "DS4.NewLootName": "Neue Beute", + "DS4.NewTalentName": "Neues Talent", + "DS4.NewRacialAbilityName": "Neue Volksfähigkeit", + "DS4.NewLanguageName": "Neue Sprache", + "DS4.NewAlphabetName": "Neue Schriftzeichen", + "DS4.NewSpecialCreatureAbilityName": "Neue Besondere Kreaturenfähigkeit", + "DS4.NewEffectLabel": "Neuer Effekt" } diff --git a/src/lang/en.json b/src/lang/en.json index 9ce4238a..c68a490b 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -258,6 +258,7 @@ "DS4.ErrorActorDoesNotHaveItem": "The actor '{actor}' does not have any item with the id '{id}'.", "DS4.ErrorUnexpectedError": "There was an unexpected error in the Dungeonslayers 4 system. For more details, please take a look at the console (F12).", "DS4.ErrorItemDoesNotHaveEffect": "The item '{item}' does not have any effect with the id '{id}'.", + "DS4.ErrorActorDoesNotHaveEffect": "The actor '{actor}' does not have any effect with the id '{id}'.", "DS4.DialogRollOptionsCheckTargetNumberLabel": "Check Target Number", "DS4.DialogRollOptionsGMModifierLabel": "Game Master Modifier", "DS4.DialogRollOptionsMaximumCoupResultLabel": "Coup to", @@ -300,5 +301,17 @@ "DS4.ChecksWorkMechanism": "Work Mechanism", "DS4.ActorCheckFlavor": "{actor} rolls a {check} check.", "DS4.ActorGenericCheckFlavor": "{actor} rolls a check against {attribute} + {trait}.", - "DS4.CheckTooltip": "Roll a {check} check" + "DS4.CheckTooltip": "Roll a {check} check", + "DS4.NewWeaponName": "New Weapon", + "DS4.NewArmorName": "New Armor", + "DS4.NewShieldName": "New Shield", + "DS4.NewSpellName": "New Spell", + "DS4.NewEquipmentName": "New Equipment", + "DS4.NewLootName": "New Loot", + "DS4.NewTalentName": "News Talent", + "DS4.NewRacialAbilityName": "New Racial Ability", + "DS4.NewLanguageName": "New Language", + "DS4.NewAlphabetName": "New Alphabet", + "DS4.NewSpecialCreatureAbilityName": "New Special Creature Ability", + "DS4.NewEffectLabel": "New Effect" } diff --git a/src/module/actor/sheets/actor-sheet.ts b/src/module/actor/sheets/actor-sheet.ts index d68d29e2..373f755f 100644 --- a/src/module/actor/sheets/actor-sheet.ts +++ b/src/module/actor/sheets/actor-sheet.ts @@ -147,7 +147,7 @@ export class DS4ActorSheet extends ActorSheet */ protected async createActiveEffect(): Promise { const createData = { - label: "New Effect", + label: getGame().i18n.localize(`DS4.NewEffectLabel`), icon: "icons/svg/aura.svg", origin: this.item.uuid, }; From 2ef58012c6174629ff67e6095086255b899ef5a2 Mon Sep 17 00:00:00 2001 From: Johannes Loher Date: Thu, 22 Jul 2021 02:50:16 +0200 Subject: [PATCH 05/18] Add possibility to enable / disable effects in the actor sheet --- src/module/actor/sheets/actor-sheet.ts | 22 +++++++++++++++++-- .../actor/components/effect-list-entry.hbs | 4 ++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/module/actor/sheets/actor-sheet.ts b/src/module/actor/sheets/actor-sheet.ts index 373f755f..fed07c40 100644 --- a/src/module/actor/sheets/actor-sheet.ts +++ b/src/module/actor/sheets/actor-sheet.ts @@ -131,6 +131,7 @@ export class DS4ActorSheet extends ActorSheet this.render(false)); } + protected onChangeEffect(event: JQuery.ChangeEvent): void { + event.preventDefault(); + const currentTarget = $(event.currentTarget); + const element: HTMLFormElement = currentTarget.get(0); + const id = currentTarget.parents(".effect").data("effectId"); + const property: string | undefined = currentTarget.data("property"); + const inverted = Boolean(currentTarget.data("inverted")); + + if (element.disabled || element.getAttribute("disabled")) return; + if (property === undefined) { + throw TypeError("HTML element does not provide 'data-property' attribute"); + } + const newValue = this.getValue(element, inverted); + this.actor.updateEmbeddedDocuments("ActiveEffect", [{ _id: id, [property]: newValue }]); + } + /** * Handle clickable item rolls. * @param event - The originating click event diff --git a/src/templates/sheets/actor/components/effect-list-entry.hbs b/src/templates/sheets/actor/components/effect-list-entry.hbs index e43b832a..4d7243eb 100644 --- a/src/templates/sheets/actor/components/effect-list-entry.hbs +++ b/src/templates/sheets/actor/components/effect-list-entry.hbs @@ -11,8 +11,8 @@ SPDX-License-Identifier: MIT --}}
  • {{!-- enabled --}} - {{!-- icon --}} From 1f629f3468b9f1421b55a67d5dae852040052927 Mon Sep 17 00:00:00 2001 From: Johannes Loher Date: Thu, 22 Jul 2021 04:06:29 +0200 Subject: [PATCH 06/18] Rename "Special Creature Abilities" tab to "Abilities" --- src/lang/de.json | 1 - src/lang/en.json | 1 - src/module/actor/sheets/actor-sheet.ts | 11 +---------- src/module/handlebars/handlebars-partials.ts | 4 ++-- src/templates/sheets/actor/character-sheet.hbs | 2 +- src/templates/sheets/actor/creature-sheet.hbs | 9 ++++----- .../tabs/{abilities.hbs => character-abilities.hbs} | 0 ...-creature-abilities.hbs => creature-abilities.hbs} | 2 +- 8 files changed, 9 insertions(+), 21 deletions(-) rename src/templates/sheets/actor/tabs/{abilities.hbs => character-abilities.hbs} (100%) rename src/templates/sheets/actor/tabs/{special-creature-abilities.hbs => creature-abilities.hbs} (87%) diff --git a/src/lang/de.json b/src/lang/de.json index 62b6bd36..e18c8ac8 100644 --- a/src/lang/de.json +++ b/src/lang/de.json @@ -19,7 +19,6 @@ "DS4.HeadingAbilities": "Fähigkeiten", "DS4.HeadingSpells": "Zaubersprüche", "DS4.HeadingDescription": "Beschreibung", - "DS4.HeadingSpecialCreatureAbilities": "Besondere Fähigkeiten", "DS4.AttackType": "Angriffsart", "DS4.AttackTypeAbbr": "AA", "DS4.DialogAttackTypeSelection": "Welche Angriffsart?", diff --git a/src/lang/en.json b/src/lang/en.json index c68a490b..97158336 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -19,7 +19,6 @@ "DS4.HeadingAbilities": "Abilities", "DS4.HeadingSpells": "Spells", "DS4.HeadingDescription": "Description", - "DS4.HeadingSpecialCreatureAbilities": "Special Abilities", "DS4.AttackType": "Attack Type", "DS4.AttackTypeAbbr": "AT", "DS4.DialogAttackTypeSelection": "Which Attack Type?", diff --git a/src/module/actor/sheets/actor-sheet.ts b/src/module/actor/sheets/actor-sheet.ts index fed07c40..4ec6878e 100644 --- a/src/module/actor/sheets/actor-sheet.ts +++ b/src/module/actor/sheets/actor-sheet.ts @@ -22,16 +22,7 @@ export class DS4ActorSheet extends ActorSheet { "systems/ds4/templates/sheets/actor/components/profile.hbs", "systems/ds4/templates/sheets/actor/components/rollable-image.hbs", "systems/ds4/templates/sheets/actor/components/talent-rank-equation.hbs", - "systems/ds4/templates/sheets/actor/tabs/abilities.hbs", "systems/ds4/templates/sheets/actor/tabs/biography.hbs", + "systems/ds4/templates/sheets/actor/tabs/character-abilities.hbs", "systems/ds4/templates/sheets/actor/tabs/character-inventory.hbs", + "systems/ds4/templates/sheets/actor/tabs/creature-abilities.hbs", "systems/ds4/templates/sheets/actor/tabs/creature-inventory.hbs", "systems/ds4/templates/sheets/actor/tabs/description.hbs", "systems/ds4/templates/sheets/actor/tabs/effects.hbs", - "systems/ds4/templates/sheets/actor/tabs/special-creature-abilities.hbs", "systems/ds4/templates/sheets/actor/tabs/spells.hbs", "systems/ds4/templates/sheets/actor/tabs/values.hbs", "systems/ds4/templates/sheets/item/components/body.hbs", diff --git a/src/templates/sheets/actor/character-sheet.hbs b/src/templates/sheets/actor/character-sheet.hbs index 8dcc5a2a..70455a92 100644 --- a/src/templates/sheets/actor/character-sheet.hbs +++ b/src/templates/sheets/actor/character-sheet.hbs @@ -36,7 +36,7 @@ SPDX-License-Identifier: MIT {{> systems/ds4/templates/sheets/actor/tabs/spells.hbs}} {{!-- Abilities Tab --}} -{{> systems/ds4/templates/sheets/actor/tabs/abilities.hbs}} +{{> systems/ds4/templates/sheets/actor/tabs/character-abilities.hbs}} {{!-- Effects Tab --}} {{> systems/ds4/templates/sheets/actor/tabs/effects.hbs}} diff --git a/src/templates/sheets/actor/creature-sheet.hbs b/src/templates/sheets/actor/creature-sheet.hbs index de12472b..ebd9f437 100644 --- a/src/templates/sheets/actor/creature-sheet.hbs +++ b/src/templates/sheets/actor/creature-sheet.hbs @@ -17,9 +17,8 @@ SPDX-License-Identifier: MIT @@ -32,12 +31,12 @@ SPDX-License-Identifier: MIT {{!-- Inventory Tab --}} {{> systems/ds4/templates/sheets/actor/tabs/creature-inventory.hbs}} - {{!-- Special Creature Abilities Tab --}} - {{> systems/ds4/templates/sheets/actor/tabs/special-creature-abilities.hbs}} - {{!-- Spells Tab --}} {{> systems/ds4/templates/sheets/actor/tabs/spells.hbs}} + {{!-- Abilities Tab --}} + {{> systems/ds4/templates/sheets/actor/tabs/creature-abilities.hbs}} + {{!-- Effects Tab --}} {{> systems/ds4/templates/sheets/actor/tabs/effects.hbs}} diff --git a/src/templates/sheets/actor/tabs/abilities.hbs b/src/templates/sheets/actor/tabs/character-abilities.hbs similarity index 100% rename from src/templates/sheets/actor/tabs/abilities.hbs rename to src/templates/sheets/actor/tabs/character-abilities.hbs diff --git a/src/templates/sheets/actor/tabs/special-creature-abilities.hbs b/src/templates/sheets/actor/tabs/creature-abilities.hbs similarity index 87% rename from src/templates/sheets/actor/tabs/special-creature-abilities.hbs rename to src/templates/sheets/actor/tabs/creature-abilities.hbs index 81c627f0..ef9c81bc 100644 --- a/src/templates/sheets/actor/tabs/special-creature-abilities.hbs +++ b/src/templates/sheets/actor/tabs/creature-abilities.hbs @@ -5,7 +5,7 @@ SPDX-FileCopyrightText: 2021 Gesina Schwalbe SPDX-License-Identifier: MIT --}} -
    +
    {{#unless (isEmpty itemsByType.specialCreatureAbility)}}
      {{> systems/ds4/templates/sheets/actor/components/item-list-header.hbs}} From 48620636dff8baca719ca336e3a5f008f47bc989 Mon Sep 17 00:00:00 2001 From: Johannes Loher Date: Fri, 23 Jul 2021 00:43:15 +0200 Subject: [PATCH 07/18] Clean up actor sheet --- src/module/actor/sheets/actor-sheet.ts | 298 +++++++++--------- src/module/settings.ts | 15 +- src/module/utils.ts | 10 + .../sheets/actor/components/add-button.hbs | 4 +- .../actor/components/control-button-group.hbs | 6 +- .../sheets/actor/components/currency.hbs | 2 +- .../actor/components/effect-list-entry.hbs | 2 +- .../actor/components/effect-list-header.hbs | 2 +- .../actor/components/item-list-entry.hbs | 8 +- .../actor/components/items-overview.hbs | 4 +- .../actor/components/talent-rank-equation.hbs | 2 +- src/templates/sheets/actor/tabs/spells.hbs | 2 +- 12 files changed, 189 insertions(+), 166 deletions(-) create mode 100644 src/module/utils.ts diff --git a/src/module/actor/sheets/actor-sheet.ts b/src/module/actor/sheets/actor-sheet.ts index 4ec6878e..9122a8d8 100644 --- a/src/module/actor/sheets/actor-sheet.ts +++ b/src/module/actor/sheets/actor-sheet.ts @@ -8,13 +8,13 @@ import { ModifiableDataBaseTotal } from "../../common/common-data"; import { DS4 } from "../../config"; import { getCanvas, getGame } from "../../helpers"; -import { DS4Item } from "../../item/item"; import { DS4Settings, getDS4Settings } from "../../settings"; import notifications from "../../ui/notifications"; +import { enforce } from "../../utils"; import { isCheck } from "../actor-data-properties"; /** - * The base Sheet class for all DS4 Actors + * The base sheet class for all {@link DS4Actor}s. */ export class DS4ActorSheet extends ActorSheet { /** @override */ @@ -38,12 +38,7 @@ export class DS4ActorSheet extends ActorSheet { const itemsByType = Object.fromEntries( Object.entries(this.actor.itemTypes).map(([itemType, items]) => { @@ -69,6 +64,9 @@ export class DS4ActorSheet extends ActorSheet): string { return `${value.base} (${getGame().i18n.localize("DS4.TooltipBaseValue")}) + ${ value.mod @@ -92,151 +93,92 @@ export class DS4ActorSheet extends ActorSheet { - const li = $(ev.currentTarget).parents(".item"); - const id = li.data("itemId"); - const item = this.actor.items.get(id); - if (!item) { - throw new Error(getGame().i18n.format("DS4.ErrorActorDoesNotHaveItem", { id, actor: this.actor.name })); - } - if (!item.sheet) { - throw new Error(getGame().i18n.localize("DS4.ErrorUnexpectedError")); - } - item.sheet.render(true); - }); - - // Delete Inventory Item - html.find(".item-delete").on("click", (ev) => { - const li = $(ev.currentTarget).parents(".item"); - this.actor.deleteEmbeddedDocuments("Item", [li.data("itemId")]); - li.slideUp(200, () => this.render(false)); - }); - - html.find(".item-change").on("change", this.onItemChange.bind(this)); + html.find(".control-item").on("click", this.onControlItem.bind(this)); + html.find(".change-item").on("change", this.onChangeItem.bind(this)); html.find(".control-effect").on("click", this.onControlEffect.bind(this)); html.find(".change-effect").on("change", this.onChangeEffect.bind(this)); html.find(".rollable-item").on("click", this.onRollItem.bind(this)); - html.find(".rollable-check").on("click", this.onRollCheck.bind(this)); } /** - * Handle creating a new embedded Item for the actor using initial data defined in the HTML dataset + * Handles a click on an element of this sheet to control an embedded item of the actor corresponding to this sheet. + * * @param event - The originating click event */ - protected onItemCreate(event: JQuery.ClickEvent): void { + protected onControlItem(event: JQuery.ClickEvent): void { event.preventDefault(); - const header = event.currentTarget; - - const { type, ...data } = foundry.utils.deepClone(header.dataset); + const a = event.currentTarget; + switch (a.dataset["action"]) { + case "create": + return this.onCreateItem(event); + case "edit": + return this.onEditItem(event); + case "delete": + return this.onDeleteItem(event); + } + } + /** + * Creates a new embedded item using the initial data defined in the HTML dataset of the clicked element. + * + * @param event - The originating click event + */ + protected onCreateItem(event: JQuery.ClickEvent): void { + const { type, ...data } = foundry.utils.deepClone(event.currentTarget.dataset); const name = getGame().i18n.localize(`DS4.New${type.capitalize()}Name`); - const itemData = { name: name, type: type, data: data, }; - - DS4Item.create(itemData, { parent: this.actor }); + Item.create(itemData, { parent: this.actor }); } /** - * Handle changes to properties of an Owned Item from within character sheet. - * Can currently properly bind: see getValue(). - * Assumes the item property is given as the value of the HTML element property 'data-property'. - * @param ev - The originating change event + * Opens the sheet of the embedded item corresponding to the clicked element. + * + * @param event - The originating click event */ - protected onItemChange(ev: JQuery.ChangeEvent): void { - ev.preventDefault(); - const el: HTMLFormElement = $(ev.currentTarget).get(0); - const id = $(ev.currentTarget).parents(".item").data("itemId"); + protected onEditItem(event: JQuery.ClickEvent): void { + const id = $(event.currentTarget).parents(".item").data("id"); const item = this.actor.items.get(id); - if (!item) { - throw new Error(getGame().i18n.format("DS4.ErrorActorDoesNotHaveItem", { id, actor: this.actor.name })); - } - const itemObject = item.toObject(); - const property: string | undefined = $(ev.currentTarget).data("property"); - - // Early return: - // Disabled => do nothing - if (el.disabled || el.getAttribute("disabled")) return; - // name not given => raise - if (property === undefined) { - throw TypeError("HTML element does not provide 'data-property' attribute"); - } - - // Set new value - const newValue = this.getValue(el); - foundry.utils.setProperty(itemObject, property, newValue); - item.update(itemObject); + enforce(item, getGame().i18n.format("DS4.ErrorActorDoesNotHaveItem", { id, actor: this.actor.name })); + enforce(item.sheet); + item.sheet.render(true); } /** - * Collect the value of a form element depending on the element's type - * The value is parsed to: - * - Checkbox: boolean - * - Text input: string - * - Number: number - * @param el - The input element to collect the value of - * @param inverted - Whether or not the value should be inverted + * Deletes the embedded item corresponding to the clicked element. + * + * @param event - The originating click event */ - private getValue(el: HTMLFormElement, inverted = false): boolean | string | number { - // One needs to differentiate between e.g. checkboxes (value="on") and select boxes etc. - // Checkbox: - if (el.type === "checkbox") { - const value: boolean = el.checked; - return inverted ? !value : value; - } - - // Text input: - else if (el.type === "text") { - const value: string = el.value; - return value; - } - - // Numbers: - else if (el.type === "number") { - const value = Number(el.value.trim()); - return value; - } - - // // Ranges: - // else if (el.type === "range") { - // const value: string = el.value.trim(); - // return value; - // } - - // // Radio Checkboxes (untested, cf. FormDataExtended.process) - // else if (el.type === "radio") { - // const chosen: HTMLFormElement = el.find((r: HTMLFormElement) => r["checked"]); - // const value: string = chosen ? chosen.value : null; - // return value; - // } - - // // Multi-Select (untested, cf. FormDataExtended.process) - // else if (el.type === "select-multiple") { - // const value: Array = []; - // el.options.array.forEach((opt: HTMLOptionElement) => { - // if (opt.selected) value.push(opt.value); - // }); - // return value; - - // unsupported: - else { - throw new TypeError("Binding of item property to this type of HTML element not supported; given: " + el); - } + protected onDeleteItem(event: JQuery.ClickEvent): void { + const li = $(event.currentTarget).parents(".item"); + this.actor.deleteEmbeddedDocuments("Item", [li.data("id")]); + li.slideUp(200, () => this.render(false)); } + /** + * Applies a change to a property of an embedded item depending on the `data-property` attribute of the + * {@link HTMLInputElement} that has been changed and its new value. + * + * @param event - The originating change event + */ + protected onChangeItem(event: JQuery.ChangeEvent): void { + return this.onChangeEmbeddedDocument(event, ".item", "Item"); + } + + /** + * Handles a click on an element of this sheet to control an embedded effect of the actor corresponding to this + * sheet. + * + * @param event - The originating click event + */ protected onControlEffect(event: JQuery.ClickEvent): void { event.preventDefault(); const a = event.currentTarget; @@ -250,45 +192,115 @@ export class DS4ActorSheet extends ActorSheet this.render(false)); } + /** + * Applies a change to a property of an embedded effect depending on the `data-property` attribute of the + * {@link HTMLInputElement} that has been changed and its new value. + * + * @param event - The originating change event + */ protected onChangeEffect(event: JQuery.ChangeEvent): void { - event.preventDefault(); - const currentTarget = $(event.currentTarget); - const element: HTMLFormElement = currentTarget.get(0); - const id = currentTarget.parents(".effect").data("effectId"); - const property: string | undefined = currentTarget.data("property"); - const inverted = Boolean(currentTarget.data("inverted")); + return this.onChangeEmbeddedDocument(event, ".effect", "ActiveEffect"); + } - if (element.disabled || element.getAttribute("disabled")) return; - if (property === undefined) { - throw TypeError("HTML element does not provide 'data-property' attribute"); + /** + * Applies a change to a property of an embedded document of the actor belonging to this sheet. The change depends + * on the `data-property` attribute of the {@link HTMLInputElement} that has been changed and its new value. + * + * @param event - The originating change event + * @param documentSelector - The selector for the closest parent of the changed {@link HTMLInputElement}, which + * contains the `data-id` attribute providing the `id` of the embedded document to be + * changed. + * @param documentName - The name of the embedded document to be changed. + */ + protected onChangeEmbeddedDocument( + event: JQuery.ChangeEvent, + documentSelector: string, + documentName: "Item" | "ActiveEffect", + ): void { + event.preventDefault(); + const element = $(event.currentTarget).get(0); + enforce(element instanceof HTMLInputElement); + if (element.disabled) return; + + const effectElement = element.closest(documentSelector); + enforce(effectElement instanceof HTMLElement); + const id = effectElement.dataset["id"]; + const property = element.dataset["property"]; + const inverted = Boolean(element.dataset["inverted"]); + enforce(property !== undefined, TypeError("HTML element does not provide 'data-property' attribute")); + + const newValue = this.parseValue(element, inverted); + this.actor.updateEmbeddedDocuments(documentName, [{ _id: id, [property]: newValue }]); + } + + /** + * Parses the value of the given {@link HTMLInputElement} depending on the element's type + * The value is parsed to: + * - checkbox: `boolean` + * - text input: `string` + * - number: `number` + * + * @param element - The input element to parse the value from + * @param inverted - Whether or not the value should be inverted + */ + protected parseValue(element: HTMLInputElement, inverted = false): boolean | string | number { + switch (element.type) { + case "checkbox": { + const value: boolean = element.checked; + return inverted ? !value : value; + } + case "text": { + const value: string = element.value; + return value; + } + case "number": { + const value = Number(element.value.trim()); + return value; + } + default: { + throw new TypeError( + "Binding of item property to this type of HTML element not supported; given: " + element, + ); + } } - const newValue = this.getValue(element, inverted); - this.actor.updateEmbeddedDocuments("ActiveEffect", [{ _id: id, [property]: newValue }]); } /** @@ -299,9 +311,7 @@ export class DS4ActorSheet extends ActorSheet notifications.error(e, { log: true })); } @@ -323,7 +333,7 @@ export class DS4ActorSheet extends ActorSheet { - const item = await DS4Item.fromDropData(data); + const item = await Item.fromDropData(data); if (item && !this.actor.canOwnItemType(item.data.type)) { notifications.warn( getGame().i18n.format("DS4.WarningActorCannotOwnItem", { diff --git a/src/module/settings.ts b/src/module/settings.ts index 96a86481..a2d1017e 100644 --- a/src/module/settings.ts +++ b/src/module/settings.ts @@ -5,10 +5,12 @@ import { getGame } from "./helpers"; export function registerSystemSettings(): void { + const game = getGame(); + /** * Track the migrations version of the latest migration that has been applied */ - getGame().settings.register("ds4", "systemMigrationVersion", { + game.settings.register("ds4", "systemMigrationVersion", { name: "System Migration Version", scope: "world", config: false, @@ -16,7 +18,7 @@ export function registerSystemSettings(): void { default: -1, }); - getGame().settings.register("ds4", "useSlayingDiceForAutomatedChecks", { + game.settings.register("ds4", "useSlayingDiceForAutomatedChecks", { name: "DS4.SettingUseSlayingDiceForAutomatedChecksName", hint: "DS4.SettingUseSlayingDiceForAutomatedChecksHint", scope: "world", @@ -25,7 +27,7 @@ export function registerSystemSettings(): void { default: false, }); - getGame().settings.register("ds4", "showSlayerPoints", { + game.settings.register("ds4", "showSlayerPoints", { name: "DS4.SettingShowSlayerPointsName", hint: "DS4.SettingShowSlayerPointsHint", scope: "world", @@ -42,9 +44,10 @@ export interface DS4Settings { } export function getDS4Settings(): DS4Settings { + const game = getGame(); return { - systemMigrationVersion: getGame().settings.get("ds4", "systemMigrationVersion"), - useSlayingDiceForAutomatedChecks: getGame().settings.get("ds4", "useSlayingDiceForAutomatedChecks"), - showSlayerPoints: getGame().settings.get("ds4", "showSlayerPoints"), + systemMigrationVersion: game.settings.get("ds4", "systemMigrationVersion"), + useSlayingDiceForAutomatedChecks: game.settings.get("ds4", "useSlayingDiceForAutomatedChecks"), + showSlayerPoints: game.settings.get("ds4", "showSlayerPoints"), }; } diff --git a/src/module/utils.ts b/src/module/utils.ts new file mode 100644 index 00000000..7c9c184e --- /dev/null +++ b/src/module/utils.ts @@ -0,0 +1,10 @@ +import { getGame } from "./helpers"; + +export function enforce(value: unknown, message?: string | Error): asserts value { + if (!value) { + if (!message) { + message = getGame().i18n.localize("DS4.ErrorUnexpectedError"); + } + throw message instanceof Error ? message : new Error(message); + } +} diff --git a/src/templates/sheets/actor/components/add-button.hbs b/src/templates/sheets/actor/components/add-button.hbs index 61dd303f..1fc86419 100644 --- a/src/templates/sheets/actor/components/add-button.hbs +++ b/src/templates/sheets/actor/components/add-button.hbs @@ -12,8 +12,8 @@ SPDX-License-Identifier: MIT !-- @param type: An optional property to use as data-type attribute }}
      - + {{localize "DS4.UserInteractionAdd"}} diff --git a/src/templates/sheets/actor/components/control-button-group.hbs b/src/templates/sheets/actor/components/control-button-group.hbs index 263a028e..89713898 100644 --- a/src/templates/sheets/actor/components/control-button-group.hbs +++ b/src/templates/sheets/actor/components/control-button-group.hbs @@ -7,14 +7,14 @@ SPDX-License-Identifier: MIT {{!-- !-- Render a group of an "edit" and a "delete" button. -!-- The current item is defined by the data-item-id HTML property of the parent li element. +!-- The current item is defined by the data-id attribute of the parent li element. !-- @param documentType: The type of document that is controlled by this button group, item or effect !-- @param editTitle: The title to use for the edit link element (will be localized) !-- @param deleteTitle: The title to use for the delete link element (will be localized) --}}
      - -
      diff --git a/src/templates/sheets/actor/components/currency.hbs b/src/templates/sheets/actor/components/currency.hbs index 99e70195..7635f91e 100644 --- a/src/templates/sheets/actor/components/currency.hbs +++ b/src/templates/sheets/actor/components/currency.hbs @@ -10,7 +10,7 @@ SPDX-License-Identifier: MIT
      {{#each data.data.currency as |value key|}} - {{/each}}
      diff --git a/src/templates/sheets/actor/components/effect-list-entry.hbs b/src/templates/sheets/actor/components/effect-list-entry.hbs index 4d7243eb..9106ddfe 100644 --- a/src/templates/sheets/actor/components/effect-list-entry.hbs +++ b/src/templates/sheets/actor/components/effect-list-entry.hbs @@ -9,7 +9,7 @@ SPDX-License-Identifier: MIT !-- Render an effect list entry row. !-- @param effectData: The data of the item. --}} -
    1. +
    2. {{!-- enabled --}} +
    3. {{!-- enabled --}}
      {{localize 'DS4.EffectEnabledAbbr'}}
      diff --git a/src/templates/sheets/actor/components/item-list-entry.hbs b/src/templates/sheets/actor/components/item-list-entry.hbs index d4331243..01adc41d 100644 --- a/src/templates/sheets/actor/components/item-list-entry.hbs +++ b/src/templates/sheets/actor/components/item-list-entry.hbs @@ -15,10 +15,10 @@ SPDX-License-Identifier: MIT !-- @param hideDescription: A flag to disable the description column. !-- @param @partial-block: Custom column headers can be passed using the partial block. --}} -
    4. +
    5. {{!-- equipped --}} {{#if isEquipable}} - {{/if}} @@ -30,12 +30,12 @@ SPDX-License-Identifier: MIT {{!-- amount --}} {{#if hasQuantity}} - {{/if}} {{!-- name --}} - {{!-- item type specifics --}} diff --git a/src/templates/sheets/actor/components/items-overview.hbs b/src/templates/sheets/actor/components/items-overview.hbs index cdabde8f..049a1792 100644 --- a/src/templates/sheets/actor/components/items-overview.hbs +++ b/src/templates/sheets/actor/components/items-overview.hbs @@ -117,7 +117,7 @@ documentType='item' type='shield'}} {{#> systems/ds4/templates/sheets/actor/components/item-list-entry.hbs itemData=itemData isEquipable=true hasQuantity=true}} {{!-- storage location --}} - {{/systems/ds4/templates/sheets/actor/components/item-list-entry.hbs}} {{/each}} @@ -137,7 +137,7 @@ documentType='item' type='equipment'}} {{#each itemsByType.loot as |itemData id|}} {{#> systems/ds4/templates/sheets/actor/components/item-list-entry.hbs itemData=itemData hasQuantity=true}} {{!-- storage location --}} - {{/systems/ds4/templates/sheets/actor/components/item-list-entry.hbs}} {{/each}} diff --git a/src/templates/sheets/actor/components/talent-rank-equation.hbs b/src/templates/sheets/actor/components/talent-rank-equation.hbs index ce91c8b9..3480b5f1 100644 --- a/src/templates/sheets/actor/components/talent-rank-equation.hbs +++ b/src/templates/sheets/actor/components/talent-rank-equation.hbs @@ -18,7 +18,7 @@ disable the input element !-- @param localizeString: The string to use as key for the localized tooltip --}} {{#*inline "talentRankValue"}} - {{/inline}} diff --git a/src/templates/sheets/actor/tabs/spells.hbs b/src/templates/sheets/actor/tabs/spells.hbs index d683f340..c3b5314f 100644 --- a/src/templates/sheets/actor/tabs/spells.hbs +++ b/src/templates/sheets/actor/tabs/spells.hbs @@ -76,7 +76,7 @@ titleKey=titleKey}} title="{{lookup ../../config.i18n.spellTypes itemData.data.spellType}}" /> {{!-- spell bonus --}} - {{!-- max. distance --}} From 8d47c3d87b61c29c5f14b876146354be321972dc Mon Sep 17 00:00:00 2001 From: Johannes Loher Date: Fri, 23 Jul 2021 00:47:49 +0200 Subject: [PATCH 08/18] remove unused property systemVersion from system.json --- src/system.json | 1 - 1 file changed, 1 deletion(-) diff --git a/src/system.json b/src/system.json index 00b2f6ad..f59e1215 100644 --- a/src/system.json +++ b/src/system.json @@ -5,7 +5,6 @@ "version": "1.1.3", "minimumCoreVersion": "0.8.8", "compatibleCoreVersion": "0.8.8", - "templateVersion": 6, "author": "Johannes Loher, Gesina Schwalbe, Oliver Rümpelein, Siegfried Krug, Max Tharr, Sascha Martens", "authors": [ { From bac53c4828fd543fe8c0a95b62a034fa5d00096a Mon Sep 17 00:00:00 2001 From: Johannes Loher Date: Fri, 23 Jul 2021 01:11:42 +0200 Subject: [PATCH 09/18] Use same styling class for effect-list and item-list Also center some columns in those lists --- src/scss/components/_effect_list.scss | 68 ------------------- ...list.scss => _embedded_document_list.scss} | 38 ++++++++++- src/scss/ds4.scss | 3 +- .../actor/components/effect-list-entry.hbs | 4 +- .../actor/components/effect-list-header.hbs | 2 +- .../actor/components/item-list-entry.hbs | 10 +-- .../actor/components/item-list-header.hbs | 2 +- .../actor/components/items-overview.hbs | 28 ++++---- .../sheets/actor/tabs/character-abilities.hbs | 16 ++--- .../sheets/actor/tabs/creature-abilities.hbs | 2 +- src/templates/sheets/actor/tabs/effects.hbs | 2 +- src/templates/sheets/actor/tabs/spells.hbs | 6 +- 12 files changed, 73 insertions(+), 108 deletions(-) delete mode 100644 src/scss/components/_effect_list.scss rename src/scss/components/{_item_list.scss => _embedded_document_list.scss} (72%) diff --git a/src/scss/components/_effect_list.scss b/src/scss/components/_effect_list.scss deleted file mode 100644 index 06e18d36..00000000 --- a/src/scss/components/_effect_list.scss +++ /dev/null @@ -1,68 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2021 Johannes Loher - * SPDX-FileCopyrightText: 2021 Gesina Schwalbe - * - * SPDX-License-Identifier: MIT - */ - -@use "../utils/mixins"; -@use "../utils/variables"; - -.ds4-effect-list { - @include mixins.mark-invalid-or-disabled-input; - - $row-height: 1.75em; - - align-items: center; - display: grid; - grid-column-gap: 0.5em; - grid-row-gap: 0.2em; - grid-template-columns: $row-height $row-height 3fr 2fr 5ch; - margin: 0.5em 0; - overflow-y: auto; - padding: 0; - - :nth-child(5n + 1) { - justify-self: center; - } - - &__row { - display: contents; // TODO: Once chromium supports `grid-template-columns: subgrid` (https://bugs.chromium.org/p/chromium/issues/detail?id=618969), switch to `display: grid; grid: 1/-1; grid-template-columns: subgrid` - - &--header { - font-weight: bold; - } - - > * { - height: $row-height; - line-height: $row-height; - white-space: nowrap; - overflow: hidden; - text-overflow: ellipsis; - } - } - - &__image { - border: none; - } - - &__editable { - background-color: transparent; - border: 0; - padding: 0; - - &--checkbox { - width: 100%; - height: 100%; - margin: 0px; - } - } - - &__control-buttons { - display: grid; - grid-template-columns: 1fr 1fr; - text-align: center; - width: 100%; - padding: 0 calc(1em / 3); - } -} diff --git a/src/scss/components/_item_list.scss b/src/scss/components/_embedded_document_list.scss similarity index 72% rename from src/scss/components/_item_list.scss rename to src/scss/components/_embedded_document_list.scss index 0b7700a3..e459e8d4 100644 --- a/src/scss/components/_item_list.scss +++ b/src/scss/components/_embedded_document_list.scss @@ -8,7 +8,7 @@ @use "../utils/mixins"; @use "../utils/variables"; -.ds4-item-list { +.ds4-embedded-document-list { @include mixins.mark-invalid-or-disabled-input; $row-height: 1.75em; @@ -23,24 +23,51 @@ &--weapon { grid-template-columns: $row-height $row-height 3ch 3fr $row-height 1fr 3ch 5fr 5ch; + :nth-child(9n + 1), + :nth-child(9n + 5), + :nth-child(9n + 6), + :nth-child(9n + 7) { + justify-self: center; + } } &--armor { grid-template-columns: $row-height $row-height 3ch 3fr 1fr 1fr 3ch 5fr 5ch; + :nth-child(9n + 1), + :nth-child(9n + 7) { + justify-self: center; + } } &--shield { grid-template-columns: $row-height $row-height 3ch 1fr 3ch 3fr 5ch; + :nth-child(7n + 1), + :nth-child(7n + 5) { + justify-self: center; + } } &--equipment { grid-template-columns: $row-height $row-height 3ch 1fr 10ch 3fr 5ch; + :nth-child(7n + 1) { + justify-self: center; + } } &--loot { grid-template-columns: $row-height 3ch 1fr 10ch 3fr 5ch; } &--spell { grid-template-columns: $row-height $row-height 2fr $row-height 1fr 1fr 1fr 1fr 5ch; + :nth-child(9n + 1), + :nth-child(9n + 4), + :nth-child(9n + 6), + :nth-child(9n + 7), + :nth-child(9n + 8) { + justify-self: center; + } } &--talent { grid-template-columns: $row-height 1fr 21ch 3fr 5ch; + :nth-child(9n + 3) { + justify-self: center; + } } &--racial-ability, &--language, @@ -49,6 +76,13 @@ grid-template-columns: $row-height 1fr 3fr 5ch; } + &--effect { + grid-template-columns: $row-height $row-height 3fr 2fr 5ch; + :nth-child(5n + 1) { + justify-self: center; + } + } + &__row { display: contents; // TODO: Once chromium supports `grid-template-columns: subgrid` (https://bugs.chromium.org/p/chromium/issues/detail?id=618969), switch to `display: grid; grid: 1/-1; grid-template-columns: subgrid` @@ -98,7 +132,7 @@ } } -.ds4-item-list-title { +.ds4-embedded-document-list-title { border-bottom: variables.$border-groove; font-weight: bold; margin-bottom: 0; diff --git a/src/scss/ds4.scss b/src/scss/ds4.scss index 8203eb62..79fb8a1d 100644 --- a/src/scss/ds4.scss +++ b/src/scss/ds4.scss @@ -34,9 +34,8 @@ @include meta.load-css("components/core_values"); @include meta.load-css("components/currency"); @include meta.load-css("components/description"); - @include meta.load-css("components/effect_list"); + @include meta.load-css("components/embedded_document_list"); @include meta.load-css("components/forms"); - @include meta.load-css("components/item_list"); @include meta.load-css("components/profile"); @include meta.load-css("components/rollable_image"); @include meta.load-css("components/sheet_tab_nav"); diff --git a/src/templates/sheets/actor/components/effect-list-entry.hbs b/src/templates/sheets/actor/components/effect-list-entry.hbs index 9106ddfe..4fbb0a95 100644 --- a/src/templates/sheets/actor/components/effect-list-entry.hbs +++ b/src/templates/sheets/actor/components/effect-list-entry.hbs @@ -9,9 +9,9 @@ SPDX-License-Identifier: MIT !-- Render an effect list entry row. !-- @param effectData: The data of the item. --}} -
    6. +
    7. {{!-- enabled --}} - diff --git a/src/templates/sheets/actor/components/effect-list-header.hbs b/src/templates/sheets/actor/components/effect-list-header.hbs index fdac8824..91311fe5 100644 --- a/src/templates/sheets/actor/components/effect-list-header.hbs +++ b/src/templates/sheets/actor/components/effect-list-header.hbs @@ -8,7 +8,7 @@ SPDX-License-Identifier: MIT {{!-- !-- Render an effect list header row. --}} -
    8. +
    9. {{!-- enabled --}}
      {{localize 'DS4.EffectEnabledAbbr'}}
      diff --git a/src/templates/sheets/actor/components/item-list-entry.hbs b/src/templates/sheets/actor/components/item-list-entry.hbs index 01adc41d..29a6d00a 100644 --- a/src/templates/sheets/actor/components/item-list-entry.hbs +++ b/src/templates/sheets/actor/components/item-list-entry.hbs @@ -15,10 +15,10 @@ SPDX-License-Identifier: MIT !-- @param hideDescription: A flag to disable the description column. !-- @param @partial-block: Custom column headers can be passed using the partial block. --}} -
    10. +
    11. {{!-- equipped --}} {{#if isEquipable}} - {{/if}} @@ -30,12 +30,12 @@ SPDX-License-Identifier: MIT {{!-- amount --}} {{#if hasQuantity}} - {{/if}} {{!-- name --}} - {{!-- item type specifics --}} @@ -45,7 +45,7 @@ SPDX-License-Identifier: MIT {{!-- description --}} {{#unless hideDescription}} -
      +
      {{{itemData.data.description}}}
      {{/unless}} diff --git a/src/templates/sheets/actor/components/item-list-header.hbs b/src/templates/sheets/actor/components/item-list-header.hbs index c2ebdb99..54229ade 100644 --- a/src/templates/sheets/actor/components/item-list-header.hbs +++ b/src/templates/sheets/actor/components/item-list-header.hbs @@ -14,7 +14,7 @@ SPDX-License-Identifier: MIT !-- @param hideDescription: A flag to disable the description column. !-- @param @partial-block: Custom column headers can be passed using the partial block. --}} -
    12. +
    13. {{!-- equipped --}} {{#if isEquipable}}
      {{localize 'DS4.ItemEquippedAbbr'}}
      diff --git a/src/templates/sheets/actor/components/items-overview.hbs b/src/templates/sheets/actor/components/items-overview.hbs index 049a1792..c9e25bf5 100644 --- a/src/templates/sheets/actor/components/items-overview.hbs +++ b/src/templates/sheets/actor/components/items-overview.hbs @@ -7,12 +7,12 @@ SPDX-License-Identifier: MIT --}} {{!-- WEAPONS --}} -

      {{localize 'DS4.ItemTypeWeaponPlural'}}

      +

      {{localize 'DS4.ItemTypeWeaponPlural'}}

      {{#unless (isEmpty itemsByType.weapon)}} -
        +
          {{#> systems/ds4/templates/sheets/actor/components/item-list-header.hbs isEquipable=true hasQuantity=true}} {{!-- attack type --}} -
          {{localize 'DS4.AttackTypeAbbr'}}
          +
          {{localize 'DS4.AttackTypeAbbr'}}
          {{!-- weapon bonus --}}
          @@ -29,7 +29,7 @@ SPDX-License-Identifier: MIT {{#> systems/ds4/templates/sheets/actor/components/item-list-entry.hbs itemData=itemData isEquipable=true hasQuantity=true}} {{!-- attack type --}} - {{!-- weapon bonus --}} @@ -45,9 +45,9 @@ SPDX-License-Identifier: MIT documentType='item' type='weapon'}} {{!-- ARMOR --}} -

          {{localize 'DS4.ItemTypeArmorPlural'}}

          +

          {{localize 'DS4.ItemTypeArmorPlural'}}

          {{#unless (isEmpty itemsByType.armor)}} -
            +
              {{#> systems/ds4/templates/sheets/actor/components/item-list-header.hbs isEquipable=true hasQuantity=true}} {{!-- armor material type --}}
              {{localize 'DS4.ArmorMaterialTypeAbbr'}}
              @@ -84,9 +84,9 @@ documentType='item' type='weapon'}} documentType='item' type='armor'}} {{!-- SHIELD --}} -

              {{localize 'DS4.ItemTypeShieldPlural'}}

              +

              {{localize 'DS4.ItemTypeShieldPlural'}}

              {{#unless (isEmpty itemsByType.shield)}} -
                +
                  {{#> systems/ds4/templates/sheets/actor/components/item-list-header.hbs isEquipable=true hasQuantity=true}} {{!-- armor value --}}
                  @@ -106,9 +106,9 @@ documentType='item' type='armor'}} documentType='item' type='shield'}} {{!-- EQUIPMENT --}} -

                  {{localize 'DS4.ItemTypeEquipmentPlural'}}

                  +

                  {{localize 'DS4.ItemTypeEquipmentPlural'}}

                  {{#unless (isEmpty itemsByType.equipment)}} -
                    +
                      {{#> systems/ds4/templates/sheets/actor/components/item-list-header.hbs isEquipable=true hasQuantity=true}} {{!-- storage location --}}
                      {{localize 'DS4.StorageLocation'}}
                      @@ -117,7 +117,7 @@ documentType='item' type='shield'}} {{#> systems/ds4/templates/sheets/actor/components/item-list-entry.hbs itemData=itemData isEquipable=true hasQuantity=true}} {{!-- storage location --}} - {{/systems/ds4/templates/sheets/actor/components/item-list-entry.hbs}} {{/each}} @@ -127,9 +127,9 @@ documentType='item' type='shield'}} documentType='item' type='equipment'}} {{!-- LOOT --}} -

                      {{localize 'DS4.ItemTypeLootPlural'}}

                      +

                      {{localize 'DS4.ItemTypeLootPlural'}}

                      {{#unless (isEmpty itemsByType.loot)}} -
                        +
                          {{#> systems/ds4/templates/sheets/actor/components/item-list-header.hbs hasQuantity=true}} {{!-- storage location --}}
                          {{localize 'DS4.StorageLocation'}}
                          @@ -137,7 +137,7 @@ documentType='item' type='equipment'}} {{#each itemsByType.loot as |itemData id|}} {{#> systems/ds4/templates/sheets/actor/components/item-list-entry.hbs itemData=itemData hasQuantity=true}} {{!-- storage location --}} - {{/systems/ds4/templates/sheets/actor/components/item-list-entry.hbs}} {{/each}} diff --git a/src/templates/sheets/actor/tabs/character-abilities.hbs b/src/templates/sheets/actor/tabs/character-abilities.hbs index 699bc704..0fdb1dc2 100644 --- a/src/templates/sheets/actor/tabs/character-abilities.hbs +++ b/src/templates/sheets/actor/tabs/character-abilities.hbs @@ -7,9 +7,9 @@ SPDX-License-Identifier: MIT
                          {{!-- TALENT --}} -

                          {{localize 'DS4.ItemTypeTalentPlural'}}

                          +

                          {{localize 'DS4.ItemTypeTalentPlural'}}

                          {{#unless (isEmpty itemsByType.talent)}} -
                            +
                              {{#> systems/ds4/templates/sheets/actor/components/item-list-header.hbs}} {{!-- rank --}}
                              {{localize 'DS4.TalentRank'}}
                              @@ -26,9 +26,9 @@ SPDX-License-Identifier: MIT documentType='item' type='talent'}} {{!-- RACIAL ABILITY --}} -

                              {{localize 'DS4.ItemTypeRacialAbilityPlural'}}

                              +

                              {{localize 'DS4.ItemTypeRacialAbilityPlural'}}

                              {{#unless (isEmpty itemsByType.racialAbility)}} -
                                +
                                  {{> systems/ds4/templates/sheets/actor/components/item-list-header.hbs}} {{#each itemsByType.racialAbility as |itemData id|}} {{> systems/ds4/templates/sheets/actor/components/item-list-entry.hbs itemData=itemData}} @@ -39,9 +39,9 @@ SPDX-License-Identifier: MIT documentType='item' type='racialAbility'}} {{!-- LANGUAGE --}} -

                                  {{localize 'DS4.ItemTypeLanguagePlural'}}

                                  +

                                  {{localize 'DS4.ItemTypeLanguagePlural'}}

                                  {{#unless (isEmpty itemsByType.language)}} -
                                    +
                                      {{> systems/ds4/templates/sheets/actor/components/item-list-header.hbs}} {{#each itemsByType.language as |itemData id|}} {{> systems/ds4/templates/sheets/actor/components/item-list-entry.hbs itemData=itemData}} @@ -52,9 +52,9 @@ SPDX-License-Identifier: MIT documentType='item' type='language'}} {{!-- ALPHABET --}} -

                                      {{localize 'DS4.ItemTypeAlphabetPlural'}}

                                      +

                                      {{localize 'DS4.ItemTypeAlphabetPlural'}}

                                      {{#unless (isEmpty itemsByType.alphabet)}} -
                                        +
                                          {{> systems/ds4/templates/sheets/actor/components/item-list-header.hbs}} {{#each itemsByType.alphabet as |itemData id|}} {{> systems/ds4/templates/sheets/actor/components/item-list-entry.hbs itemData=itemData}} diff --git a/src/templates/sheets/actor/tabs/creature-abilities.hbs b/src/templates/sheets/actor/tabs/creature-abilities.hbs index ef9c81bc..ab62882d 100644 --- a/src/templates/sheets/actor/tabs/creature-abilities.hbs +++ b/src/templates/sheets/actor/tabs/creature-abilities.hbs @@ -7,7 +7,7 @@ SPDX-License-Identifier: MIT
                                          {{#unless (isEmpty itemsByType.specialCreatureAbility)}} -
                                            +
                                              {{> systems/ds4/templates/sheets/actor/components/item-list-header.hbs}} {{#each itemsByType.specialCreatureAbility as |itemData id|}} {{> systems/ds4/templates/sheets/actor/components/item-list-entry.hbs itemData=itemData}} diff --git a/src/templates/sheets/actor/tabs/effects.hbs b/src/templates/sheets/actor/tabs/effects.hbs index 8b2320eb..67ed0a36 100644 --- a/src/templates/sheets/actor/tabs/effects.hbs +++ b/src/templates/sheets/actor/tabs/effects.hbs @@ -7,7 +7,7 @@ SPDX-License-Identifier: MIT
                                              {{#unless (isEmpty data.effects)}} -
                                                +
                                                  {{> systems/ds4/templates/sheets/actor/components/effect-list-header.hbs}} {{#each enrichedEffects as |effectData id| }} {{> systems/ds4/templates/sheets/actor/components/effect-list-entry.hbs effectData=effectData}} diff --git a/src/templates/sheets/actor/tabs/spells.hbs b/src/templates/sheets/actor/tabs/spells.hbs index c3b5314f..64e6eac9 100644 --- a/src/templates/sheets/actor/tabs/spells.hbs +++ b/src/templates/sheets/actor/tabs/spells.hbs @@ -51,7 +51,7 @@ titleKey=titleKey}}
                                                  {{#unless (isEmpty itemsByType.spell)}} -
                                                    +
                                                      {{#> systems/ds4/templates/sheets/actor/components/item-list-header.hbs isEquipable=true hideDescription=true}} {{!-- spell type --}}
                                                      {{localize 'DS4.SpellTypeAbbr'}}
                                                      @@ -72,11 +72,11 @@ titleKey=titleKey}} {{#> systems/ds4/templates/sheets/actor/components/item-list-entry.hbs itemData=itemData isEquipable=true hideDescription=true}} {{!-- spell type --}} - {{!-- spell bonus --}} - {{!-- max. distance --}} From f92bbff902fb06f7093b1ab5059ee46434f3169d Mon Sep 17 00:00:00 2001 From: Johannes Loher Date: Fri, 23 Jul 2021 01:13:45 +0200 Subject: [PATCH 10/18] Fix a localization typo --- src/lang/en.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lang/en.json b/src/lang/en.json index 97158336..694c45f4 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -307,7 +307,7 @@ "DS4.NewSpellName": "New Spell", "DS4.NewEquipmentName": "New Equipment", "DS4.NewLootName": "New Loot", - "DS4.NewTalentName": "News Talent", + "DS4.NewTalentName": "New Talent", "DS4.NewRacialAbilityName": "New Racial Ability", "DS4.NewLanguageName": "New Language", "DS4.NewAlphabetName": "New Alphabet", From 14f87163ff582b5a96ab2c59aadf5be73e3ad3ec Mon Sep 17 00:00:00 2001 From: Johannes Loher Date: Fri, 23 Jul 2021 12:29:01 +0200 Subject: [PATCH 11/18] Keep the source name od effects up to date in the actor sheet. --- src/module/active-effect.ts | 27 +++++++++++++++++++++++--- src/module/actor/sheets/actor-sheet.ts | 2 +- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/module/active-effect.ts b/src/module/active-effect.ts index 6ae292d6..d4ace9c4 100644 --- a/src/module/active-effect.ts +++ b/src/module/active-effect.ts @@ -3,6 +3,7 @@ // SPDX-License-Identifier: MIT import { DS4Actor } from "./actor/actor"; +import { getGame } from "./helpers"; declare global { interface DocumentClassConfig { @@ -10,7 +11,13 @@ declare global { } } +type PromisedType = T extends Promise ? U : T; export class DS4ActiveEffect extends ActiveEffect { + /** + * A cached reference to the source document to avoid recurring database lookups + */ + protected source: PromisedType> | undefined = undefined; + /** @override */ apply(actor: DS4Actor, change: foundry.data.ActiveEffectData["changes"][number]): unknown { change.value = Roll.replaceFormulaData(change.value, actor.data); @@ -23,9 +30,23 @@ export class DS4ActiveEffect extends ActiveEffect { } /** - * A public wrapper for {@link ActiveEffect#_getSourceName}. + * Gets the current source name based on the cached source object. */ - async getSourceName(): Promise { - return this._getSourceName(); + async getCurrentSourceName(): Promise { + const game = getGame(); + const origin = await this.getSource(); + if (origin === null) return game.i18n.localize("None"); + return origin.name ?? game.i18n.localize("Unknown"); + } + + /** + * Gets the source document for this effect. Uses the cached {@link DS4ActiveEffect#origin} if it has already been + * set. + */ + protected async getSource(): ReturnType { + if (this.source === undefined) { + this.source = this.data.origin !== undefined ? await fromUuid(this.data.origin) : null; + } + return this.source; } } diff --git a/src/module/actor/sheets/actor-sheet.ts b/src/module/actor/sheets/actor-sheet.ts index 9122a8d8..c11ec973 100644 --- a/src/module/actor/sheets/actor-sheet.ts +++ b/src/module/actor/sheets/actor-sheet.ts @@ -49,7 +49,7 @@ export class DS4ActorSheet extends ActorSheet { return { ...effect.toObject(), - sourceName: await effect.getSourceName(), + sourceName: await effect.getCurrentSourceName(), }; }); const enrichedEffects = await Promise.all(enrichedEffectPromises); From 20226e30b10a249de0df02402cc81e08b75fd7f2 Mon Sep 17 00:00:00 2001 From: Johannes Loher Date: Fri, 23 Jul 2021 12:33:52 +0200 Subject: [PATCH 12/18] Add missing licensing information --- src/module/utils.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/module/utils.ts b/src/module/utils.ts index 7c9c184e..5081ba25 100644 --- a/src/module/utils.ts +++ b/src/module/utils.ts @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2021 Johannes Loher +// +// SPDX-License-Identifier: MIT + import { getGame } from "./helpers"; export function enforce(value: unknown, message?: string | Error): asserts value { From 2b3dd9b859b961861b66e9ee21a4ca111ab404c4 Mon Sep 17 00:00:00 2001 From: Johannes Loher Date: Fri, 23 Jul 2021 12:39:01 +0200 Subject: [PATCH 13/18] Improve `enforce` to also work before initialization of `game` --- src/module/helpers.ts | 4 ++++ src/module/utils.ts | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/module/helpers.ts b/src/module/helpers.ts index edfc28d3..e96322e4 100644 --- a/src/module/helpers.ts +++ b/src/module/helpers.ts @@ -15,3 +15,7 @@ export function getGame(): Game { } return game; } + +export function getGameSafe(): Game | undefined { + return game instanceof Game ? game : undefined; +} diff --git a/src/module/utils.ts b/src/module/utils.ts index 5081ba25..668a9bff 100644 --- a/src/module/utils.ts +++ b/src/module/utils.ts @@ -2,12 +2,14 @@ // // SPDX-License-Identifier: MIT -import { getGame } from "./helpers"; +import { getGameSafe } from "./helpers"; export function enforce(value: unknown, message?: string | Error): asserts value { if (!value) { if (!message) { - message = getGame().i18n.localize("DS4.ErrorUnexpectedError"); + message = + getGameSafe()?.i18n.localize("DS4.ErrorUnexpectedError") ?? + "There was an unexpected error in the Dungeonslayers 4 system. For more details, please take a look at the console (F12)."; } throw message instanceof Error ? message : new Error(message); } From 22923855f96fcb301f041d1cef2ce5578cb1449b Mon Sep 17 00:00:00 2001 From: Johannes Loher Date: Fri, 23 Jul 2021 12:48:11 +0200 Subject: [PATCH 14/18] Ad documentation for `enforce` --- src/module/utils.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/module/utils.ts b/src/module/utils.ts index 668a9bff..a3038fe1 100644 --- a/src/module/utils.ts +++ b/src/module/utils.ts @@ -4,6 +4,14 @@ import { getGameSafe } from "./helpers"; +/** + * Tests if the given `value` is truthy. + * + * If it is not truthy, an {@link Error} is thrown, which depends on the given `message` parameter: + * - If `message` is a string`, it is used to construct a new {@link Error} which then is thrown. + * - If `message` is an instance of {@link Error}, it is thrown. + * - If `message` is `undefined`, an {@link Error} with a default message is thrown. + */ export function enforce(value: unknown, message?: string | Error): asserts value { if (!value) { if (!message) { From cada51877d1bd63ecab140e008355ddf0d868a08 Mon Sep 17 00:00:00 2001 From: Johannes Loher Date: Fri, 23 Jul 2021 12:50:13 +0200 Subject: [PATCH 15/18] Remove unused @use --- src/scss/components/_control_button_group.scss | 1 - 1 file changed, 1 deletion(-) diff --git a/src/scss/components/_control_button_group.scss b/src/scss/components/_control_button_group.scss index e38c2e48..6fa87150 100644 --- a/src/scss/components/_control_button_group.scss +++ b/src/scss/components/_control_button_group.scss @@ -3,7 +3,6 @@ * * SPDX-License-Identifier: MIT */ -@use "../utils/variables"; .ds4-control-button-group { display: flex; From 710659510e4e66d8a5069260b5e9a3ff79a05a7a Mon Sep 17 00:00:00 2001 From: Johannes Loher Date: Fri, 23 Jul 2021 17:08:07 +0200 Subject: [PATCH 16/18] Fix items not being rollable in the char sheet --- src/module/actor/sheets/actor-sheet.ts | 2 +- src/module/macros/roll-item.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/module/actor/sheets/actor-sheet.ts b/src/module/actor/sheets/actor-sheet.ts index c11ec973..3dbd267a 100644 --- a/src/module/actor/sheets/actor-sheet.ts +++ b/src/module/actor/sheets/actor-sheet.ts @@ -309,7 +309,7 @@ export class DS4ActorSheet extends ActorSheet notifications.error(e, { log: true })); diff --git a/src/module/macros/roll-item.ts b/src/module/macros/roll-item.ts index 751a7e99..92c59b59 100644 --- a/src/module/macros/roll-item.ts +++ b/src/module/macros/roll-item.ts @@ -38,7 +38,7 @@ async function getOrCreateRollItemMacro(itemData: foundry.data.ItemData["_source } /** - * Executes the roll item macro for the given itemId. + * Executes the roll item macro for the item associated to the given `itemId`. */ export async function rollItem(itemId: string): Promise { const actor = getActiveActor(); From e10a3f17ac8c902c09c8624ab062af12f083eab4 Mon Sep 17 00:00:00 2001 From: Johannes Loher Date: Fri, 23 Jul 2021 17:32:26 +0200 Subject: [PATCH 17/18] Display fallback icon iin the effects tab if no icon is available --- src/lang/de.json | 2 +- src/lang/en.json | 2 +- src/module/active-effect.ts | 5 +++++ src/module/actor/sheets/actor-sheet.ts | 2 ++ 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/lang/de.json b/src/lang/de.json index e18c8ac8..e1dde04a 100644 --- a/src/lang/de.json +++ b/src/lang/de.json @@ -211,7 +211,7 @@ "DS4.CreatureBaseInfoSizeCategory": "Größenkategorie", "DS4.CreatureBaseInfoExperiencePoints": "Erfahrungspunkte", "DS4.CreatureBaseInfoDescription": "Beschreibung", - "DS4.WarningManageActiveEffectOnOwnedItem": "Das Verwalten von aktiven Effekten innerhalb eines besessen Items wird derzeit nicht unterstützt und wird in einem nachfolgenden Update hinzugefügt.", + "DS4.WarningManageActiveEffectOnOwnedItem": "Das Verwalten von aktiven Effekten innerhalb eines besessen Items wird derzeit nicht unterstützt und wird in einem nachfolgenden Update hinzugefügt. Falls Sie eigentlich den auf den Aktor übertragenen Effekt verwalten wollen, können Sie dies im 'Effekte'-Tab des Aktorbogens tun.", "DS4.WarningActorCannotOwnItem": "Der Aktor '{actorName}' vom Typ '{actorType}' kann das Item '{itemName}' vom Typ '{itemType}' nicht besitzen.", "DS4.ErrorDiceCoupFumbleOverlap": "Es gibt eine Überlappung zwischen Patzern und Immersiegen.", "DS4.ErrorSlayingDiceRecursionLimitExceeded": "Die maximale Rekursionstiefe für slayende Würfelwürfe wurde überschritten.", diff --git a/src/lang/en.json b/src/lang/en.json index 694c45f4..d1042021 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -211,7 +211,7 @@ "DS4.CreatureBaseInfoSizeCategory": "Size Category", "DS4.CreatureBaseInfoExperiencePoints": "Experience Points", "DS4.CreatureBaseInfoDescription": "Description", - "DS4.WarningManageActiveEffectOnOwnedItem": "Managing Active Effects within an Owned Item is not currently supported and will be added in a subsequent update.", + "DS4.WarningManageActiveEffectOnOwnedItem": "Managing Active Effects within an Owned Item is not currently supported and will be added in a subsequent update. If you actually want to manage the effect that has been transferred to the actor, you can do so in the 'Effects' tab in the actor sheet.", "DS4.WarningActorCannotOwnItem": "The actor '{actorName}' of type '{actorType}' cannot own the item '{itemName}' of type '{itemType}'.", "DS4.ErrorDiceCoupFumbleOverlap": "There is an overlap between Fumbles and Coups.", "DS4.ErrorSlayingDiceRecursionLimitExceeded": "Maximum recursion depth for slaying dice roll exceeded.", diff --git a/src/module/active-effect.ts b/src/module/active-effect.ts index d4ace9c4..8d53ba28 100644 --- a/src/module/active-effect.ts +++ b/src/module/active-effect.ts @@ -13,6 +13,11 @@ declare global { type PromisedType = T extends Promise ? U : T; export class DS4ActiveEffect extends ActiveEffect { + /** + * A fallback icon that can be used if no icon is defined for the effect. + */ + static FALLBACK_ICON = "icons/svg/aura.svg"; + /** * A cached reference to the source document to avoid recurring database lookups */ diff --git a/src/module/actor/sheets/actor-sheet.ts b/src/module/actor/sheets/actor-sheet.ts index 3dbd267a..9f101e17 100644 --- a/src/module/actor/sheets/actor-sheet.ts +++ b/src/module/actor/sheets/actor-sheet.ts @@ -5,6 +5,7 @@ // // SPDX-License-Identifier: MIT +import { DS4ActiveEffect } from "../../active-effect"; import { ModifiableDataBaseTotal } from "../../common/common-data"; import { DS4 } from "../../config"; import { getCanvas, getGame } from "../../helpers"; @@ -49,6 +50,7 @@ export class DS4ActorSheet extends ActorSheet { return { ...effect.toObject(), + icon: effect.data.icon ?? DS4ActiveEffect.FALLBACK_ICON, sourceName: await effect.getCurrentSourceName(), }; }); From cbc46b7c06e0c4d1b9b9ee59a3238f59b99897e5 Mon Sep 17 00:00:00 2001 From: Johannes Loher Date: Fri, 23 Jul 2021 17:34:52 +0200 Subject: [PATCH 18/18] Make `icon` required in EnrichedActiveEffectDataSource --- src/module/actor/sheets/actor-sheet.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/module/actor/sheets/actor-sheet.ts b/src/module/actor/sheets/actor-sheet.ts index 9f101e17..72d75a81 100644 --- a/src/module/actor/sheets/actor-sheet.ts +++ b/src/module/actor/sheets/actor-sheet.ts @@ -376,5 +376,6 @@ interface DS4ActorSheetData extends ActorSheet.Data { type ActiveEffectDataSource = foundry.data.ActiveEffectData["_source"]; interface EnrichedActiveEffectDataSource extends ActiveEffectDataSource { + icon: string; sourceName: string; }