summaryrefslogtreecommitdiff
path: root/web/src/lib/ui/cards/MonsterAbilityCard.svelte
blob: ab9459f40359e9a732cd9a7921cdd68f03f4893a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
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 = $derived(142.4 * scale);
	const height = $derived(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>