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 { T, useThrelte } from '@threlte/core'; |
| 3 | import { HTML, Stars, interactivity, type IntersectionEvent } from '@threlte/extras'; |
| 4 | import * as THREE from 'three'; |
| 5 | import { MODELS } from '$lib/assets/manifest'; |
| 6 | import type { ActiveShip, Envelope, Waypoint } from '$lib/types'; |
| 7 | import AsteroidField from './AsteroidField.svelte'; |
| 8 | import CameraRig from './CameraRig.svelte'; |
| 9 | import type { CameraFlight } from './camera.svelte'; |
| 10 | import { systemPos } from './coords'; |
| 11 | import Star from './Star.svelte'; |
| 12 | import JumpGate from './JumpGate.svelte'; |
| 13 | import Model from './Model.svelte'; |
| 14 | import Planet from './Planet.svelte'; |
| 15 | import ShipMarker from './ShipMarker.svelte'; |
| 16 | import Station from './Station.svelte'; |
| 17 | import Wormhole from './Wormhole.svelte'; |
| 18 | |
| 19 | interface Props { |
| 20 | flight: CameraFlight; |
| 21 | waypoints: Envelope<Waypoint>[]; |
| 22 | ships: Envelope<ActiveShip>[]; |
| 23 | selected: string | null; |
| 24 | onSelect: (symbol: string) => void; |
| 25 | /** Waypoints to emphasise (hint targets, trade stops). */ |
| 26 | highlights?: ReadonlySet<string>; |
| 27 | } |
| 28 | |
| 29 | let { flight, waypoints, ships, selected, onSelect, highlights = new Set() }: Props = $props(); |
| 30 | |
| 31 | interactivity(); |
| 32 | const { dom } = useThrelte(); |
| 33 | |
| 34 | let hovered = $state<string | null>(null); |
| 35 | $effect(() => { |
| 36 | dom.style.cursor = hovered ? 'pointer' : ''; |
| 37 | }); |
| 38 | |
| 39 | const selectionRing = new THREE.RingGeometry(6.5, 7.1, 48); |
| 40 | const highlightRing = new THREE.RingGeometry(8.2, 8.7, 48); |
| 41 | $effect(() => () => { |
| 42 | selectionRing.dispose(); |
| 43 | highlightRing.dispose(); |
| 44 | }); |
| 45 | |
| 46 | const PLANET_SIZE: Record<string, number> = { planet: 3.5, gas_giant: 5, moon: 1.8 }; |
| 47 | </script> |
| 48 | |
| 49 | <CameraRig {flight} /> |
| 50 | |
| 51 | <T.AmbientLight intensity={0.45} /> |
| 52 | <T.DirectionalLight position={[80, 120, 40]} intensity={1.2} /> |
| 53 | <Star /> |
| 54 | <Stars radius={400} depth={100} count={4000} factor={6} fade /> |
| 55 | |
| 56 | <!-- system plane grid --> |
| 57 | <T.GridHelper args={[300, 30, '#164e63', '#0f172a']} position={[0, -4, 0]} /> |
| 58 | |
| 59 | {#each waypoints as w (w.data.symbol)} |
| 60 | {@const p = systemPos(w.data)} |
| 61 | {@const click = (e: IntersectionEvent<MouseEvent>) => { |
| 62 | e.stopPropagation(); |
| 63 | onSelect(w.data.symbol); |
| 64 | }} |
| 65 | {@const enter = (e: IntersectionEvent<PointerEvent>) => { |
| 66 | e.stopPropagation(); |
| 67 | hovered = w.data.symbol; |
| 68 | }} |
| 69 | {@const leave = () => { |
| 70 | if (hovered === w.data.symbol) hovered = null; |
| 71 | }} |
| 72 | |
| 73 | <T.Group onpointerenter={enter} onpointerleave={leave}> |
| 74 | {#if w.data.kind === 'planet' || w.data.kind === 'gas_giant' || w.data.kind === 'moon'} |
| 75 | <Planet kind={w.data.kind} symbol={w.data.symbol} size={PLANET_SIZE[w.data.kind]} position={p} onclick={click} /> |
| 76 | {:else if w.data.kind === 'station'} |
| 77 | <Station position={p} onclick={click} /> |
| 78 | {:else if w.data.kind === 'jump_gate'} |
| 79 | <JumpGate position={p} onclick={click} /> |
| 80 | {:else if w.data.kind === 'asteroid_field'} |
| 81 | <AsteroidField symbol={w.data.symbol} position={p} onclick={click} /> |
| 82 | {:else if w.data.kind === 'wormhole'} |
| 83 | <Wormhole symbol={w.data.symbol} position={p} onclick={click} /> |
| 84 | {:else if w.data.kind === 'derelict'} |
| 85 | <Model src={MODELS.derelict} position={p} scale={2} rotation={[0.4, 0.7, 0.5]} onclick={click} /> |
| 86 | <T.PointLight position={[p[0], p[1] + 2, p[2]]} color="#ef4444" intensity={8} distance={18} /> |
| 87 | {:else} |
| 88 | <T.Mesh position={p} onclick={click}> |
| 89 | <T.SphereGeometry args={[2, 24, 24]} /> |
| 90 | <T.MeshStandardMaterial color="#d6d3d1" emissive="#57534e" emissiveIntensity={0.5} /> |
| 91 | </T.Mesh> |
| 92 | {/if} |
| 93 | </T.Group> |
| 94 | |
| 95 | {#if selected === w.data.symbol} |
| 96 | <T.Mesh position={p} rotation.x={-Math.PI / 2} geometry={selectionRing}> |
| 97 | <T.MeshBasicMaterial color="#22d3ee" transparent opacity={0.9} side={THREE.DoubleSide} /> |
| 98 | </T.Mesh> |
| 99 | {/if} |
| 100 | |
| 101 | {#if highlights.has(w.data.symbol)} |
| 102 | <T.Mesh position={p} rotation.x={-Math.PI / 2} geometry={highlightRing}> |
| 103 | <T.MeshBasicMaterial color="#a78bfa" transparent opacity={0.85} side={THREE.DoubleSide} /> |
| 104 | </T.Mesh> |
| 105 | {/if} |
| 106 | |
| 107 | <HTML position={[p[0], p[1] + 8, p[2]]} center pointerEvents="none" class="pointer-events-none"> |
| 108 | <div |
| 109 | class="rounded px-1.5 py-0.5 font-mono text-[10px] whitespace-nowrap {selected === |
| 110 | w.data.symbol |
| 111 | ? 'bg-cyan-950/90 text-cyan-200' |
| 112 | : hovered === w.data.symbol |
| 113 | ? 'bg-slate-900/90 text-slate-200' |
| 114 | : 'bg-slate-950/70 text-slate-400'}" |
| 115 | > |
| 116 | {w.data.symbol} |
| 117 | </div> |
| 118 | </HTML> |
| 119 | {/each} |
| 120 | |
| 121 | {#each ships as ship (ship.data.symbol)} |
| 122 | <ShipMarker {ship} {waypoints} /> |
| 123 | {/each} |