Compare commits

...
10 Commits
Author SHA1 Message Date
kamilkrzywda a57c590bae Merge pull request 'v0.9.8 — pin tab bar at top while panel content scrolls (#31)' (#33) from pin-tab-bar into master
CI / build + unit + e2e (push) Successful in 2m49s
2026-09-29 12:25:01 +02:00
kamilkrzywda 1710e50b63 fix(ui): pin the OPERATIONS tab bar while panel content scrolls (#31)
CI / build + unit + e2e (pull_request) Successful in 2m47s
The TabsList is now position:sticky top:0 with a z-index above the panel
content. In wide mode it pins to the top of the OPERATIONS scroll area
(#21's center-pane scroller); in narrow mode, where the body scrolls and
there is no inner scroll container, it pins to the viewport. The existing
opaque background keeps scrolled content from showing through.
2026-09-29 10:22:14 +00:00
kamilkrzywda 1bb04d2a51 Merge pull request 'v0.9.7 — local system refreshes after jump, no page reload needed (#30)' (#32) from local-system-refresh into master
CI / build + unit + e2e (push) Successful in 3m7s
2026-09-29 12:03:41 +02:00
kamilkrzywda e27ff7015e fix(ui): refresh LOCAL SYSTEM after a jump instead of waiting for a page reload (#30)
CI / build + unit + e2e (pull_request) Successful in 2m39s
WorldMapPanel owns the world state and applied the /api/jump response
locally, so MissionControl's lifted /api/system state (LOCAL SYSTEM tab,
CARGO HOLD, SECTOR row) stayed on the previous system until a full refresh.
The panel now takes an onJumped callback that MissionControl wires to an
/api/system refetch after every successful jump.
2026-09-29 10:00:18 +00:00
kamilkrzywda e6c88b10c2 Merge pull request 'v0.9.6 — keep active tab between page refresh (#27)' (#29) from keep-active-tab into master
CI / build + unit + e2e (push) Successful in 2m46s
2026-09-29 11:43:21 +02:00
kamilkrzywda f4690bc1a2 feat(ui): keep the active operations tab across page refreshes (#27)
CI / build + unit + e2e (pull_request) Successful in 2m15s
Persist the selected tab ID to localStorage (sw-active-tab) on every change
and restore it on mount when it matches one of the seven valid tab IDs. The
Radix Tabs become controlled for this; SSR and first client render still agree
on the default, so there is no hydration mismatch.
2026-09-29 09:42:18 +00:00
kamilkrzywda 4b030716f7 Merge pull request 'v0.9.5 — fix infinite loop on name-pool exhaustion (server freeze) (#21)' (#26) from ui-layout-fix into master
CI / build + unit + e2e (push) Successful in 2m54s
2026-09-29 11:22:07 +02:00
kamilkrzywda 06f8a28e96 fix(game): numbered name fallback when pool exhausted — server no longer freezes past 128 systems
CI / build + unit + e2e (pull_request) Successful in 2m38s
Production freeze reported after the v0.9.3 (#21) deploy: every API route
hung and all panels stayed at LOADING. Root cause was not the #21 layout
(verified healthy across all 7 tabs/viewports) but makeName's unbounded
rejection loop over a finite 16x8=128 system-name pool — once a save grew
past ~128 systems, any jump into an undiscovered system spun forever on
Node's single thread (sql.js is synchronous), blocking the whole process.

makeName and makeCrewName now fall back to numbered variants ('Kepler Drift 2')
once their pools are exhausted, so they always terminate.
2026-09-29 09:18:00 +00:00
kamilkrzywda 36ff412f0b Merge pull request 'v0.9.4 — top bar shows app version instead of ◄ SHIP (#23)' (#25) from topbar-version into master
CI / build + unit + e2e (push) Successful in 3m12s
2026-09-29 10:33:19 +02:00
kamilkrzywda c35edc60d0 feat(ui): top bar shows app version instead of ◄ SHIP label (#23)
CI / build + unit + e2e (pull_request) Successful in 2m44s
2026-09-29 08:30:35 +00:00
9 changed files with 192 additions and 18 deletions
+21
View File
@@ -1,5 +1,26 @@
# Changelog # Changelog
## v0.9.8 — 2026-09-29 10:20
- The OPERATIONS tab bar now stays pinned while its content scrolls (#31): the TabsList is `position: sticky; top: 0` with a z-index above the panel content, so it pins to the top of the OPERATIONS scroll area in wide mode (where only the center pane scrolls, #21) and to the viewport when the body scrolls in narrow mode. Its existing opaque background (`--surface-raised`) keeps scrolled content from showing through; no layout restructure needed — #21 behavior is untouched.
- e2e: new smoke spec — shrink the viewport so WORLD MAP's fixed-height chart overflows the pane, scroll the panel to the bottom (asserting a real offset), and check the tablist's bounding box hasn't moved.
## v0.9.7 — 2026-09-29 09:59
- LOCAL SYSTEM no longer shows the previous system after a jump (#30): WorldMapPanel owns the world state and applied the `/api/jump` response locally, so MissionControl's lifted `/api/system` state (which drives the LOCAL SYSTEM tab, CARGO HOLD and the SECTOR row) went stale until a page refresh. The panel now takes an `onJumped` callback that MissionControl wires to a `/api/system` refetch after every successful jump — same failure policy as the mount fetch (keep old state on error).
- e2e: new smoke spec — click-to-jump on WORLD MAP, wait for the chart's turn counter to update, switch to LOCAL SYSTEM and assert its header shows the NEW current system from `/api/world` (no `page.reload()` workaround; one jump per run/retry, same pattern as the existing jump test).
## v0.9.6 — 2026-09-29 09:41
- The active operations tab now survives a page refresh (#27): the selected tab ID is persisted to `localStorage` (`sw-active-tab`) on every change and restored on mount when it matches one of the seven valid tab IDs (unknown/stale values fall back to WORLD MAP). The Radix Tabs are controlled for this; SSR and first client render still agree on the default, so there is no hydration mismatch.
- e2e: new smoke spec — click CREW, reload, assert `aria-selected=true` again (fresh context per run/retry, no API state touched, idempotent).
## v0.9.5 — 2026-09-29 09:13
- Fixed the production freeze reported after the v0.9.3 (#21) deploy ("entire UI system is now fucked"). Root cause was NOT the #21 layout change (verified healthy across all 7 tabs and multiple viewports — no clipping, middle pane scrolls internally, side panes fixed): it was world name generation. `makeName` draws from a finite pool of 16×8=128 system names with an unbounded rejection loop, so once a save grew past ~128 systems (turns of play / e2e jump loops), any jump into an undiscovered system spun forever on Node's single thread — sql.js runs synchronously, so the whole process blocked and EVERY API route hung, leaving all panels stuck at LOADING.
- `makeName` (lib/game/world.ts) now falls back to numbered variants (`Kepler Drift 2`) once the pool is exhausted, so it always terminates; `makeCrewName` (lib/game/crew.ts) gets the same guard — the roster has no cap and its 16×22=352 pool would eventually exhaust too.
- Tests: unit — both name generators terminate with unique numbered names after full pool exhaustion (80 tests green, was 78); e2e unchanged — no spec depends on the old behavior and a fresh CI stack never approaches 128 systems.
## v0.9.4 — 2026-09-29 08:29
- Top bar (#23): the `◄ SHIP` label in the mission control header is replaced with the app version number (e.g. `v0.9.4`). The header reads it from `package.json` via the same `@/package.json` import that `/api/version` and the OpenAPI spec use, so there is a single source of truth — no second hardcoded copy.
- e2e: no spec changes needed — no spec asserted on the old `◄ SHIP` label (the landing-page test only checks the SpaceWanderer heading). All 15 specs compile unchanged.
## v0.9.3 — 2026-09-29 08:20 ## v0.9.3 — 2026-09-29 08:20
- Layout (#21): only the middle column scrolls now — the app is pinned to the viewport (`height: 100vh` + `overflow: hidden` on the root in wide mode) so body-level scrolling no longer moves the side panes. Left/right columns keep their existing `overflow-y: auto`, so any overflowing content (e.g. a long planet list) scrolls inside its own track instead. - Layout (#21): only the middle column scrolls now — the app is pinned to the viewport (`height: 100vh` + `overflow: hidden` on the root in wide mode) so body-level scrolling no longer moves the side panes. Left/right columns keep their existing `overflow-y: auto`, so any overflowing content (e.g. a long planet list) scrolls inside its own track instead.
- Added `min-height: 0` to the BODY wrapper and the 3-column grid — flex/grid items default to a content-based minimum size, which is what let the page grow past the viewport before. - Added `min-height: 0` to the BODY wrapper and the 3-column grid — flex/grid items default to a content-based minimum size, which is what let the page grow past the viewport before.
+42 -5
View File
@@ -1,6 +1,6 @@
'use client' 'use client'
import { useEffect, useState } from 'react' import { useCallback, useEffect, useState } from 'react'
import { Badge } from '@/components/ui/badge' import { Badge } from '@/components/ui/badge'
import { Panel, PanelContent, PanelHeader, PanelTitle } from '@/components/ui/panel' import { Panel, PanelContent, PanelHeader, PanelTitle } from '@/components/ui/panel'
import { Progress } from '@/components/ui/progress' import { Progress } from '@/components/ui/progress'
@@ -18,6 +18,7 @@ import { CREW_CAPACITY } from '@/lib/game/ship-costs'
import type { CrewDto, SystemState } from '@/lib/game/save' import type { CrewDto, SystemState } from '@/lib/game/save'
import type { ShipState } from '@/lib/game/ship' import type { ShipState } from '@/lib/game/ship'
import type { TechDto } from '@/lib/game/tech' import type { TechDto } from '@/lib/game/tech'
import pkg from '@/package.json'
// Interface base: layout + visual treatment rebuilt from the scificn-ui Mission Control // Interface base: layout + visual treatment rebuilt from the scificn-ui Mission Control
// showcase (src/app/_pages/showcase/mission-control-content.tsx in baxy5/scificn-ui). All seven // showcase (src/app/_pages/showcase/mission-control-content.tsx in baxy5/scificn-ui). All seven
@@ -37,6 +38,11 @@ function useNarrow(threshold = 900): boolean {
return narrow return narrow
} }
// Must match the TabsTrigger values in the render below — used to validate the tab persisted for
// #27 (an unknown stored value falls back to the default).
const TAB_IDS = ['world-map', 'local-system', 'crew', 'ship-systems', 'skill-tree', 'missions', 'event-log']
const ACTIVE_TAB_KEY = 'sw-active-tab'
export function MissionControl() { export function MissionControl() {
const narrow = useNarrow() const narrow = useNarrow()
const [tick, setTick] = useState(0) const [tick, setTick] = useState(0)
@@ -48,6 +54,9 @@ export function MissionControl() {
const [system, setSystem] = useState<SystemState | null>(null) const [system, setSystem] = useState<SystemState | null>(null)
const [techs, setTechs] = useState<TechDto[] | null>(null) const [techs, setTechs] = useState<TechDto[] | null>(null)
const [crewCount, setCrewCount] = useState<number | null>(null) const [crewCount, setCrewCount] = useState<number | null>(null)
// #27 — the active tab survives a page refresh. Restored from localStorage on mount; null until
// then so SSR and the first client render agree on the default tab (no hydration mismatch).
const [activeTab, setActiveTab] = useState<string | null>(null)
useEffect(() => { useEffect(() => {
let cancelled = false let cancelled = false
@@ -97,6 +106,25 @@ export function MissionControl() {
return () => clearInterval(id) return () => clearInterval(id)
}, []) }, [])
// #27 — restore the persisted tab once on mount (validated against TAB_IDS).
useEffect(() => {
const stored = window.localStorage.getItem(ACTIVE_TAB_KEY)
if (stored && TAB_IDS.includes(stored)) setActiveTab(stored)
}, [])
// #30 — re-fetch /api/system after a jump: WorldMapPanel owns the world state, so without this
// the lifted system state stays on the previous system until a page refresh. Same failure
// policy as the mount fetch — keep the old state on error.
const refreshSystem = useCallback(() => {
fetch('/api/system')
.then(async (res) => {
if (!res.ok) throw new Error(`HTTP ${res.status}`)
return (await res.json()) as SystemState
})
.then((s) => setSystem(s))
.catch(() => {})
}, [])
const timeStr = new Date().toLocaleTimeString('en-GB', { hour12: false }) const timeStr = new Date().toLocaleTimeString('en-GB', { hour12: false })
// Slugs of the researched techs — drives the effective caps + build gates in the SHIP SYSTEMS // Slugs of the researched techs — drives the effective caps + build gates in the SHIP SYSTEMS
@@ -141,7 +169,7 @@ export function MissionControl() {
flexShrink: 0, flexShrink: 0,
}} }}
> >
◄ SHIP v{pkg.version}
</span> </span>
<span style={{ color: 'var(--border)', flexShrink: 0 }}>│</span> <span style={{ color: 'var(--border)', flexShrink: 0 }}>│</span>
@@ -355,12 +383,21 @@ export function MissionControl() {
</PanelHeader> </PanelHeader>
<PanelContent style={{ padding: 0, flex: 1, minHeight: 0, overflowY: 'auto' }}> <PanelContent style={{ padding: 0, flex: 1, minHeight: 0, overflowY: 'auto' }}>
<Tabs defaultValue="world-map"> <Tabs
value={activeTab ?? 'world-map'}
onValueChange={(v) => {
setActiveTab(v)
window.localStorage.setItem(ACTIVE_TAB_KEY, v) // #27 — keep the tab across refreshes
}}
>
<TabsList <TabsList
style={{ style={{
padding: '0 1rem', padding: '0 1rem',
background: 'var(--surface-raised)', background: 'var(--surface-raised)', // opaque — content scrolls under it (#31)
overflowX: 'auto', overflowX: 'auto',
position: 'sticky', // #31 — pinned in both modes: to the top of the OPERATIONS
top: 0, // scroll area (wide) and to the viewport when the body scrolls (narrow)
zIndex: 1,
}} }}
> >
<TabsTrigger value="world-map">WORLD MAP</TabsTrigger> <TabsTrigger value="world-map">WORLD MAP</TabsTrigger>
@@ -374,7 +411,7 @@ export function MissionControl() {
{/* WORLD MAP TAB — live data from /api/world */} {/* WORLD MAP TAB — live data from /api/world */}
<TabsContent value="world-map" style={{ margin: 0, padding: '1rem' }}> <TabsContent value="world-map" style={{ margin: 0, padding: '1rem' }}>
<WorldMapPanel height={380} /> <WorldMapPanel height={380} onJumped={refreshSystem} />
</TabsContent> </TabsContent>
{/* LOCAL SYSTEM TAB — live data (state owned by MissionControl; scans report up) */} {/* LOCAL SYSTEM TAB — live data (state owned by MissionControl; scans report up) */}
+4 -2
View File
@@ -11,9 +11,10 @@ import type { WorldState } from '@/lib/game/save'
interface WorldMapPanelProps { interface WorldMapPanelProps {
height?: number height?: number
onJumped?: () => void // #30 — let the parent refresh /api/system after a successful jump
} }
export function WorldMapPanel({ height = 380 }: WorldMapPanelProps) { export function WorldMapPanel({ height = 380, onJumped }: WorldMapPanelProps) {
const [world, setWorld] = useState<WorldState | null>(null) const [world, setWorld] = useState<WorldState | null>(null)
const [error, setError] = useState<string | null>(null) const [error, setError] = useState<string | null>(null)
const [jumpingId, setJumpingId] = useState<number | null>(null) const [jumpingId, setJumpingId] = useState<number | null>(null)
@@ -47,12 +48,13 @@ export function WorldMapPanel({ height = 380 }: WorldMapPanelProps) {
const body = (await res.json()) as WorldState & { error?: string } const body = (await res.json()) as WorldState & { error?: string }
if (!res.ok) throw new Error(body.error ?? `HTTP ${res.status}`) if (!res.ok) throw new Error(body.error ?? `HTTP ${res.status}`)
setWorld(body) // fresh state straight from the response — no refetch needed setWorld(body) // fresh state straight from the response — no refetch needed
onJumped?.() // #30 — parent re-fetches /api/system (LOCAL SYSTEM + CARGO HOLD mirror it)
} catch (err: unknown) { } catch (err: unknown) {
setError(err instanceof Error ? err.message : String(err)) setError(err instanceof Error ? err.message : String(err))
} finally { } finally {
setJumpingId(null) setJumpingId(null)
} }
}, []) }, [onJumped])
if (error && !world) { if (error && !world) {
return ( return (
+66
View File
@@ -70,6 +70,48 @@ test('tabs switch panels client-side (event log terminal)', async ({ page }) =>
await expect(page.getByText(/T\d+ \/\/ /).first()).toBeVisible(); await expect(page.getByText(/T\d+ \/\/ /).first()).toBeVisible();
}); });
test('active tab survives a page reload (#27)', async ({ page }) => {
await page.goto('/');
// Fresh context → nothing stored yet, so CREW starts unselected (the default is WORLD MAP).
await expect(page.getByRole('tab', { name: 'CREW' })).toHaveAttribute('aria-selected', 'false');
await page.getByRole('tab', { name: 'CREW' }).click();
await expect(page.getByRole('tab', { name: 'CREW' })).toHaveAttribute('aria-selected', 'true');
await page.reload();
// The tab is restored from localStorage on mount — no API state involved, so this holds across retries.
await expect(page.getByRole('tab', { name: 'CREW' })).toHaveAttribute('aria-selected', 'true');
});
test('tab bar stays pinned while panel content scrolls (#31)', async ({ page }) => {
await page.goto('/');
// 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();
const tablist = page.getByRole('tablist');
await expect(tablist).toBeVisible();
const before = await tablist.boundingBox();
expect(before).not.toBeNull();
// Scroll the nearest scroll container above the tab list all the way down.
const scrolled = await page.evaluate(() => {
let el = document.querySelector('[role="tablist"]')?.parentElement ?? null;
while (el && !['auto', 'scroll'].includes(getComputedStyle(el).overflowY)) el = el.parentElement;
if (!el) throw new Error('no scroll container above the tab list');
el.scrollTop = el.scrollHeight;
return el.scrollTop;
});
expect(scrolled).toBeGreaterThan(50); // content really overflowed — guards against a vacuous pass
await expect(tablist).toBeVisible();
const after = await tablist.boundingBox();
expect(after).not.toBeNull();
// Pinned: the tab bar's viewport position is unchanged even though the content scrolled away (#31).
expect(Math.abs(after!.y - before!.y)).toBeLessThan(2);
});
test('world map shows the generated starting system and its neighbours', 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; const world = (await (await page.request.get('/api/world')).json()) as WorldState;
@@ -100,6 +142,30 @@ test('jumping to an adjacent system updates the world state and turn counter', a
expect(after.systems.find((s) => s.current)?.id).toBe(targetId); expect(after.systems.find((s) => s.current)?.id).toBe(targetId);
}); });
test('local system shows the new current system after a jump, without a page reload (#30)', async ({ page }) => {
const before = (await (await page.request.get('/api/world')).json()) as WorldState;
const currentId = before.systems.find((s) => s.current)!.id;
const edge = before.edges.find(([a, b]) => a === currentId || b === currentId)!;
const targetId = edge[0] === currentId ? edge[1] : edge[0];
const targetName = before.systems.find((s) => s.id === targetId)!.name;
await page.goto('/');
// Jump through the UI: click the target's chart field on WORLD MAP (the default tab).
await page.getByRole('tabpanel').getByRole('button', { name: targetName.toUpperCase(), exact: true }).click();
// Wait until the jump response is applied to the chart — server state is committed by then, so
// the /api/world read below can't race the in-flight POST.
await expect(page.getByText(`GALACTIC CHART // JUMP ROUTES — TURN ${before.turn + 1}`)).toBeVisible();
const after = (await (await page.request.get('/api/world')).json()) as WorldState;
const newCurrent = after.systems.find((s) => s.current)!;
expect(newCurrent.id).toBe(targetId); // the jump landed where we aimed
// Switch to LOCAL SYSTEM — it must show the NEW current system without a page reload (#30).
await page.getByRole('tab', { name: 'LOCAL SYSTEM' }).click();
await expect(page.getByText(`EXPLORABLE WORLDS // ${newCurrent.name.toUpperCase()} — TURN ${after.turn}`)).toBeVisible();
});
test('local system shows the current system bodies with staggered moons and explore buttons', async ({ page }) => { test('local system shows the current system bodies with staggered moons and explore buttons', async ({ page }) => {
const sys = (await (await page.request.get('/api/system')).json()) as SystemState; const sys = (await (await page.request.get('/api/system')).json()) as SystemState;
+13
View File
@@ -71,4 +71,17 @@ describe('makeCrewName', () => {
for (let i = 0; i < 40; i++) makeCrewName(rng, taken) for (let i = 0; i < 40; i++) makeCrewName(rng, taken)
expect(taken.size).toBe(40) expect(taken.size).toBe(40)
}) })
it('terminates with numbered variants once all 352 base names are taken', () => {
const rng = startingCrewRng('7')
const taken = new Set<string>()
for (let i = 0; i < 352; i++) makeCrewName(rng, taken) // exhaust the whole pool
expect(taken.size).toBe(352)
const a = makeCrewName(rng, taken) // must return instead of spinning forever
const b = makeCrewName(rng, taken)
expect(a).not.toBe(b)
expect(taken.has(a)).toBe(true)
expect(taken.has(b)).toBe(true)
})
}) })
+12 -2
View File
@@ -49,16 +49,26 @@ function pick<T>(rng: () => number, arr: T[]): T {
} }
// A name unique against `taken` (the current roster), claimed into the set on success. // A name unique against `taken` (the current roster), claimed into the set on success.
// 16×22 = 352 combinations — a roster realistically never approaches that size. // The pool is finite (16×22=352) and the roster has no cap, so — like makeName — fall back to
// numbered variants once every base is taken instead of spinning forever.
export function makeCrewName(rng: () => number, taken: Set<string>): string { export function makeCrewName(rng: () => number, taken: Set<string>): string {
for (;;) { for (;;) {
const name = `${title(pick(rng, FIRST_NAMES))} ${pick(rng, LAST_NAMES)}` const base = `${title(pick(rng, FIRST_NAMES))} ${pick(rng, LAST_NAMES)}`
if (!taken.has(base)) {
taken.add(base)
return base
}
if (taken.size >= FIRST_NAMES.length * LAST_NAMES.length) {
for (let n = 2; ; n++) {
const name = `${base} ${n}`
if (!taken.has(name)) { if (!taken.has(name)) {
taken.add(name) taken.add(name)
return name return name
} }
} }
} }
}
}
// The crew a new game starts with: 2–3 members, unique names and roles (roles are drawn // The crew a new game starts with: 2–3 members, unique names and roles (roles are drawn
// without replacement). Pure — the caller derives the rng from the save seed. // without replacement). Pure — the caller derives the rng from the save seed.
+13
View File
@@ -76,6 +76,19 @@ describe('generateRing (expansion)', () => {
for (let i = 0; i < 40; i++) makeName(rng, taken) for (let i = 0; i < 40; i++) makeName(rng, taken)
expect(taken.size).toBe(40) expect(taken.size).toBe(40)
}) })
it('terminates with numbered variants once all 128 base names are taken', () => {
const rng = mulberry32(9)
const taken = new Set<string>()
for (let i = 0; i < 128; i++) makeName(rng, taken) // exhaust the whole pool
expect(taken.size).toBe(128)
const a = makeName(rng, taken) // must return instead of spinning forever
const b = makeName(rng, taken)
expect(a).not.toBe(b)
expect(taken.has(a)).toBe(true)
expect(taken.has(b)).toBe(true)
})
}) })
describe('generatePlanets', () => { describe('generatePlanets', () => {
+14 -2
View File
@@ -36,16 +36,28 @@ function title(word: string): string {
return word.charAt(0) + word.slice(1).toLowerCase() return word.charAt(0) + word.slice(1).toLowerCase()
} }
// Picks a name not in `taken` and adds it, so callers can't accidentally reuse one. // Picks a name not in `taken` and adds it, so callers can't accidentally reuse one. The base
// pool is finite (16×8=128), so once every base is taken the loop would spin forever — which
// froze the whole server on a save that had grown past 128 systems (synchronous sql.js runs on
// Node's single thread). Numbered variants keep names unique and terminate.
export function makeName(rng: () => number, taken: Set<string>): string { export function makeName(rng: () => number, taken: Set<string>): string {
for (;;) { for (;;) {
const name = `${title(FIRST[Math.floor(rng() * FIRST.length)])} ${title(SECOND[Math.floor(rng() * SECOND.length)])}` const base = `${title(FIRST[Math.floor(rng() * FIRST.length)])} ${title(SECOND[Math.floor(rng() * SECOND.length)])}`
if (!taken.has(base)) {
taken.add(base)
return base
}
if (taken.size >= FIRST.length * SECOND.length) {
for (let n = 2; ; n++) {
const name = `${base} ${n}`
if (!taken.has(name)) { if (!taken.has(name)) {
taken.add(name) taken.add(name)
return name return name
} }
} }
} }
}
}
function clamp(v: number): number { function clamp(v: number): number {
return Math.min(96, Math.max(4, v)) return Math.min(96, Math.max(4, v))
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "space-wanderer", "name": "space-wanderer",
"version": "0.9.3", "version": "0.9.8",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "next dev -p 3000", "dev": "next dev -p 3000",