starfleet-ui
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#6 · main · 2 min 01 s
0Étoiles
0Forks
0Issues
| 1 | <script lang="ts"> |
| 2 | import { page } from '$app/state'; |
| 3 | import { Tween } from 'svelte/motion'; |
| 4 | import { cubicOut } from 'svelte/easing'; |
| 5 | import { sound, toggleMute } from '$lib/sound.svelte'; |
| 6 | import type { GalaxyEvent } from '$lib/types'; |
| 7 | |
| 8 | interface Props { |
| 9 | callsign: string; |
| 10 | credits: number; |
| 11 | events: GalaxyEvent[]; |
| 12 | } |
| 13 | |
| 14 | let { callsign, credits, events }: Props = $props(); |
| 15 | |
| 16 | // Credits count up/down so the player sees trades land. |
| 17 | const shown = new Tween(0, { duration: 700, easing: cubicOut }); |
| 18 | let lastCredits: number | null = null; |
| 19 | let delta = $state<number | null>(null); |
| 20 | $effect(() => { |
| 21 | const c = credits; |
| 22 | if (lastCredits !== null && c !== lastCredits) { |
| 23 | delta = c - lastCredits; |
| 24 | const t = setTimeout(() => (delta = null), 2500); |
| 25 | lastCredits = c; |
| 26 | shown.set(c); |
| 27 | return () => clearTimeout(t); |
| 28 | } |
| 29 | lastCredits = c; |
| 30 | shown.set(c, { duration: 0 }); |
| 31 | }); |
| 32 | |
| 33 | const live = $derived.by(() => { |
| 34 | const t = Date.now(); |
| 35 | return events.filter((e) => Date.parse(e.starts) <= t && t < Date.parse(e.ends)); |
| 36 | }); |
| 37 | |
| 38 | const NAV = [ |
| 39 | { href: '/', label: 'Map' }, |
| 40 | { href: '/contracts', label: 'Contracts' }, |
| 41 | { href: '/postings', label: 'Postings' }, |
| 42 | { href: '/federation', label: 'Federation' }, |
| 43 | { href: '/factions', label: 'Factions' }, |
| 44 | { href: '/messages', label: 'Messages' }, |
| 45 | { href: '/codex', label: 'Codex' } |
| 46 | ]; |
| 47 | |
| 48 | const EVENT_STYLE: Record<GalaxyEvent['kind'], string> = { |
| 49 | storm: 'border-red-500/50 text-red-200 bg-red-950/50', |
| 50 | boom: 'border-emerald-500/50 text-emerald-200 bg-emerald-950/50', |
| 51 | surge: 'border-orange-500/50 text-orange-200 bg-orange-950/50' |
| 52 | }; |
| 53 | const EVENT_HELP: Record<GalaxyEvent['kind'], string> = { |
| 54 | storm: 'Solar storm: the gate is closed, no jumps in or out.', |
| 55 | boom: 'Mining boom: extraction yields doubled.', |
| 56 | surge: 'Pirate surge: hull wear tripled.' |
| 57 | }; |
| 58 | |
| 59 | const isActive = (href: string) => (href === '/' ? page.url.pathname === '/' : page.url.pathname.startsWith(href)); |
| 60 | </script> |
| 61 | |
| 62 | <header class="hud-panel pointer-events-auto flex items-center gap-3 rounded-none border-x-0 border-t-0 px-3 py-2 md:gap-5 md:px-4"> |
| 63 | <a href="/" class="font-display text-lg font-black tracking-[0.3em] text-cyan-300">STARFLEET</a> |
| 64 | |
| 65 | <nav class="flex min-w-0 flex-1 gap-1 overflow-x-auto" aria-label="Sections"> |
| 66 | {#each NAV as item (item.href)} |
| 67 | <a |
| 68 | href={item.href} |
| 69 | aria-current={isActive(item.href) ? 'page' : undefined} |
| 70 | class="rounded-md px-2.5 py-1 text-sm whitespace-nowrap transition {isActive(item.href) |
| 71 | ? 'bg-cyan-400/15 text-cyan-200' |
| 72 | : 'text-slate-400 hover:bg-slate-800/70 hover:text-slate-100'}" |
| 73 | > |
| 74 | {item.label} |
| 75 | </a> |
| 76 | {/each} |
| 77 | </nav> |
| 78 | |
| 79 | {#if live.length} |
| 80 | <ul class="hidden max-w-sm gap-1.5 overflow-hidden lg:flex" aria-label="Galaxy events"> |
| 81 | {#each live.slice(0, 4) as e (e.system + e.kind)} |
| 82 | <li> |
| 83 | <a |
| 84 | href="/systems/{e.system}" |
| 85 | title={EVENT_HELP[e.kind]} |
| 86 | class="block rounded-full border px-2 py-0.5 font-mono text-[11px] whitespace-nowrap {EVENT_STYLE[e.kind]}" |
| 87 | > |
| 88 | {e.kind} · {e.system} |
| 89 | </a> |
| 90 | </li> |
| 91 | {/each} |
| 92 | {#if live.length > 4}<li class="text-xs text-slate-500">+{live.length - 4}</li>{/if} |
| 93 | </ul> |
| 94 | {/if} |
| 95 | |
| 96 | <div class="flex items-center gap-3"> |
| 97 | <div class="text-right leading-tight"> |
| 98 | <div class="font-mono text-xs font-bold text-cyan-200">{callsign}</div> |
| 99 | <div class="relative font-mono text-sm text-amber-300 tabular-nums"> |
| 100 | {Math.round(shown.current).toLocaleString('en-US')} cr |
| 101 | {#if delta} |
| 102 | <span |
| 103 | class="animate-rise absolute top-full right-0 text-xs {delta > 0 ? 'text-emerald-300' : 'text-red-300'}" |
| 104 | aria-live="polite" |
| 105 | > |
| 106 | {delta > 0 ? '+' : ''}{delta.toLocaleString('en-US')} |
| 107 | </span> |
| 108 | {/if} |
| 109 | </div> |
| 110 | </div> |
| 111 | <button |
| 112 | onclick={toggleMute} |
| 113 | aria-label={sound.muted ? 'Unmute sounds' : 'Mute sounds'} |
| 114 | class="rounded-md border border-slate-700 px-2 py-1 text-sm text-slate-300 hover:border-cyan-400/50" |
| 115 | > |
| 116 | {sound.muted ? '🔇' : '🔊'} |
| 117 | </button> |
| 118 | <form method="POST" action="/logout"> |
| 119 | <button class="rounded-md px-2 py-1 text-xs tracking-wider text-slate-500 uppercase hover:text-red-300">Log out</button> |
| 120 | </form> |
| 121 | </div> |
| 122 | </header> |