import { content } from "@deadhead/content"; import { describe, expect, it } from "vitest"; import { createRepositionRecord, dispatchPosition, dispatchProgress, locationPosition, realToGame, } from "../src/index"; const record = createRepositionRecord( { id: "r1", ship: { id: "s1", modelId: "courier", locationId: "earth", inFlight: false }, pilot: { id: "p1", isAvatar: false, assignedShipId: "s1", inFlight: false, skills: {}, restEndsAt: null, }, destinationId: "moon", now: Date.parse("2100-01-01T00:30:00Z"), worldSeed: 7, }, content, ); const midpoint = (record.departureAt + record.arrivalAt) / 2; describe("in-flight progress", () => { it("is 0 at departure, 0.5 at the midpoint and 1 at arrival", () => { expect(dispatchProgress(record, record.departureAt)).toBe(0); expect(dispatchProgress(record, midpoint)).toBe(0.5); expect(dispatchProgress(record, record.arrivalAt)).toBe(1); }); it("stays clamped outside the flight", () => { expect(dispatchProgress(record, record.departureAt - 60_000)).toBe(0); expect(dispatchProgress(record, record.arrivalAt + 3_600_000)).toBe(1); }); }); describe("in-flight position", () => { const origin = locationPosition( content.location("earth")!, realToGame(record.departureAt, content.config), ); const destination = locationPosition( content.location("moon")!, realToGame(record.arrivalAt, content.config), ); it("starts at the origin's position at departure", () => { expect(dispatchPosition(record, record.departureAt, content)).toEqual(origin); }); it("ends at the destination's position at arrival", () => { const end = dispatchPosition(record, record.arrivalAt, content); expect(end.x).toBeCloseTo(destination.x, 9); expect(end.y).toBeCloseTo(destination.y, 9); }); it("is halfway along the line at the midpoint", () => { const mid = dispatchPosition(record, midpoint, content); expect(mid.x).toBeCloseTo((origin.x + destination.x) / 2, 9); expect(mid.y).toBeCloseTo((origin.y + destination.y) / 2, 9); }); });