From 05db40fa813d30a1ded19919e147c9530cfee031 Mon Sep 17 00:00:00 2001 From: Kevin Garner Date: Tue, 17 Dec 2024 23:20:42 -0600 Subject: [PATCH] Extracted common active effect summarization code to share. --- .../info-card/Cards/EffectInfoCard.svelte | 43 +++---------------- src/components/item-list/EffectSummary.svelte | 43 +++---------------- src/utils/active-effect.ts | 40 +++++++++++++++++ 3 files changed, 50 insertions(+), 76 deletions(-) diff --git a/src/components/info-card/Cards/EffectInfoCard.svelte b/src/components/info-card/Cards/EffectInfoCard.svelte index 8a94204f2..1c7c3e07b 100644 --- a/src/components/info-card/Cards/EffectInfoCard.svelte +++ b/src/components/info-card/Cards/EffectInfoCard.svelte @@ -3,6 +3,7 @@ import { CONSTANTS } from 'src/constants'; import { FoundryAdapter } from 'src/foundry/foundry-adapter'; import type { ActiveEffect5e } from 'src/types/types'; + import { ActiveEffectsHelper } from 'src/utils/active-effect'; interface Props { activeEffect: ActiveEffect5e; @@ -18,43 +19,9 @@ }), ); - let pills = $derived.by(() => { - let result = []; - - if (activeEffect.disabled) { - result.push('EFFECT.Disabled'); - } - - if (activeEffect.transfer) { - result.push('EFFECT.Transfer'); - } - - if (activeEffect.isSuppressed) { - result.push('DND5E.Suppressed'); - } - - Array.from(activeEffect.statuses) - .map( - (x: string) => CONFIG.statusEffects.find((y) => y.id === x)?.name ?? x, - ) - .forEach((e) => { - result.push(e); - }); - - return result; - }); - - function findMode(mode: number) { - const entry = Object.entries(CONST.ACTIVE_EFFECT_MODES).find( - ([_, value]) => value === mode, - ); - - if (!entry) { - return '—'; - } - - return localize(`EFFECT.MODE_${entry[0]}`); - } + let pills = $derived.by(() => + ActiveEffectsHelper.getActiveEffectPills(activeEffect), + ); const localize = FoundryAdapter.localize; @@ -88,7 +55,7 @@