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 { Canvas } from '@threlte/core'; |
| 3 | import GalaxySceneInner from '$lib/scenes/GalaxySceneInner.svelte'; |
| 4 | import SystemSceneInner from '$lib/scenes/SystemSceneInner.svelte'; |
| 5 | import { |
| 6 | isActive, |
| 7 | systemOf, |
| 8 | type ActiveShip, |
| 9 | type Envelope, |
| 10 | type GalaxyEvent, |
| 11 | type Influence, |
| 12 | type Ship, |
| 13 | type SystemDetail, |
| 14 | type SystemSummary |
| 15 | } from '$lib/types'; |
| 16 | import { useHud } from './hud.svelte'; |
| 17 | |
| 18 | /** |
| 19 | * The one WebGL canvas of the session. It lives in the HUD layout, so moving between |
| 20 | * galaxy and system views swaps scenes instead of tearing down the GL context. |
| 21 | */ |
| 22 | interface Props { |
| 23 | systems: SystemSummary[]; |
| 24 | details: SystemDetail[]; |
| 25 | events: GalaxyEvent[]; |
| 26 | influence: Record<string, Influence>; |
| 27 | ships: Envelope<Ship>[]; |
| 28 | } |
| 29 | |
| 30 | let { systems, details, events, influence, ships }: Props = $props(); |
| 31 | const hud = useHud(); |
| 32 | |
| 33 | const active = $derived(ships.filter((s): s is Envelope<ActiveShip> => isActive(s.data))); |
| 34 | |
| 35 | /** Systems holding (or being entered by) one of the player's ships. */ |
| 36 | const fleet = $derived( |
| 37 | new Set( |
| 38 | active.flatMap((s) => { |
| 39 | const at = s.data.waypoint ?? s.data.route?.to; |
| 40 | return at ? [systemOf(at)] : []; |
| 41 | }) |
| 42 | ) |
| 43 | ); |
| 44 | |
| 45 | const shipsInSystem = $derived.by(() => { |
| 46 | const sym = hud.system?.symbol; |
| 47 | if (!sym) return []; |
| 48 | const inSys = (wp: string | null | undefined) => !!wp && systemOf(wp) === sym; |
| 49 | return active.filter((s) => inSys(s.data.waypoint) || inSys(s.data.route?.to) || inSys(s.data.route?.from)); |
| 50 | }); |
| 51 | </script> |
| 52 | |
| 53 | <Canvas> |
| 54 | {#if hud.mode === 'system' && hud.system} |
| 55 | {#key hud.system.symbol} |
| 56 | <SystemSceneInner |
| 57 | flight={hud.systemFlight} |
| 58 | waypoints={hud.system.waypoints} |
| 59 | ships={shipsInSystem} |
| 60 | selected={hud.selectedWaypoint} |
| 61 | highlights={hud.highlights} |
| 62 | onSelect={(s) => hud.selectWaypoint(s)} |
| 63 | /> |
| 64 | {/key} |
| 65 | {:else} |
| 66 | <GalaxySceneInner |
| 67 | flight={hud.galaxyFlight} |
| 68 | {systems} |
| 69 | {details} |
| 70 | {events} |
| 71 | {influence} |
| 72 | overlay={hud.overlay} |
| 73 | {fleet} |
| 74 | highlights={hud.highlights} |
| 75 | selected={hud.selectedSystem} |
| 76 | onSelect={(s) => hud.selectSystem(s, systems)} |
| 77 | /> |
| 78 | {/if} |
| 79 | </Canvas> |