feat(database): add public game data registries

This commit is contained in:
JB
2026-07-26 00:39:09 -04:00
parent ae6013d9d6
commit 317e5b39bd
12 changed files with 702 additions and 20 deletions
@@ -0,0 +1,12 @@
<script lang="ts">
import { databaseCategories } from '$lib/database/categories';
let { active = '' }: { active?: string } = $props();
</script>
<nav class="database-category-nav" aria-label="Game database categories">
{#each databaseCategories as category}
<a class:active={active === category.slug} aria-current={active === category.slug ? 'page' : undefined} href={`/database/${category.slug}`}>
<small>{category.code}</small><span>{category.label}</span><b>›</b>
</a>
{/each}
</nav>
@@ -0,0 +1,56 @@
<script lang="ts">
import { goto } from '$app/navigation';
import { page } from '$app/state';
import GameIcon from './GameIcon.svelte';
import ItemIcon from './ItemIcon.svelte';
import type { GameIconName } from '$lib/game-icons';
type Option = { value: string; label: string; iconUrl?: string; gameIcon?: GameIconName };
type Group = { key: string; label: string; kind: 'segmented' | 'searchable'; options: Option[]; selected: string[] };
let { groups }: { groups: Group[] } = $props();
let queries = $state<Record<string, string>>({});
const change = (key: string, value: string) => {
const params = new URLSearchParams(page.url.searchParams);
const selected = params.getAll(key);
params.delete(key);
for (const entry of selected.includes(value) ? selected.filter((entry) => entry !== value) : [...selected, value]) params.append(key, entry);
params.delete('page');
void goto(`${page.url.pathname}?${params}`, { keepFocus: true, noScroll: true });
};
const clear = () => {
const params = new URLSearchParams(page.url.searchParams);
for (const group of groups) params.delete(group.key);
params.delete('page');
void goto(`${page.url.pathname}?${params}`, { noScroll: true });
};
const visible = (group: Group) => {
const query = (queries[group.key] ?? '').normalize('NFKC').trim().toLocaleLowerCase();
return group.options.filter((option) => !query || option.label.toLocaleLowerCase().includes(query));
};
const selectedCount = $derived(groups.reduce((total, group) => total + group.selected.length, 0));
</script>
<section class="database-facet-panel" aria-label="Database filters">
<header><div><small>TACTICAL FILTER MATRIX</small><strong>MATCH ANY WITHIN A GROUP · MATCH EVERY ACTIVE GROUP</strong></div>{#if selectedCount}<button type="button" onclick={clear}>CLEAR {selectedCount} FILTER{selectedCount === 1 ? '' : 'S'}</button>{/if}</header>
<div class="database-facet-groups">
{#each groups as group}
<fieldset class:searchable={group.kind === 'searchable'} class="database-facet-group">
<legend>{group.label}<span>{group.selected.length ? `${group.selected.length} ACTIVE` : 'ANY'}</span></legend>
{#if group.kind === 'searchable'}
<label class="database-facet-search"><span class="sr-only">Search {group.label}</span><input type="search" value={queries[group.key] ?? ''} oninput={(event) => queries[group.key] = event.currentTarget.value} placeholder={`FILTER ${group.label}`}/></label>
{/if}
<div>
{#each visible(group) as option}
<button type="button" class:selected={group.selected.includes(option.value)} aria-pressed={group.selected.includes(option.value)} onclick={() => change(group.key, option.value)}>
{#if option.gameIcon}<GameIcon name={option.gameIcon} decorative/>{:else if option.iconUrl !== undefined}<ItemIcon src={option.iconUrl} alt=""/>{:else}<i aria-hidden="true"></i>{/if}
<span>{option.label}</span>
</button>
{:else}
<small>NO MATCHING OPTIONS</small>
{/each}
</div>
</fieldset>
{/each}
</div>
</section>
@@ -0,0 +1,41 @@
<script lang="ts">
import GameIcon from './GameIcon.svelte';
import ItemIcon from './ItemIcon.svelte';
import ItemIconRail from './ItemIconRail.svelte';
import type { GameIconName } from '$lib/game-icons';
import type { DatabaseItem } from '$lib/database/items';
let {
item
}: {
item: DatabaseItem & { gameIcon?: GameIconName }
} = $props();
</script>
<article class="database-item-card">
<header>
<div class="database-item-icon">
{#if item.gameIcon}<GameIcon name={item.gameIcon} decorative/>{:else}<ItemIcon src={item.iconUrl} alt=""/>{/if}
</div>
<div><small>{item.kicker}</small><h2>{item.name}</h2></div>
</header>
{#if item.badges?.length}<div class="database-item-badges">{#each item.badges as badge}<span class={badge.tone ?? ''}>{badge.label}</span>{/each}</div>{/if}
<div class:stacked={item.factLayout === 'stack'} class="database-item-facts">
{#each item.facts as fact}<div><span>{fact.label}</span><b>{fact.value}</b></div>{/each}
</div>
{#if item.lines?.length}
<div class="database-item-lines">{#each item.lines as line}<div><span>{line.label}</span><b>{line.value}</b></div>{/each}</div>
{/if}
{#if item.iconGroups?.length}
<div class="database-item-icon-groups">
{#each item.iconGroups as group}
<div><span>{group.label}</span><ItemIconRail label={group.label} items={group.items} emptyLabel={group.emptyLabel}/></div>
{/each}
</div>
{/if}
{#if item.description}<p>{item.description}</p>{/if}
{#if item.secondaryDescription}<p class="secondary-description">{item.secondaryDescription}</p>{/if}
{#if item.actions?.length}
<footer class="database-item-actions">{#each item.actions as action}<a href={action.href}>{action.label} →</a>{/each}</footer>
{/if}
</article>
+49
View File
@@ -0,0 +1,49 @@
<script lang="ts">
import ItemIcon from './ItemIcon.svelte';
import type { DatabaseRelatedItem } from '$lib/database/items';
let {
label,
items,
emptyLabel = 'NONE ASSIGNED'
}: {
label: string;
items: DatabaseRelatedItem[];
emptyLabel?: string;
} = $props();
let selected = $state<DatabaseRelatedItem | null>(null);
</script>
<svelte:window onkeydown={(event) => { if (event.key === 'Escape') selected = null; }}/>
<div class="item-icon-rail" aria-label={`${label}: ${items.length ? items.map((item) => item.name).join(', ') : emptyLabel}`}>
{#if items.length}
{#each items as item}
<button type="button" title={`View ${item.name}`} aria-label={`View ${item.name} details`} onclick={() => selected = item}>
<ItemIcon src={item.iconUrl} alt=""/>
</button>
{/each}
{:else}
<small>{emptyLabel}</small>
{/if}
</div>
{#if selected?.preview}
<div class="database-preview-backdrop" role="presentation" onclick={(event) => { if (event.target === event.currentTarget) selected = null; }}>
<div class="database-preview-dialog" role="dialog" aria-modal="true" aria-labelledby={`database-preview-${selected.id}`}>
<header><div><small>DATABASE QUICK VIEW</small><strong id={`database-preview-${selected.id}`}>{selected.preview.name}</strong></div><button type="button" aria-label="Close details" onclick={() => selected = null}>×</button></header>
<article class="database-item-card">
<header>
<div class="database-item-icon"><ItemIcon src={selected.preview.iconUrl} alt=""/></div>
<div><small>{selected.preview.kicker}</small><h2>{selected.preview.name}</h2></div>
</header>
{#if selected.preview.badges?.length}<div class="database-item-badges">{#each selected.preview.badges as badge}<span class={badge.tone ?? ''}>{badge.label}</span>{/each}</div>{/if}
<div class:stacked={selected.preview.factLayout === 'stack'} class="database-item-facts">{#each selected.preview.facts as fact}<div><span>{fact.label}</span><b>{fact.value}</b></div>{/each}</div>
{#if selected.preview.lines?.length}<div class="database-item-lines">{#each selected.preview.lines as line}<div><span>{line.label}</span><b>{line.value}</b></div>{/each}</div>{/if}
{#if selected.preview.description}<p>{selected.preview.description}</p>{/if}
{#if selected.preview.secondaryDescription}<p class="secondary-description">{selected.preview.secondaryDescription}</p>{/if}
{#if selected.preview.actions?.length}<footer class="database-item-actions">{#each selected.preview.actions as action}<a href={action.href}>{action.label} →</a>{/each}</footer>{/if}
</article>
</div>
</div>
{/if}