summaryrefslogtreecommitdiff
path: root/web/src/lib/game/elements.ts
blob: 61ecde394e65c17f9b8d9593c9ea33ae686425ee (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
/**
 * The six elemental abilities. The indices match the server's `Elements`
 * enum (the state serializes `elementState` as element-index →
 * state-index), and the wire commands `useElement` / `imbueElement` take
 * the enum *name*.
 */

export const ELEMENTS = [
	{ name: 'fire', label: 'Fire', color: 'var(--el-fire)', icon: '/images/psd/element-fire.png' },
	{ name: 'ice', label: 'Ice', color: 'var(--el-ice)', icon: '/images/psd/element-ice.png' },
	{ name: 'air', label: 'Air', color: 'var(--el-air)', icon: '/images/psd/element-air.png' },
	{ name: 'earth', label: 'Earth', color: 'var(--el-earth)', icon: '/images/psd/element-earth.png' },
	{ name: 'light', label: 'Light', color: 'var(--el-light)', icon: '/images/psd/element-light.png' },
	{ name: 'dark', label: 'Dark', color: 'var(--el-dark)', icon: '/images/psd/element-dark.png' },
] as const;

/** ElementState index: 0 full, 1 half, 2 inert. */
export type ElementState = 0 | 1 | 2;

/**
 * The element's fill state from the game state (absent → inert), matching
 * the reference `ElementButton`: a tap uses the element when it is active,
 * imbues it (full) when inert; a long press imbues the half (advanced)
 * amount.
 */
export function elementState(state: Record<string, number>, index: number): ElementState {
	const value = state[String(index)];
	return value === 0 || value === 1 || value === 2 ? value : 2;
}