/** * Arma 3 marker catalog lookups (pure, client-safe). * * The generated catalog mirrors the game config, so every class name accepted * here is a valid `setMarkerType` / `setMarkerColor` / `setMarkerBrush` value. */ import { ARMA_MARKER_BRUSHES, ARMA_MARKER_CATEGORIES, ARMA_MARKER_COLORS, ARMA_MARKER_TYPES, } from "./catalog.generated"; import type { ArmaMarkerBrush, ArmaMarkerCategory, ArmaMarkerColor, ArmaMarkerType, ArmaRgba, } from "./types"; export * from "./types"; export { ARMA_MARKER_BRUSHES, ARMA_MARKER_CATEGORIES, ARMA_MARKER_COLORS, ARMA_MARKER_TYPES }; /** Arma's own marker defaults (what `createMarker` produces before any setters). */ export const DEFAULT_MARKER_TYPE = "mil_dot"; export const DEFAULT_MARKER_COLOR = "Default"; export const DEFAULT_MARKER_BRUSH = "Solid"; const typeIndex = new Map( ARMA_MARKER_TYPES.map((entry) => [entry.className.toLowerCase(), entry]), ); const colorIndex = new Map( ARMA_MARKER_COLORS.map((entry) => [entry.className.toLowerCase(), entry]), ); const brushIndex = new Map( ARMA_MARKER_BRUSHES.map((entry) => [entry.className.toLowerCase(), entry]), ); /** Arma class names are case-insensitive; lookups are too. */ export function markerTypeOf(className: string | null | undefined): ArmaMarkerType | null { return className ? (typeIndex.get(className.toLowerCase()) ?? null) : null; } export function markerColorOf(className: string | null | undefined): ArmaMarkerColor | null { return className ? (colorIndex.get(className.toLowerCase()) ?? null) : null; } export function markerBrushOf(className: string | null | undefined): ArmaMarkerBrush | null { return className ? (brushIndex.get(className.toLowerCase()) ?? null) : null; } /** * The color a marker actually renders with. "Default" (or an unknown class) * means "the marker type's own config color", which for NATO symbols is the * side color; areas and lines have no type, so they fall back to black like * in-game. */ export function resolveMarkerRgba( colorClass: string | null | undefined, typeClass?: string | null, ): ArmaRgba { const color = markerColorOf(colorClass); if (color && color.className.toLowerCase() !== "default") return color.rgba; const type = markerTypeOf(typeClass); if (type) return type.color; return color?.rgba ?? [0, 0, 0, 1]; } function channelHex(value: number): string { const clamped = Math.max(0, Math.min(1, value)); return Math.round(clamped * 255) .toString(16) .padStart(2, "0"); } /** "#rrggbb" for an Arma RGBA (alpha is applied separately as opacity). */ export function rgbaToHex(rgba: ArmaRgba): string { return `#${channelHex(rgba[0])}${channelHex(rgba[1])}${channelHex(rgba[2])}`; } /** Marker types grouped by CfgMarkerClasses category, in config order. */ export function markerTypesByCategory(): { category: ArmaMarkerCategory; types: ArmaMarkerType[]; }[] { const groups = new Map(); for (const type of ARMA_MARKER_TYPES) { const key = type.category; const list = groups.get(key) ?? []; list.push(type); groups.set(key, list); } const known = new Map(ARMA_MARKER_CATEGORIES.map((c) => [c.className, c])); const ordered: { category: ArmaMarkerCategory; types: ArmaMarkerType[] }[] = []; for (const category of ARMA_MARKER_CATEGORIES) { const types = groups.get(category.className); if (types?.length) ordered.push({ category, types }); } for (const [key, types] of groups) { if (!known.has(key)) ordered.push({ category: { className: key, name: key }, types }); } return ordered; }