summaryrefslogtreecommitdiff
path: root/web/src/lib/ui/cards/AbilityText.svelte
diff options
context:
space:
mode:
Diffstat (limited to 'web/src/lib/ui/cards/AbilityText.svelte')
-rw-r--r--web/src/lib/ui/cards/AbilityText.svelte200
1 files changed, 200 insertions, 0 deletions
diff --git a/web/src/lib/ui/cards/AbilityText.svelte b/web/src/lib/ui/cards/AbilityText.svelte
new file mode 100644
index 0000000..51fe672
--- /dev/null
+++ b/web/src/lib/ui/cards/AbilityText.svelte
@@ -0,0 +1,200 @@
+<!--
+ The ability-line renderer (the web counterpart of the reference
+ `LineBuilder.createLines` output, PORTING.md ยง8b). Walks the structured
+ tree produced by `parseLines` and renders it: rows of text / icons /
+ element-use, gray sub-line boxes, dotted conditional boxes, columns,
+ row-groups, element images and dividers. Font metrics come from
+ `resolveStyle` (the reference `LineStyles`); icons come from the served
+ `/images/abilities/` assets.
+-->
+<script lang="ts">
+ import type { LineStyle, Node } from '$lib/game/line/types';
+ import { resolveStyle } from '$lib/game/line/lineStyle';
+ import { abilityImage, dividerImage } from '$lib/game/line/images';
+
+ let {
+ node,
+ fh = true,
+ left = false,
+ scale = 1
+ }: {
+ node: Node;
+ fh?: boolean;
+ left?: boolean;
+ scale?: number;
+ } = $props();
+
+ /** The resolved font metrics for a style. */
+ function r(style: LineStyle) {
+ return resolveStyle(style, fh, left);
+ }
+</script>
+
+{#if node.kind === 'column'}
+ <div class="at-col" style="align-items: {node.align === 'left' ? 'flex-start' : node.align === 'right' ? 'flex-end' : 'center'}">
+ {#each node.children as child}
+ <svelte:self node={child} {fh} {left} {scale} />
+ {/each}
+ </div>
+{:else if node.kind === 'row' || node.kind === 'rowgroup'}
+ <div
+ class="at-row"
+ class:at-row--group={node.kind === 'rowgroup'}
+ style="justify-content: {node.align === 'left' ? 'flex-start' : node.align === 'right' ? 'flex-end' : 'center'}"
+ >
+ {#each node.children as child}
+ <svelte:self node={child} {fh} {left} {scale} />
+ {/each}
+ </div>
+{:else if node.kind === 'subline'}
+ <div class="at-subline" class:at-subline--boss={node.boss}>
+ {#each node.children as child}
+ <svelte:self node={child} {fh} {left} {scale} />
+ {/each}
+ </div>
+{:else if node.kind === 'conditional'}
+ <div class="at-conditional" class:at-conditional--boss={node.boss} class:at-conditional--banner={node.belongs}>
+ {#if node.belongs}
+ <img class="at-conditional__banner" src="/images/abilities/element_top.png" alt="" />
+ {/if}
+ <div class="at-conditional__inner">
+ {#each node.children as child}
+ <svelte:self node={child} {fh} {left} {scale} />
+ {/each}
+ </div>
+ </div>
+{:else if node.kind === 'text'}
+ {@const m = r(node.style)}
+ {#if m.color !== 'transparent'}
+ <span
+ class="at-text"
+ style="font-size: {m.size * scale}px; line-height: {m.height}; color: {m.color}"
+ >{node.text}</span>
+ {:else}
+ <span style="display: inline-block; width: {m.size * scale}px"></span>
+ {/if}
+{:else if node.kind === 'token'}
+ {@const h = r(node.style).size * scale}
+ <img
+ class="at-token"
+ src={abilityImage(node.gfx, node.token, fh)}
+ alt={node.token}
+ style="height: {h}px; width: {h}px"
+ draggable="false"
+ />
+{:else if node.kind === 'elementUse'}
+ {@const h = r(node.style).size * scale}
+ <span class="at-use" style="height: {h}px; width: {h}px">
+ <img src={abilityImage(node.element, node.element, fh)} alt={node.element} style="height: {h}px; width: {h}px" draggable="false" />
+ <img
+ class="at-use__use"
+ src={abilityImage('use', 'use', fh)}
+ alt="use"
+ style="height: {h * 0.5}px"
+ draggable="false"
+ />
+ </span>
+{:else if node.kind === 'image'}
+ {@const h = r('normal').size * scale * (node.element ? 0.6 : 1)}
+ <img
+ class="at-image"
+ src={abilityImage(node.gfx, node.gfx, fh)}
+ alt={node.gfx}
+ style="height: {h}px"
+ draggable="false"
+ />
+{:else if node.kind === 'divider'}
+ <img
+ class="at-divider"
+ src={dividerImage(node.boss)}
+ alt=""
+ style="height: {node.thin ? 2 * scale : 6 * scale}px; width: {55 * scale}px"
+ draggable="false"
+ />
+{/if}
+
+<style>
+ .at-col {
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+ width: 100%;
+ }
+ .at-row {
+ display: flex;
+ flex-direction: row;
+ align-items: center;
+ width: 100%;
+ }
+ .at-row--group {
+ gap: 2px;
+ }
+ .at-text {
+ font-family: 'Markazi', 'Majalla', system-ui, sans-serif;
+ white-space: pre-wrap;
+ text-shadow: 0.4px 0.4px 1px rgba(0, 0, 0, 0.87);
+ }
+ .at-token {
+ display: inline-block;
+ vertical-align: middle;
+ flex-shrink: 0;
+ }
+ .at-image {
+ display: block;
+ margin: 0 auto;
+ }
+ .at-divider {
+ display: block;
+ margin: 0 auto;
+ opacity: 0.9;
+ }
+ .at-use {
+ position: relative;
+ display: inline-block;
+ vertical-align: middle;
+ flex-shrink: 0;
+ }
+ .at-use__use {
+ position: absolute;
+ bottom: 0;
+ left: 20%;
+ }
+ .at-subline {
+ display: flex;
+ flex-direction: column;
+ background: rgba(128, 128, 128, 0.6);
+ border-radius: 6px;
+ padding: 0.5px 2.5px 0.3px 2px;
+ margin: 0 2px;
+ }
+ .at-subline--boss {
+ background: rgba(210, 210, 210, 0.27);
+ }
+ .at-subline .at-row {
+ justify-content: flex-start;
+ }
+ .at-conditional {
+ position: relative;
+ display: inline-block;
+ margin: 2px;
+ }
+ .at-conditional__inner {
+ display: flex;
+ flex-direction: column;
+ background: rgba(128, 128, 128, 0.6);
+ border: 1.5px dotted rgba(255, 255, 255, 0.85);
+ border-radius: 10px;
+ padding: 2px 2px 0.5px 2px;
+ }
+ .at-conditional--boss .at-conditional__inner {
+ background: rgba(210, 210, 210, 0.27);
+ }
+ .at-conditional__banner {
+ position: absolute;
+ top: -3px;
+ left: 50%;
+ transform: translateX(-50%);
+ width: 20px;
+ z-index: 1;
+ }
+</style>