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 | import { describe, expect, test } from 'bun:test'; |
| 2 | import type { ActiveShip, Waypoint } from '../types'; |
| 3 | import { JUMP_HEIGHT, SHIP_ALTITUDE, shipPose } from './shipPath'; |
| 4 | |
| 5 | const wps: Waypoint[] = [ |
| 6 | { symbol: 'SYS-1-A', system: 'SYS-1', kind: 'station', x: 0, y: 0 }, |
| 7 | { symbol: 'SYS-1-B', system: 'SYS-1', kind: 'jump_gate', x: 100, y: 50 } |
| 8 | ]; |
| 9 | |
| 10 | const base: ActiveShip = { |
| 11 | symbol: 'ORION-1', |
| 12 | status: 'in_orbit', |
| 13 | waypoint: 'SYS-1-A', |
| 14 | route: null, |
| 15 | speed: 30, |
| 16 | fuel: { current: 100, capacity: 100 }, |
| 17 | cargo: { units: 0, capacity: 40, items: [] }, |
| 18 | modules: [], |
| 19 | hull: 100, |
| 20 | insured_until: null, |
| 21 | ready: null, |
| 22 | trade: null |
| 23 | }; |
| 24 | |
| 25 | const t0 = Date.parse('2026-11-06T12:00:00Z'); |
| 26 | const route = (from: string, to: string) => ({ |
| 27 | from, |
| 28 | to, |
| 29 | departed: new Date(t0).toISOString(), |
| 30 | arrives: new Date(t0 + 100_000).toISOString() |
| 31 | }); |
| 32 | |
| 33 | describe('shipPose', () => { |
| 34 | test('parks at its waypoint (game y maps to scene -z)', () => { |
| 35 | const pose = shipPose({ ...base, waypoint: 'SYS-1-B' }, wps, t0); |
| 36 | expect(pose?.position).toEqual([100, SHIP_ALTITUDE, -50]); |
| 37 | expect(pose?.moving).toBe(false); |
| 38 | }); |
| 39 | |
| 40 | test('interpolates an in-system trip and faces the destination', () => { |
| 41 | const ship = { ...base, status: 'in_transit' as const, waypoint: null, route: route('SYS-1-A', 'SYS-1-B') }; |
| 42 | const pose = shipPose(ship, wps, t0 + 50_000); |
| 43 | expect(pose?.position).toEqual([50, SHIP_ALTITUDE, -25]); |
| 44 | expect(pose?.heading).toEqual([100, SHIP_ALTITUDE, -50]); |
| 45 | expect(pose?.moving).toBe(true); |
| 46 | }); |
| 47 | |
| 48 | test('clamps past arrival to the destination', () => { |
| 49 | const ship = { ...base, status: 'in_transit' as const, waypoint: null, route: route('SYS-1-A', 'SYS-1-B') }; |
| 50 | expect(shipPose(ship, wps, t0 + 999_999)?.position).toEqual([100, SHIP_ALTITUDE, -50]); |
| 51 | }); |
| 52 | |
| 53 | test('descends onto the gate when jumping in from another system', () => { |
| 54 | const ship = { ...base, status: 'in_transit' as const, waypoint: null, route: route('OTHER-9-C', 'SYS-1-B') }; |
| 55 | expect(shipPose(ship, wps, t0)?.position[1]).toBe(SHIP_ALTITUDE + JUMP_HEIGHT); |
| 56 | expect(shipPose(ship, wps, t0 + 100_000)?.position[1]).toBe(SHIP_ALTITUDE); |
| 57 | }); |
| 58 | |
| 59 | test('returns null when nothing is known', () => { |
| 60 | expect(shipPose({ ...base, waypoint: 'NOPE-1-Z' }, wps, t0)).toBeNull(); |
| 61 | }); |
| 62 | }); |