Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
be11aac356 | ||
|
|
fdc5624b0c | ||
|
|
ff4ced9d71 | ||
|
|
d14ffdcf2f | ||
|
|
d083b5b708 | ||
|
|
c012b0fe56 | ||
|
|
6483d510ef | ||
|
|
bc6bc7dd07 |
@@ -1,5 +1,14 @@
|
||||
# Changelog
|
||||
|
||||
## v0.9.11 — 2026-09-29 14:49
|
||||
- NAVIGATION AI now enables multi-system jumps (#35): once the existing root tech is researched, `/api/jump` accepts targets up to two hops away (BFS over jump routes) and a multi-hop jump costs one turn per hop — single-hop jumps keep their existing cost. On the WORLD MAP chart, two-hop systems become clickable JUMP fields with a distinct `// JUMP ×2` sublabel; without the tech the range stays adjacent-only as before.
|
||||
- e2e: new spec researches NAVIGATION AI (scan loop + SKILL TREE UI) and jumps to a two-hop system in one action, asserting the world state and the +2 turn cost; the world-map button-count spec now derives its expected count from the save's tech state so it holds across retries on the shared CI DB.
|
||||
|
||||
## v0.9.10 — 2026-09-29 12:57
|
||||
- The WORLD MAP now fills the entire available area of its tab (#36): in wide mode (pinned viewport, #21) the OPERATIONS Tabs are a full-height flex column and the world-map panel flexes to the bottom of the pane — the chart SVG sizes to the measured container instead of the old fixed 380px height, so there is no internal scrollbar on this tab at any window size. The scene keeps its viewBox and scales with the pane on resizes (pan/zoom stay accurate; re-fitting after a resize is intentionally not done). Narrow mode keeps the fixed fallback height since the page scrolls naturally there.
|
||||
- Follow-up to that layout change (CI run 382): the OPERATIONS Tabs root uses `min-height: 100%` instead of `height: 100%`. With a capped height, a tall tab's content overflowed the flex column and shrank items down to their automatic minimum — the tablist's `overflow-x: auto` zeroes that minimum per CSS spec, so the bar collapsed to ~0px with its buttons clipped out of hit-testing (every subsequent tab click failed with "div intercepts pointer events"); a capped box also released the sticky pin on deep scrolls. With min-height the box grows to fit tall tabs — the bar keeps its natural height and stays pinned across the whole scroll range, while WORLD MAP still fills the pane exactly.
|
||||
- e2e: the #31 spec no longer relies on WORLD MAP's overflow to force scrolling — it now switches to SHIP SYSTEMS, whose six always-present stacked system cards deterministically overflow the shrunk 1280×560 pane (waiting for the HULL card first), and asserts the same pinned tab bar.
|
||||
|
||||
## v0.9.9 — 2026-09-29 11:21
|
||||
- The WORLD MAP chart is now a force-directed graph (d3-force) with pan + zoom (d3-zoom), replacing the hand-rolled static NodeGraph render (#28): nodes settle into a dynamic layout seeded from the API coordinates and visibly rearrange after every jump, then auto zoom-to-fit so the whole network stays framed in the chart box. Wheel/drag pans and zooms the scene; only systems adjacent to the current one remain clickable (same `role=button` + name contract as before), all nodes lock while a jump is in flight, and a real pan's trailing click never triggers an accidental jump. Jump flow (`POST /api/jump`, turn counter, `onJumped` refresh from #30) is unchanged; the now-orphaned hand-rolled `NodeGraph` component (world map was its only consumer) is deleted.
|
||||
|
||||
|
||||
@@ -160,6 +160,12 @@ body {
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
/* Radix Tabs hides inactive content via the `hidden` attribute, but inline display styles (the
|
||||
#36 pane-fill flex chain on the WORLD MAP tab) outrank the UA stylesheet — restore semantics. */
|
||||
[hidden] {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
#root {
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
@@ -130,6 +130,7 @@ export function MissionControl() {
|
||||
// Slugs of the researched techs — drives the effective caps + build gates in the SHIP SYSTEMS
|
||||
// tab via the same pure helpers the API enforces (lib/game/tech.ts).
|
||||
const researchedSlugs = new Set((techs ?? []).filter((t) => t.state === 'RESEARCHED').map((t) => t.slug))
|
||||
const navAi = researchedSlugs.has('NAV_AI') // #35 — two-hop systems become jumpable chart fields
|
||||
|
||||
return (
|
||||
<div
|
||||
@@ -383,12 +384,17 @@ export function MissionControl() {
|
||||
</PanelHeader>
|
||||
|
||||
<PanelContent style={{ padding: 0, flex: 1, minHeight: 0, overflowY: 'auto' }}>
|
||||
{/* Flex column at least pane-tall so a tab can fill it (#36). min-height, not height:
|
||||
tall tabs grow the box to their content, which keeps the sticky tab bar's containing
|
||||
block spanning the whole scroll range (a capped height releases the pin on deep
|
||||
scrolls) and means items never overflow the box, so nothing gets shrink-squashed. */}
|
||||
<Tabs
|
||||
value={activeTab ?? 'world-map'}
|
||||
onValueChange={(v) => {
|
||||
setActiveTab(v)
|
||||
window.localStorage.setItem(ACTIVE_TAB_KEY, v) // #27 — keep the tab across refreshes
|
||||
}}
|
||||
style={{ display: 'flex', flexDirection: 'column', minHeight: '100%' }}
|
||||
>
|
||||
<TabsList
|
||||
style={{
|
||||
@@ -409,9 +415,14 @@ export function MissionControl() {
|
||||
<TabsTrigger value="event-log">EVENT LOG</TabsTrigger>
|
||||
</TabsList>
|
||||
|
||||
{/* WORLD MAP TAB — live data from /api/world */}
|
||||
<TabsContent value="world-map" style={{ margin: 0, padding: '1rem' }}>
|
||||
<WorldMapPanel height={380} onJumped={refreshSystem} />
|
||||
{/* WORLD MAP TAB — live data from /api/world; fills the whole pane (#36). Wide mode:
|
||||
flex column so the panel can fill it with pure flex sizing (a min-height-only
|
||||
container breaks percentage resolution, so no height:'100%' anywhere in this chain). */}
|
||||
<TabsContent
|
||||
value="world-map"
|
||||
style={{ margin: 0, padding: '1rem', ...(!narrow ? { display: 'flex', flexDirection: 'column', flex: 1, minHeight: 0 } : {}) }}
|
||||
>
|
||||
<WorldMapPanel height={380} narrow={narrow} navAi={navAi} onJumped={refreshSystem} />
|
||||
</TabsContent>
|
||||
|
||||
{/* LOCAL SYSTEM TAB — live data (state owned by MissionControl; scans report up) */}
|
||||
|
||||
+42
-23
@@ -6,15 +6,20 @@ import type { SimulationNodeDatum } from 'd3-force'
|
||||
import { select } from 'd3-selection'
|
||||
import { zoom, zoomIdentity } from 'd3-zoom'
|
||||
import type { WorldState } from '@/lib/game/save'
|
||||
import { reachableWithin } from '@/lib/game/world'
|
||||
|
||||
// WORLD MAP tab — real world state from /api/world on a force-directed chart (d3-force) with
|
||||
// pan + zoom (d3-zoom), per #28. Clicking a system adjacent to the current one jumps there
|
||||
// (same POST /api/jump flow as before); the current and unreachable systems are dimmed and not
|
||||
// pan + zoom (d3-zoom), per #28. Clicking a system within jump range of the current one jumps
|
||||
// there (same POST /api/jump flow as before; two hops away once NAVIGATION AI is researched,
|
||||
// #35); the current and unreachable systems are dimmed and not
|
||||
// clickable, and every node is locked while a jump is in flight. Turn-based: fetch on mount,
|
||||
// refetch via the jump response — no polling.
|
||||
// refetch via the jump response — no polling. In wide mode (#36) the chart fills the whole tab
|
||||
// pane (no internal scrollbar); narrow keeps a fixed fallback height since the page scrolls naturally there.
|
||||
|
||||
interface WorldMapPanelProps {
|
||||
height?: number
|
||||
height?: number // fallback chart height when the pane gives no definite space (narrow mode)
|
||||
narrow?: boolean
|
||||
navAi?: boolean // #35 — NAVIGATION AI researched: two-hop systems are jumpable fields too
|
||||
onJumped?: () => void // #30 — let the parent refresh /api/system after a successful jump
|
||||
}
|
||||
|
||||
@@ -44,7 +49,9 @@ const STATUS_COLOR: Record<NodeStatus, string> = {
|
||||
offline: 'var(--border)',
|
||||
}
|
||||
|
||||
export function WorldMapPanel({ height = 380, onJumped }: WorldMapPanelProps) {
|
||||
export function WorldMapPanel({ height = 380, narrow = false, navAi = false, onJumped }: WorldMapPanelProps) {
|
||||
// Wide mode: the flex chain (Tabs → TabsContent → this panel) provides a definite pane size to fill (#36).
|
||||
const filling = !narrow
|
||||
const [world, setWorld] = useState<WorldState | null>(null)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [jumpingId, setJumpingId] = useState<number | null>(null)
|
||||
@@ -99,32 +106,35 @@ export function WorldMapPanel({ height = 380, onJumped }: WorldMapPanelProps) {
|
||||
const container = containerRef.current
|
||||
if (!container || !world) return
|
||||
|
||||
// Measured pane size (#36): the flex chain gives a definite box in wide mode; `height` is the
|
||||
// fallback when the container has no resolved size yet (narrow flow, or tab hidden on load).
|
||||
const W = container.clientWidth || 800
|
||||
const H = container.clientHeight || height
|
||||
const current = world.systems.find((s) => s.current)!
|
||||
// Systems one jump away — the only clickable chart fields (the same set as before).
|
||||
const reachableIds = new Set(
|
||||
world.edges.filter(([a, b]) => a === current.id || b === current.id).map(([a, b]) => (a === current.id ? b : a))
|
||||
)
|
||||
// Clickable chart fields: one hop away, or two hops once NAVIGATION AI is researched (#35).
|
||||
const hops = reachableWithin(world.edges, current.id, navAi ? 2 : 1)
|
||||
|
||||
const nodes: ChartNode[] = world.systems.map((s) => ({
|
||||
id: s.id,
|
||||
name: s.name.toUpperCase(),
|
||||
status: s.current ? 'current' : reachableIds.has(s.id) ? 'jumpable' : 'offline',
|
||||
status: s.current ? 'current' : hops.has(s.id) ? 'jumpable' : 'offline',
|
||||
sublabel: s.current
|
||||
? 'CURRENT'
|
||||
: reachableIds.has(s.id)
|
||||
? (s.discovered ? 'DISCOVERED // JUMP' : 'UNKNOWN // JUMP')
|
||||
: hops.has(s.id)
|
||||
? `${s.discovered ? 'DISCOVERED' : 'UNKNOWN'} // JUMP${(hops.get(s.id) ?? 1) > 1 ? ' ×2' : ''}`
|
||||
: s.discovered ? 'DISCOVERED' : 'UNKNOWN',
|
||||
x: (s.x / 100) * W, // seed from the API coordinates so the layout settles near the old chart
|
||||
y: (s.y / 100) * height,
|
||||
y: (s.y / 100) * H,
|
||||
}))
|
||||
const links: ChartLink[] = world.edges.map(([a, b]) => ({ source: a, target: b }))
|
||||
|
||||
// width/height 100% + fixed viewBox: the scene scales with the pane on window resizes without
|
||||
// rebuilding (pan/zoom stay accurate — d3 maps pointers through the SVG transform matrix).
|
||||
const svg = select(container)
|
||||
.append('svg')
|
||||
.attr('width', '100%')
|
||||
.attr('height', height)
|
||||
.attr('viewBox', `0 0 ${W} ${height}`)
|
||||
.attr('height', '100%')
|
||||
.attr('viewBox', `0 0 ${W} ${H}`)
|
||||
.style('display', 'block')
|
||||
|
||||
const root = svg.append('g')
|
||||
@@ -162,9 +172,9 @@ export function WorldMapPanel({ height = 380, onJumped }: WorldMapPanelProps) {
|
||||
maxY = Math.max(maxY, (n.y ?? 0) + NODE_H / 2)
|
||||
}
|
||||
const pad = 16
|
||||
const scale = Math.min(W / (maxX - minX + pad * 2), height / (maxY - minY + pad * 2))
|
||||
const scale = Math.min(W / (maxX - minX + pad * 2), H / (maxY - minY + pad * 2))
|
||||
const tx = W / 2 - scale * ((minX + maxX) / 2)
|
||||
const ty = height / 2 - scale * ((minY + maxY) / 2)
|
||||
const ty = H / 2 - scale * ((minY + maxY) / 2)
|
||||
svg.call(zoomBehavior.transform, zoomIdentity.translate(tx, ty).scale(scale))
|
||||
}
|
||||
|
||||
@@ -220,7 +230,7 @@ export function WorldMapPanel({ height = 380, onJumped }: WorldMapPanelProps) {
|
||||
const simulation = forceSimulation(nodes)
|
||||
.force('link', forceLink<ChartNode, ChartLink>(links).id((d) => d.id).distance(130).strength(0.25))
|
||||
.force('charge', forceManyBody().strength(-420))
|
||||
.force('center', forceCenter(W / 2, height / 2))
|
||||
.force('center', forceCenter(W / 2, H / 2))
|
||||
.force('collide', forceCollide(60))
|
||||
.on('end', fitToNodes)
|
||||
.on('tick', () => {
|
||||
@@ -236,7 +246,7 @@ export function WorldMapPanel({ height = 380, onJumped }: WorldMapPanelProps) {
|
||||
simulation.stop()
|
||||
svg.remove()
|
||||
}
|
||||
}, [world, jumpingId, jump, height])
|
||||
}, [world, jumpingId, jump, height, navAi])
|
||||
|
||||
if (error && !world) {
|
||||
return (
|
||||
@@ -256,10 +266,19 @@ export function WorldMapPanel({ height = 380, onJumped }: WorldMapPanelProps) {
|
||||
)
|
||||
}
|
||||
|
||||
// flex (not height:'100%'): the pane chain is sized by min-height, where percentages don't resolve
|
||||
return (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: '0.75rem' }}>
|
||||
{/* Same wrapper + title bar as the old hand-rolled chart; d3 owns everything inside the box. */}
|
||||
<div style={{ border: '1px solid var(--border)', background: 'var(--surface)', fontFamily: 'var(--font-mono)', overflow: 'hidden' }}>
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: '0.75rem', ...(filling ? { flex: 1, minHeight: 0 } : {}) }}>
|
||||
{/* Wrapper + title bar; in wide mode the box flexes to fill the whole pane (#36). d3 owns everything inside it. */}
|
||||
<div
|
||||
style={{
|
||||
border: '1px solid var(--border)',
|
||||
background: 'var(--surface)',
|
||||
fontFamily: 'var(--font-mono)',
|
||||
overflow: 'hidden',
|
||||
...(filling ? { flex: 1, minHeight: 0, display: 'flex', flexDirection: 'column' } : {}),
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
padding: '0.4rem 0.75rem',
|
||||
@@ -273,7 +292,7 @@ export function WorldMapPanel({ height = 380, onJumped }: WorldMapPanelProps) {
|
||||
>
|
||||
GALACTIC CHART // JUMP ROUTES — TURN {world.turn}
|
||||
</div>
|
||||
<div ref={containerRef} style={{ width: '100%', height: `${height}px` }} />
|
||||
<div ref={containerRef} style={{ width: '100%', ...(filling ? { flex: 1, minHeight: 0 } : { height: `${height}px` }) }} />
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
|
||||
+77
-5
@@ -87,8 +87,11 @@ test('tab bar stays pinned while panel content scrolls (#31)', async ({ page })
|
||||
// Shrink the viewport so the center pane's content overflows its scroll area regardless of save state.
|
||||
await page.setViewportSize({ width: 1280, height: 560 });
|
||||
|
||||
// WORLD MAP is always tall enough to overflow (fixed-height chart) — deterministic across retries.
|
||||
await page.getByRole('tab', { name: 'WORLD MAP' }).click();
|
||||
// SHIP SYSTEMS always renders six stacked system cards (seeded at start, never removed) — tall
|
||||
// enough to overflow the shrunk pane on any save state, deterministic across retries. (#36 made
|
||||
// WORLD MAP fill its pane instead of overflowing it, so it can no longer force the scroll.)
|
||||
await page.getByRole('tab', { name: 'SHIP SYSTEMS' }).click();
|
||||
await expect(page.getByRole('heading', { name: 'HULL' })).toBeVisible();
|
||||
|
||||
const tablist = page.getByRole('tablist');
|
||||
await expect(tablist).toBeVisible();
|
||||
@@ -114,16 +117,21 @@ test('tab bar stays pinned while panel content scrolls (#31)', async ({ page })
|
||||
|
||||
test('world map shows the generated starting system and its neighbours', async ({ page }) => {
|
||||
const world = (await (await page.request.get('/api/world')).json()) as WorldState;
|
||||
// #35 — once NAVIGATION AI is researched the chart also offers two-hop systems, so the expected
|
||||
// button count depends on the save's tech state (the CI DB persists across retries).
|
||||
const techs = (await (await page.request.get('/api/tech')).json()) as { slug: string; state: string }[];
|
||||
const maxHops = techs.some((t) => t.slug === 'NAV_AI' && t.state === 'RESEARCHED') ? 2 : 1;
|
||||
|
||||
await page.goto('/');
|
||||
// Live chart title carries the turn counter.
|
||||
await expect(page.getByText(/GALACTIC CHART \/\/ JUMP ROUTES — TURN \d+/)).toBeVisible();
|
||||
// The current system is marked, and every adjacent system is a clickable chart field (role=button).
|
||||
// The current system is marked, and every in-range system is a clickable chart field (role=button).
|
||||
const current = world.systems.find((s) => s.current)!;
|
||||
await expect(page.getByText('CURRENT', { exact: true })).toBeVisible();
|
||||
const panel = page.getByRole('tabpanel');
|
||||
const adjacent = world.edges.filter(([a, b]) => a === current.id || b === current.id); // six on a fresh save
|
||||
await expect(panel.getByRole('button')).toHaveCount(adjacent.length);
|
||||
// Six on a fresh save without NAV AI; the two-hop ring joins once it is researched.
|
||||
const jumpable = world.systems.filter((s) => s.id !== current.id && shortestJumpPath(current.id, s.id, world.edges).length <= maxHops);
|
||||
await expect(panel.getByRole('button')).toHaveCount(jumpable.length);
|
||||
});
|
||||
|
||||
test('jumping to an adjacent system updates the world state and turn counter', async ({ page }) => {
|
||||
@@ -361,6 +369,70 @@ test('SKILL TREE tab researches WEAPONS SYSTEMS and unlocks the gated WEAPONS bu
|
||||
await expect(weaponsCard.getByText('LV 1')).toBeVisible();
|
||||
});
|
||||
|
||||
test('NAVIGATION AI research unlocks two-hop jumps on the world map (#35)', async ({ page }) => {
|
||||
// Research costs two resources (70% of scans drop one), so a short scan loop makes it affordable;
|
||||
// jumping keeps it going if a system exhausts. Idempotent: a retry finds it already RESEARCHED.
|
||||
let techs = (await (await page.request.get('/api/tech')).json()) as { id: number; slug: string; state: string }[];
|
||||
const navAiState = () => techs.find((t) => t.slug === 'NAV_AI')!.state;
|
||||
if (navAiState() !== 'RESEARCHED') {
|
||||
let ship = (await (await page.request.get('/api/ship')).json()) as ShipState;
|
||||
let iterations = 0;
|
||||
while (totalQty(ship.inventory, 'resource') < 2 && iterations < 40) {
|
||||
iterations++;
|
||||
const sys = (await (await page.request.get('/api/system')).json()) as SystemState;
|
||||
const unexplored = sys.planets.filter((p) => !p.explored);
|
||||
if (unexplored.length > 0) {
|
||||
expect((await page.request.post('/api/explore', { data: { planetId: unexplored[0].id } })).status()).toBe(200);
|
||||
} else {
|
||||
await jumpToFreshSystem(page); // prefer undiscovered territory — first-edge ping-pongs between exhausted systems
|
||||
}
|
||||
ship = (await (await page.request.get('/api/ship')).json()) as ShipState;
|
||||
}
|
||||
expect(totalQty(ship.inventory, 'resource')).toBeGreaterThanOrEqual(2);
|
||||
|
||||
await page.goto('/');
|
||||
// SKILL TREE tab: research NAVIGATION AI (two resources) — the card flips to RESEARCHED.
|
||||
await page.getByRole('tab', { name: 'SKILL TREE' }).click();
|
||||
const techCard = page.getByRole('heading', { name: 'NAVIGATION AI' }).locator('xpath=ancestor::div[3]');
|
||||
await expect(techCard.getByText('AVAILABLE')).toBeVisible(); // root tech — no prerequisites
|
||||
await expect(techCard.getByRole('button', { name: 'RESEARCH' })).toBeEnabled(); // resources ≥ 2
|
||||
await techCard.getByRole('button', { name: 'RESEARCH' }).click();
|
||||
await expect(techCard.getByText('RESEARCHED')).toBeVisible();
|
||||
}
|
||||
|
||||
// Pick a system exactly two hops from the current one. A completely fresh save has none (the start
|
||||
// region is only one hop deep), so jump once first — that expansion creates the two-hop territory.
|
||||
let world = (await (await page.request.get('/api/world')).json()) as WorldState;
|
||||
const findTwoHop = () => {
|
||||
const currentId = world.systems.find((s) => s.current)!.id;
|
||||
return world.systems.find((s) => shortestJumpPath(currentId, s.id, world.edges).length === 2);
|
||||
};
|
||||
let guard = 0;
|
||||
while (!findTwoHop() && guard < 5) {
|
||||
await jumpToFreshSystem(page); // +1 turn — jumping into undiscovered territory always expands the chart
|
||||
world = (await (await page.request.get('/api/world')).json()) as WorldState;
|
||||
guard++;
|
||||
}
|
||||
const target = findTwoHop()!;
|
||||
expect(target).toBeDefined();
|
||||
|
||||
await page.goto('/'); // fresh chart with NAV AI researched — two-hop fields are clickable now
|
||||
// #27 restores whatever tab a previous step persisted (SKILL TREE after the research above), so
|
||||
// activate WORLD MAP explicitly before asserting on the chart.
|
||||
await page.getByRole('tab', { name: 'WORLD MAP' }).click();
|
||||
await expect(page.getByText(/GALACTIC CHART \/\/ JUMP ROUTES — TURN \d+/)).toBeVisible();
|
||||
const panel = page.getByRole('tabpanel');
|
||||
const turnBefore = world.turn;
|
||||
|
||||
// The two-hop systems render as distinct chart fields (// JUMP ×2 sublabel) — several at once, so .first().
|
||||
await expect(panel.getByText(/(DISCOVERED|UNKNOWN) \/\/ JUMP ×2/).first()).toBeVisible();
|
||||
await panel.getByRole('button', { name: target.name.toUpperCase() }).click();
|
||||
|
||||
const after = (await (await page.request.get('/api/world')).json()) as WorldState;
|
||||
expect(after.systems.find((s) => s.id === target.id)!.current).toBe(true); // world state updated in one action
|
||||
expect(after.turn).toBe(turnBefore + 2); // the turn cost scales with hop count (#35)
|
||||
});
|
||||
|
||||
test('MISSIONS tab accepts a contract and completing it grants the reward', async ({ page }) => {
|
||||
const board = (await (await page.request.get('/api/missions')).json()) as MissionDto[];
|
||||
expect(board.filter((m) => m.state === 'AVAILABLE').length).toBeGreaterThanOrEqual(3); // the board is always topped up
|
||||
|
||||
+7
-4
@@ -6,7 +6,7 @@ import { generateStartingCrew, rollCrewMember, startingCrewRng, type CrewMember
|
||||
import { BASE_CAPACITY, BASE_LEVEL, SHIP_TYPES } from './ship-costs'
|
||||
import { checkMissionCompletion, topUpMissionBoard } from './missions'
|
||||
import { TECHS } from './tech'
|
||||
import { bodyRng, explorationRng, generatePlanets, generateRing, generateStartRegion, mulberry32, rollExploration, type FoundItem } from './world'
|
||||
import { bodyRng, explorationRng, generatePlanets, generateRing, generateStartRegion, mulberry32, reachableWithin, rollExploration, type FoundItem } from './world'
|
||||
|
||||
// Save lifecycle: auto-init on first hit, world state reads, and the jump action.
|
||||
// Single-player by design — exactly one save row ever exists, so every query below is
|
||||
@@ -217,10 +217,13 @@ export async function jumpToSystem(db: GameDb, systemId: number): Promise<WorldS
|
||||
if (current.id === target.id) throw new JumpError(409, 'Already at this system')
|
||||
|
||||
const routes = await db.db.select().from(schema.jumpRoutes)
|
||||
const adjacent = routes.some((r) => r.fromSystem === current.id && r.toSystem === target.id)
|
||||
if (!adjacent) throw new JumpError(409, `${target.name} is not reachable from ${current.name}`)
|
||||
// #35 — NAVIGATION AI extends the jump range from adjacent (1 hop) to 2 hops; a multi-hop jump
|
||||
// costs one turn per hop, so single-hop jumps keep their existing cost.
|
||||
const navAi = (await db.db.select().from(schema.tech)).some((t) => t.slug === 'NAV_AI' && t.researched)
|
||||
const hopCount = reachableWithin(routes.map((r) => [r.fromSystem, r.toSystem]), current.id, navAi ? 2 : 1).get(target.id)
|
||||
if (hopCount === undefined) throw new JumpError(409, `${target.name} is not reachable from ${current.name}`)
|
||||
|
||||
const turn = save.turn + 1
|
||||
const turn = save.turn + hopCount
|
||||
await db.db.update(schema.solarSystems).set({ isCurrent: false }).where(eq(schema.solarSystems.id, current.id))
|
||||
await db.db.update(schema.solarSystems).set({ isCurrent: true, discovered: true }).where(eq(schema.solarSystems.id, target.id))
|
||||
|
||||
|
||||
+3
-1
@@ -37,7 +37,9 @@ export const EFFECTS: Record<string, TechEffect & { description: string }> = {
|
||||
BUILD_WEAPONS: { kind: 'unlock_build', shipType: 'WEAPONS', description: 'Unlocks building the WEAPONS system' },
|
||||
REACTOR_LEVEL_CAP: { kind: 'raise_level_cap', shipType: 'REACTOR', bonus: 2, description: `Raises REACTOR max level by 2 (${MAX_LEVEL} → ${MAX_LEVEL + 2})` },
|
||||
HULL_CAPACITY_CAP: { kind: 'raise_capacity_cap', shipType: 'HULL', bonus: 3, description: `Raises HULL max capacity by 3 (${MAX_CAPACITY} → ${MAX_CAPACITY + 3})` },
|
||||
NAV_LEVEL_CAP: { kind: 'raise_level_cap', shipType: 'NAV COMPUTER', bonus: 2, description: `Raises NAV COMPUTER max level by 2 (${MAX_LEVEL} → ${MAX_LEVEL + 2})` },
|
||||
// #35 — the researched state of this tech also extends the jump range to 2 hops (enforced in
|
||||
// lib/game/save.ts, which keys off the NAV_AI slug); the description is what the SKILL TREE card shows.
|
||||
NAV_LEVEL_CAP: { kind: 'raise_level_cap', shipType: 'NAV COMPUTER', bonus: 2, description: `Raises NAV COMPUTER max level by 2 (${MAX_LEVEL} → ${MAX_LEVEL + 2}) and enables multi-system jumps (up to 2 hops in one action)` },
|
||||
WEAPONS_LEVEL_CAP: { kind: 'raise_level_cap', shipType: 'WEAPONS', bonus: 2, description: `Raises WEAPONS max level by 2 (once built)` },
|
||||
REACTOR_CAPACITY_CAP: { kind: 'raise_capacity_cap', shipType: 'REACTOR', bonus: 3, description: `Raises REACTOR max capacity by 3 (${MAX_CAPACITY} → ${MAX_CAPACITY + 3})` },
|
||||
}
|
||||
|
||||
+35
-1
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { bodyRng, explorationRng, generatePlanets, generateRing, generateStartRegion, makeName, mulberry32, rollExploration } from './world'
|
||||
import { bodyRng, explorationRng, generatePlanets, generateRing, generateStartRegion, makeName, mulberry32, reachableWithin, rollExploration } from './world'
|
||||
|
||||
describe('generateStartRegion', () => {
|
||||
const region = generateStartRegion(mulberry32(42))
|
||||
@@ -145,3 +145,37 @@ describe('rollExploration', () => {
|
||||
expect(shapes).toEqual(new Set(['rp', 'r-', '-p', '--']))
|
||||
})
|
||||
})
|
||||
|
||||
describe('reachableWithin (#35 jump range)', () => {
|
||||
// Chain 1—2—3—4 with a branch off 2: 2—5. Distances from 1: 2→1, 3/5→2, 4→3.
|
||||
const edges: [number, number][] = [[1, 2], [2, 3], [3, 4], [2, 5]]
|
||||
|
||||
it('maxHops=1 returns only direct neighbours at distance 1 (the pre-NAV-AI range)', () => {
|
||||
expect(reachableWithin(edges, 1, 1)).toEqual(new Map([[2, 1]]))
|
||||
})
|
||||
|
||||
it('maxHops=2 adds the two-hop systems and stops before three', () => {
|
||||
expect(reachableWithin(edges, 1, 2)).toEqual(new Map([ [2, 1], [3, 2], [5, 2] ]))
|
||||
})
|
||||
|
||||
it('larger maxHops keeps walking until the graph is exhausted', () => {
|
||||
expect(reachableWithin(edges, 1, 5)).toEqual(new Map([ [2, 1], [3, 2], [5, 2], [4, 3] ]))
|
||||
})
|
||||
|
||||
it('never includes the origin and handles empty/isolated input', () => {
|
||||
expect(reachableWithin(edges, 1, 3).has(1)).toBe(false)
|
||||
expect(reachableWithin([], 1, 2)).toEqual(new Map())
|
||||
expect(reachableWithin([[9, 10]], 1, 2)).toEqual(new Map())
|
||||
})
|
||||
|
||||
it('accepts double-directed route rows (the save.ts input shape) identically', () => {
|
||||
const directed: [number, number][] = [[1, 2], [2, 1], [2, 3], [3, 2]]
|
||||
expect(reachableWithin(directed, 1, 2)).toEqual(new Map([ [2, 1], [3, 2] ]))
|
||||
})
|
||||
|
||||
it('on a fresh start region every system is one hop away — two-hop targets only exist after an expansion', () => {
|
||||
const region = generateStartRegion(mulberry32(42)) // edges index into [start, ...neighbors], start = 0
|
||||
expect(reachableWithin(region.edges, 0, 1).size).toBe(region.neighbors.length)
|
||||
expect(reachableWithin(region.edges, 0, 2).size).toBe(region.neighbors.length)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -136,6 +136,36 @@ export function generateRing(
|
||||
return { systems, edges: ringEdges(systems.length) }
|
||||
}
|
||||
|
||||
// BFS over jump routes: every system within maxHops of fromId, mapped to its shortest hop count.
|
||||
// `edges` may be undirected pairs (WorldState.edges) or double-directed route rows — duplicates are
|
||||
// harmless because a visited system is never re-queued. fromId itself is not in the result.
|
||||
export function reachableWithin(edges: [number, number][], fromId: number, maxHops: number): Map<number, number> {
|
||||
const adj = new Map<number, number[]>()
|
||||
for (const [a, b] of edges) {
|
||||
if (!adj.has(a)) adj.set(a, [])
|
||||
if (!adj.has(b)) adj.set(b, [])
|
||||
adj.get(a)!.push(b)
|
||||
adj.get(b)!.push(a)
|
||||
}
|
||||
const dist = new Map<number, number>()
|
||||
const seen = new Set([fromId]) // the origin is never re-queued or reported
|
||||
let frontier = [fromId]
|
||||
for (let hop = 1; hop <= maxHops; hop++) {
|
||||
const next: number[] = []
|
||||
for (const id of frontier) {
|
||||
for (const nb of adj.get(id) ?? []) {
|
||||
if (!seen.has(nb)) {
|
||||
seen.add(nb)
|
||||
dist.set(nb, hop)
|
||||
next.push(nb)
|
||||
}
|
||||
}
|
||||
}
|
||||
frontier = next
|
||||
}
|
||||
return dist
|
||||
}
|
||||
|
||||
// --- Bodies (planets + moons) and exploration -------------------------------
|
||||
|
||||
export interface WorldMoon {
|
||||
|
||||
+4
-4
@@ -8,7 +8,7 @@ export const openApiSpec = {
|
||||
info: {
|
||||
title: 'SpaceWanderer API',
|
||||
description:
|
||||
'JSON API for SpaceWanderer — a single-player turn-based space adventure (one save, no accounts). World endpoints: read the generated world state and jump between adjacent solar systems.',
|
||||
'JSON API for SpaceWanderer — a single-player turn-based space adventure (one save, no accounts). World endpoints: read the generated world state and jump between solar systems within range (adjacent by default; two hops once NAVIGATION AI is researched).',
|
||||
// Sourced from package.json so it stays in sync with every version bump.
|
||||
version: pkg.version,
|
||||
},
|
||||
@@ -52,9 +52,9 @@ export const openApiSpec = {
|
||||
},
|
||||
'/api/jump': {
|
||||
post: {
|
||||
summary: 'Jump to an adjacent solar system',
|
||||
summary: 'Jump to a solar system within range',
|
||||
description:
|
||||
'Validates that the target is a jump route away from the current system, sets it as current (discovering it if new and generating its neighbours), increments the turn counter and writes a jump event. Returns the fresh world state.',
|
||||
'Validates that the target is within jump range of the current system — one hop away, or two hops once NAVIGATION AI is researched (#35) — sets it as current (discovering it if new and generating its neighbours), advances the turn counter by the hop count and writes a jump event. Returns the fresh world state.',
|
||||
operationId: 'jumpToSystem',
|
||||
requestBody: {
|
||||
required: true,
|
||||
@@ -90,7 +90,7 @@ export const openApiSpec = {
|
||||
},
|
||||
},
|
||||
409: {
|
||||
description: 'Target is not adjacent to the current system (or is the current system itself)',
|
||||
description: 'Target is outside jump range of the current system — more than one hop away, or more than two hops without NAVIGATION AI researched (or is the current system itself)',
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: { $ref: '#/components/schemas/Error' },
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "space-wanderer",
|
||||
"version": "0.9.9",
|
||||
"version": "0.9.11",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev -p 3000",
|
||||
|
||||
Reference in New Issue
Block a user