summaryrefslogtreecommitdiff
path: root/web/src/lib/ui/cards/MonsterAbilityCard.svelte
diff options
context:
space:
mode:
Diffstat (limited to 'web/src/lib/ui/cards/MonsterAbilityCard.svelte')
-rw-r--r--web/src/lib/ui/cards/MonsterAbilityCard.svelte157
1 files changed, 157 insertions, 0 deletions
diff --git a/web/src/lib/ui/cards/MonsterAbilityCard.svelte b/web/src/lib/ui/cards/MonsterAbilityCard.svelte
new file mode 100644
index 0000000..5310874
--- /dev/null
+++ b/web/src/lib/ui/cards/MonsterAbilityCard.svelte
@@ -0,0 +1,157 @@
+<!--
+ A monster ability card (the reference `MonsterAbilityCardFront`): the card
+ back with title, initiative, card number, shuffle badge, positioned
+ graphics, and the ability lines rendered by {@link AbilityText} from the
+ `parseLines` tree.
+-->
+<script lang="ts">
+ import type { MonsterAbilityCard } from '$lib/protocol/types';
+ import type { StatMonster } from '$lib/game/line/statApplier';
+ import type { ColumnNode } from '$lib/game/line/types';
+ import { buildAbilityCardTree } from '$lib/game/line/buildAbility';
+ import { gt, gameTable } from '$lib/i18n/gameI18n';
+ import { isElement } from '$lib/game/line/tokens';
+ import AbilityText from './AbilityText.svelte';
+
+ let {
+ card,
+ stat,
+ fh = true,
+ flying = false,
+ scale = 1,
+ applyStats = true,
+ applyAll = false
+ }: {
+ card: MonsterAbilityCard;
+ stat: StatMonster | null;
+ fh?: boolean;
+ flying?: boolean;
+ scale?: number;
+ applyStats?: boolean;
+ applyAll?: boolean;
+ } = $props();
+
+ // The tree re-resolves when the in-game locale table changes.
+ const tree = $derived.by(() => {
+ void $gameTable;
+ return buildAbilityCardTree(card, stat, {
+ fh,
+ flying,
+ scale,
+ applyStats,
+ applyAll
+ }) as ColumnNode;
+ });
+
+ const width = 142.4 * scale;
+ const height = 94.4 * scale;
+
+ const initText = $derived(
+ card.initiative.toString().length === 1
+ ? `0${card.initiative}`
+ : card.initiative.toString()
+ );
+</script>
+
+<div
+ class="mac"
+ style="width: {width}px; height: {height}px; --scale: {scale}"
+>
+ <img
+ class="mac__bg"
+ src={fh ? '/images/psd/monsterAbility-front_fh.png' : '/images/psd/monsterAbility-front.png'}
+ alt=""
+ draggable="false"
+ />
+
+ {#each card.graphics.slice(0, 4) as g}
+ <img
+ class="mac__gfx"
+ src={`/images/abilities/${g.gfx}.png`}
+ alt=""
+ draggable="false"
+ style="left: {g.x * width}px; top: {g.y * height}px; transform: rotate({g.angle}deg) scale({g.scale * scale * (isElement(g.gfx) ? 0.264 : 0.44)}); transform-origin: top left"
+ />
+ {/each}
+
+ <div class="mac__title" style="font-size: {fh ? 10 * scale : 11.2 * scale}px">
+ {gt(card.title)}
+ </div>
+ <div class="mac__init" style="font-size: {fh ? 15 * scale : 16 * scale}px">
+ {initText}
+ </div>
+ <div class="mac__nr" style="font-size: {6.4 * scale}px">{card.nr}</div>
+
+ {#if card.shuffle}
+ <img class="mac__shuffle" src="/images/abilities/shuffle.png" alt="shuffle" draggable="false" style="height: {12.8 * scale}px" />
+ {/if}
+
+ <div class="mac__lines">
+ <AbilityText node={tree} {fh} {scale} />
+ </div>
+</div>
+
+<style>
+ .mac {
+ position: relative;
+ border-radius: 8px;
+ flex-shrink: 0;
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
+ }
+ .mac__bg {
+ position: absolute;
+ inset: 0;
+ width: 100%;
+ height: 100%;
+ border-radius: 8px;
+ object-fit: fill;
+ }
+ .mac__gfx {
+ position: absolute;
+ }
+ .mac__title {
+ position: absolute;
+ top: 2px;
+ left: 0;
+ right: 0;
+ text-align: center;
+ font-family: 'Markazi', 'Majalla', system-ui, sans-serif;
+ color: #fff;
+ text-shadow: 0.6px 0.6px 1px rgba(0, 0, 0, 0.87);
+ white-space: nowrap;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ }
+ .mac__init {
+ position: absolute;
+ left: 4px;
+ top: 12.8px;
+ font-family: 'Markazi', 'Majalla', system-ui, sans-serif;
+ color: #fff;
+ text-shadow: 0.6px 0.6px 1px rgba(0, 0, 0, 0.87);
+ }
+ .mac__nr {
+ position: absolute;
+ left: 4.8px;
+ bottom: 0.4px;
+ font-family: system-ui, sans-serif;
+ color: #fff;
+ text-shadow: 0.6px 0.6px 1px rgba(0, 0, 0, 0.87);
+ }
+ .mac__shuffle {
+ position: absolute;
+ right: 6px;
+ bottom: 3.2px;
+ }
+ .mac__lines {
+ position: absolute;
+ top: 11px;
+ left: 0;
+ right: 0;
+ bottom: 0;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ padding: 0 4px;
+ }
+</style>