From 890c161a1fd4c5f50fadd07b826412b82404478e Mon Sep 17 00:00:00 2001 From: Evan Hu Date: Fri, 27 Nov 2026 08:19:18 +0900 Subject: [PATCH] docs(readme,website): polish README and website and remove roadmap --- .github/workflows/website.yml | 7 +- CONTRIBUTING.md | 4 +- README.md | 169 +++++++++---- apps/website/plugins/content.ts | 277 +------------------- apps/website/plugins/llms.ts | 5 +- apps/website/src/components/Footer.tsx | 6 +- apps/website/src/components/Header.tsx | 4 +- apps/website/src/components/LocaleLink.tsx | 12 +- apps/website/src/components/Segments.tsx | 12 - apps/website/src/content/groups.ts | 114 ++++++++- apps/website/src/content/types.ts | 46 +--- apps/website/src/content/virtual.d.ts | 4 - apps/website/src/copy/de.ts | 31 +-- apps/website/src/copy/en.ts | 30 +-- apps/website/src/copy/es.ts | 31 +-- apps/website/src/copy/fr.ts | 31 +-- apps/website/src/copy/ja.ts | 31 +-- apps/website/src/copy/ko.ts | 31 +-- apps/website/src/copy/pages/de.ts | 47 +++- apps/website/src/copy/pages/en.ts | 47 +++- apps/website/src/copy/pages/es.ts | 47 +++- apps/website/src/copy/pages/fr.ts | 47 +++- apps/website/src/copy/pages/ja.ts | 47 +++- apps/website/src/copy/pages/ko.ts | 47 +++- apps/website/src/copy/pages/pt.ts | 47 +++- apps/website/src/copy/pages/ru.ts | 47 +++- apps/website/src/copy/pages/zh-tw.ts | 47 +++- apps/website/src/copy/pages/zh.ts | 47 +++- apps/website/src/copy/pt.ts | 31 +-- apps/website/src/copy/ru.ts | 31 +-- apps/website/src/copy/zh-tw.ts | 31 +-- apps/website/src/copy/zh.ts | 31 +-- apps/website/src/links.ts | 1 - apps/website/src/locales.test.ts | 15 +- apps/website/src/locales.ts | 2 +- apps/website/src/pages/Home.tsx | 30 ++- apps/website/src/pages/Roadmap.tsx | 164 ------------ apps/website/src/routes/$lang/roadmap.tsx | 8 - apps/website/src/routes/roadmap.tsx | 7 - apps/website/src/styles.css | 280 ++++++--------------- docs/en/index.md | 14 +- docs/zh/index.md | 14 +- 42 files changed, 725 insertions(+), 1249 deletions(-) delete mode 100644 apps/website/src/components/Segments.tsx delete mode 100644 apps/website/src/pages/Roadmap.tsx delete mode 100644 apps/website/src/routes/$lang/roadmap.tsx delete mode 100644 apps/website/src/routes/roadmap.tsx diff --git a/.github/workflows/website.yml b/.github/workflows/website.yml index 1cacfa89a..28661e819 100644 --- a/.github/workflows/website.yml +++ b/.github/workflows/website.yml @@ -1,6 +1,6 @@ name: Website -# Builds the site in apps/website, every page prerendered to static HTML, with the playground's web builds of the examples and the API reference generated from packages/game's Go doc comments, and deploys it to GitHub Pages. It builds again as this repository's issues change, so the roadmap follows them, and hourly for the NSGo issues under nsgo-dev/nsgo#1047, whose changes cannot trigger a workflow here. +# Builds the site in apps/website, every page prerendered to static HTML, with the playground's web builds of the examples and the API reference generated from packages/game's Go doc comments, and deploys it to GitHub Pages. on: push: branches: @@ -24,10 +24,6 @@ on: - "package.json" - "bun.lock" - ".github/workflows/website.yml" - issues: - types: [opened, edited, closed, reopened, deleted, transferred] - schedule: - - cron: "17 * * * *" workflow_dispatch: permissions: @@ -76,7 +72,6 @@ jobs: env: BASE_PATH: ${{ steps.pages.outputs.base_path }} SITE_ORIGIN: ${{ steps.pages.outputs.origin }} - GITHUB_TOKEN: ${{ github.token }} run: bun run build - name: Upload the Pages artifact if: github.event_name != 'pull_request' diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 45fc9a8fb..9058d297a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,6 @@ # Contributing -Contributions are welcome: bug fixes, new packages from the [roadmap](https://game.nsgo.dev/roadmap/), examples, documentation, and website improvements. +Contributions are welcome: bug fixes, new packages, examples, documentation, and website improvements. ## Repository layout @@ -74,7 +74,7 @@ The site is [TanStack Start](https://tanstack.com/start) and React, every page p ## Pull requests -1. **Keep PRs focused.** One issue or cohesive change per pull request. Before starting a large feature, open an issue or comment on the existing roadmap issue to align on the API. +1. **Keep PRs focused.** One issue or cohesive change per pull request. Before starting a large feature, open an issue to align on the API. 2. **Verify locally before opening.** Ensure `gofmt -l` outputs nothing, `go tool nsgo test ./...` passes, and `go tool nsgo check` passes for your targets. For `docs/` or `apps/website/` changes, ensure `bun run build` exits `0`. 3. **Link the issue.** Include `Fixes #` (or `Refs #` for partial work) in the pull request description. 4. **Add a changelog fragment.** A change to `packages/`, `examples/` or `template/` adds a file to `changelog.d/` instead of editing `CHANGELOG.md`, as [changelog.d/README.md](changelog.d/README.md) describes. An internal change takes the `skip-changelog` label instead. diff --git a/README.md b/README.md index 4d3382485..484365dc6 100644 --- a/README.md +++ b/README.md @@ -2,77 +2,150 @@ NSGo Game: write games in Go, ship one codebase to six platforms -A game layer for [NSGo](https://github.com/nsgo-dev/nsgo) apps, written in Go, in two stages: +

+ A pure-Go 2D & 3D game layer for NSGo — one codebase across macOS, iOS, Windows, Linux, Android and Web. +

-1. **2D**: a fixed-step loop, input actions, sprites, tilemaps, scenes and sound. A game draws into one NSGo view, a `Canvas`, a pixel buffer or a shader, and its HUD and menus stay ordinary native NSGo views on top. -2. **3D**: meshes, cameras, lights and glTF models on a GPU view NSGo adds for it ([nsgo#1059](https://github.com/nsgo-dev/nsgo/issues/1059)). +

+ Website · + Docs · + 中文文档 · + Playground · + Showcase · + API Reference · + llms.txt +

-The loop, input actions, sound and scene switching are shared by both stages. It uses only NSGo's public API, so an app that does not import it links none of it. +--- -## Status +**NSGo Game** (`github.com/nsgo-dev/game/packages/game`) adds everything you need to build and ship complete 2D and 3D games in [NSGo](https://github.com/nsgo-dev/nsgo) apps—using pure Go with zero hand-written C. -Released as `v0.1.0` (compatible with NSGo `v0.3.4` or later). Every package is either stable or experimental: stable packages break their API only in a minor release and only after a deprecation period, experimental ones may change in any minor release. The [API stability policy](docs/en/stability.md) ([中文](docs/zh/stability.md)) defines both, describes how deprecations work across releases, and lists each package's status. +Your game draws into one NSGo view (`Canvas`, pixel buffer, shader, or GPU view) while its HUD, pause screens, dialogues and settings remain ordinary native NSGo views with native typography, input methods and accessibility. Every package imports independently and uses only NSGo's public API, so an app that does not import a package links none of it. -The plan is [nsgo#1047](https://github.com/nsgo-dev/nsgo/issues/1047), and its tasks are this repository's issues. The engine-side primitives it needs (key-up and held keys, display frame times, gamepads, audio everywhere, a batched `DrawAtlas`, the GPU view) are tracked in NSGo. +## Highlights -## Layout +- **Pure Go, six platforms**: Ship one Go codebase to **macOS, iOS, Windows, Linux, Android and Web**—zero hand-written C or `cgo`. +- **Drawn game, native UI**: Render your world at 60 fps or display refresh rate in a single view while keeping scores, menus and dialogs native NSGo views. +- **2D & 3D on one shared foundation**: Fixed-step `game.Loop`, input actions, sound mixer, assets, saves and scene transitions are shared between 2D and 3D—mix both freely in one game. +- **Visual 2D & 3D scene editor**: Run `game editor` for a live viewport, scene hierarchy, inspector, transform gizmos, asset browser and Go plugin API ([Editor Guide](docs/en/editor.md)). +- **Plain-text YAML everything**: Scenes, prefabs, materials, animations, data tables, bullet patterns, quests, input maps and project settings are versioned, schema-validated YAML—clean to review in Git and easy for both humans and AI agents to edit ([File Formats](docs/en/formats.md)). +- **Built for AI coding agents**: Ships `llms.txt` / `llms-full.txt`, JSON Schemas, runtime scene inspection via [`game/mcp`](docs/en/mcp.md), deterministic [`statedump`](docs/en/statedump.md) diffs and an installable [Agent Skill](docs/en/agent-skill.md). +- **141 modular packages & 16 starter templates**: From sprites, tilemaps and rigid-body physics to glTF PBR rendering, dedicated servers and self-hosted leaderboards—every package documented and marked `stable` or `experimental` ([API Stability](docs/en/stability.md)). -A monorepo. The Go module lives in `packages/game`, and the root `go.work` uses it, so Go commands also run from the repository root. +## Quick Start -``` -game/ -├─ go.work -├─ packages/ -│ └─ game/ Go module github.com/nsgo-dev/game/packages/game -│ ├─ sprite/ -│ └─ sound/ -├─ apps/website/ the site at https://game.nsgo.dev -├─ examples/ sample games -└─ docs/ - ├─ en/ the site's docs in English - └─ zh/ the same pages in Simplified Chinese +Requires **Go 1.27+** and **NSGo `v0.3.4+`** (iOS builds require macOS and Xcode). + +```sh +# 1. Create a new game project (add -template to pick from 16 genres) +go run github.com/nsgo-dev/game/packages/game/cmd/game@latest new mygame + +# 2. Run natively with hot reload on save +cd mygame +go tool nsgo dev + +# 3. Run in the browser (WebAssembly) +go tool nsgo dev -target web ``` -Import the packages from `github.com/nsgo-dev/game/packages/game`: +Or launch the visual scene editor or install the coding-agent skill: -- `game`: the fixed-step `Loop` every package shares ([guide](docs/en/loop.md)). -- `game/sprite`: atlases, frames, animations, sprites and batches drawn into a `Canvas` ([guide](docs/en/sprite.md)). -- `game/sound`: the `Mixer`, its effects and music ([guide](docs/en/sound.md)). -- `game/input`: input actions ([#3](https://github.com/nsgo-dev/game/issues/3)). -- `game/tilemap`: tilemaps and the camera ([#5](https://github.com/nsgo-dev/game/issues/5)). -- `game/scene`: drawing layers, hit testing and scene switching ([#6](https://github.com/nsgo-dev/game/issues/6)). +```sh +# Open the visual 2D/3D scene editor +go run github.com/nsgo-dev/game/packages/game/cmd/game@latest editor -`examples/caverun` is the playable 2D platformer sample, [Cave Run](examples/caverun/README.md) ([#8](https://github.com/nsgo-dev/game/issues/8)), and `examples/lantern3d` is the interactive 3D glTF scene sample, [Lantern 3D](examples/lantern3d/README.md) ([#205](https://github.com/nsgo-dev/game/issues/205)). +# Install the Agent Skill for coding agents +bunx skills add nsgo-dev/game +``` -## Docs +See [Getting Started](docs/en/getting-started.md) ([中文](docs/zh/getting-started.md)) for the full walkthrough, or follow the 9-chapter [Tutorial: Star Catcher](docs/en/tutorial.md) ([中文](docs/zh/tutorial.md)) from an empty project to a shipped game. -- [Overview](docs/en/index.md) ([中文](docs/zh/index.md)) -- [Getting Started](docs/en/getting-started.md) ([中文](docs/zh/getting-started.md)) -- [Tutorial: Star Catcher](docs/en/tutorial.md) ([中文](docs/zh/tutorial.md)), nine chapters from an empty project to a shipped game, with each chapter's code in [`examples/tutorial`](examples/tutorial/) -- [Packages](docs/en/packages.md) ([中文](docs/zh/packages.md)): [Loop](docs/en/loop.md), [sprite](docs/en/sprite.md), [sound](docs/en/sound.md) -- [API Stability](docs/en/stability.md) ([中文](docs/zh/stability.md)) -- [Agent Skill](docs/en/agent-skill.md) ([中文](docs/zh/agent-skill.md)) — installable via `bunx skills add nsgo-dev/game` -- [3D Models from Blender](docs/en/3d-models-blender.md) ([中文](docs/zh/3d-models-blender.md)) -- [Building and Shipping](docs/en/shipping.md) ([中文](docs/zh/shipping.md)) +## Package Overview -## Targets +Import only what you need from `github.com/nsgo-dev/game/packages/game`. Browse the full interactive catalog of all 141 packages at [game.nsgo.dev/packages](https://game.nsgo.dev/packages/) or check [API Stability](docs/en/stability.md) ([中文](docs/zh/stability.md)). -macOS, iOS, Windows, Linux, Android and the web. See [Building and Shipping](docs/en/shipping.md). +| Area | Key Packages | +| --- | --- | +| **Core 2D** | `game` ([Loop](docs/en/loop.md)), `sprite`, `tilemap`, `tileshape`, `scene`, `screen`, `input`, `sound`, `text`, `assets`, `resource`, `save`, `math2d` | +| **Physics & Navigation** | `physics`, `physics/rigid` ([2D Rigid](docs/en/physics2d-rigid.md)), `physics3d`, `ai`, `ai/perception3d`, `navbake`, `navbake3d`, `vehicle` | +| **3D & Rendering** | `math3d`, `scene3d`, `render3d`, `gltf`, `scenemodel`, `anim3d`, `world3d`, `voxel` ([Blender Guide](docs/en/3d-models-blender.md)) | +| **Animation & Visual FX** | `tween`, `animclip`, `skeletal`, `particles`, `pixelfx`, `lights2d`, `effects`, `cutscene`, `quality` | +| **Gameplay & Genre Kits** | `flow`, `entities`, `platformer`, `rooms`, `worldmap`, `fog`, `procgen`, `stats`, `inventory`, `ability`, `quest`, `loot`, `cards`, `bullets`, `fighting`, `framedata`, `rts`, `rhythm`, `idle`, `vn`, `undo` | +| **UI, L10n & Accessibility** | `gameui`, `l10n`, `a11y`, `perf` | +| **Multiplayer & Online** | `net`, `server`, `accounts`, `cloudsave`, `leaderboard`, `leaderboard/selfhost`, `achievements`, `presence`, `liveops`, `modding` | +| **Editor, Tooling & Testing** | `editor`, `project`, `refs`, `debug`, `mcp`, `replay`, `statedump`, `playtest`, `gametest`, `placeholder`, `tooling/datatable`, `tooling/jsonschema`, `tooling/library` | -Consoles (Nintendo Switch, PlayStation and Xbox) are out of scope: their SDKs are under NDA and need C toolchains, and NSGo and this repository are Go only, with no hand-written C. +## Starter Templates -## Contributing +Scaffold a working, tested game in any of 16 genres with `game new -template mygame` (or `nsgo init -template github.com/nsgo-dev/game/template/`). Run `game new -list` or read [Templates](docs/en/templates.md) ([中文](docs/zh/templates.md)) for details. -See [CONTRIBUTING.md](CONTRIBUTING.md) for the repository layout, local test and cross-target check commands, coding conventions and pull request guidelines. +| 2D Templates | Description | 3D & Specialty Templates | Description | +| --- | --- | --- | --- | +| `starter` | Minimal tap-to-score 2D starter (default) | `action3d` | Third-person 3D action adventure with orbit camera & blended animations | +| `platformer2d` | Side-scrolling platformer with coyote time, jump buffer & rooms | `fps3d` | First-person 3D shooter arena with hitscan/projectile weapons & AI waves | +| `rpg2d` | Top-down RPG with branching dialogue, inventory, quests & saves | `racing3d` | 3D raycast-car circuit racer with rivals, checkpoints & best-lap ghost | +| `roguelike2d` | Seeded 5-floor turn-based roguelike with BSP caves & loot tables | `fighting2d` | 1v1 2D fighter with motion inputs, combos, frame data & CPU opponent | +| `towerdefense2d` | Upgradeable towers, YAML enemy waves, economy & lives | `cards2d` | Drag-and-drop single-player card game with YAML deck & deals | +| `rts2d` | Real-time strategy skirmish with fog of war, flow fields & control groups | `puzzle2d` | Grid sliding puzzle with YAML levels, undo/redo & star ratings | +| `shmup2d` | Vertical shooter with YAML bullet patterns, waves & 3-phase boss | `rhythm` | 4-lane rhythm game with beat maps, audio clock & latency calibration | +| `idle` | Generators, upgrades, big numbers, offline progress & prestige | `visualnovel` | Branching Yarn Spinner visual novel with backlog, saves & EN/中文 | +## Playable Examples -## Compatibility +Try the examples directly in your browser in the [Playground](https://game.nsgo.dev/playground/) or run them locally with `go tool nsgo dev ./examples/`. -| `game` | Go | NSGo | +| Example | Genre / Focus | Source | | --- | --- | --- | -| `v0.1.0` | 1.27+ | `v0.3.4` or later | +| **Cave Run** | Side-scrolling 2D platformer with native HUD & menus | [`examples/caverun`](examples/caverun/) | +| **Crypt Quest** | Top-down tile dungeon adventure across all six targets | [`examples/cryptquest`](examples/cryptquest/) | +| **Starburst** | Twin-stick arena shooter with particles, physics & input | [`examples/starburst`](examples/starburst/) | +| **Fountain** | Particle stress test maintaining 5,000 live particles | [`examples/fountain`](examples/fountain/) | +| **Slide Gem** | Touch-first 6×6 sliding match-3 with zero external assets | [`examples/slidegem`](examples/slidegem/) | +| **Lantern 3D** | 2D ↔ 3D scene switching with glTF diorama, PBR lighting & shared input/audio | [`examples/lantern3d`](examples/lantern3d/) | +| **Field Medic** | Small game shipping its own scene editor and editor plugin | [`examples/fieldmedic`](examples/fieldmedic/) | +| **Star Catcher** | Complete 9-chapter step-by-step tutorial game | [`examples/tutorial`](examples/tutorial/) | + +## Documentation + +| Topic | English | 简体中文 | +| --- | --- | --- | +| Overview & Architecture | [Overview](docs/en/index.md) | [概览](docs/zh/index.md) | +| Installation & First Game | [Getting Started](docs/en/getting-started.md) | [快速开始](docs/zh/getting-started.md) | +| 9-Chapter Walkthrough | [Tutorial: Star Catcher](docs/en/tutorial.md) | [教程:Star Catcher](docs/zh/tutorial.md) | +| Visual Scene Editor | [Scene Editor](docs/en/editor.md) | [场景编辑器](docs/zh/editor.md) | +| Plain-Text YAML Formats & Schemas | [File Formats](docs/en/formats.md) · [Schemas](docs/en/schemas.md) | [文件格式](docs/zh/formats.md) · [Schema](docs/zh/schemas.md) | +| Starter Templates & CLI | [Templates](docs/en/templates.md) · [CLI](docs/en/cli.md) | [模板](docs/zh/templates.md) · [命令行](docs/zh/cli.md) | +| 3D & Blender Pipeline | [3D Models from Blender](docs/en/3d-models-blender.md) | [从 Blender 导入 3D 模型](docs/zh/3d-models-blender.md) | +| AI Agents & MCP | [MCP](docs/en/mcp.md) · [Agent Skill](docs/en/agent-skill.md) | [MCP](docs/zh/mcp.md) · [智能体技能](docs/zh/agent-skill.md) | +| Migrating from Another Engine | [Godot](docs/en/from-godot.md) · [Unity](docs/en/from-unity.md) · [Ebitengine](docs/en/from-ebitengine.md) | [Godot](docs/zh/from-godot.md) · [Unity](docs/zh/from-unity.md) · [Ebitengine](docs/zh/from-ebitengine.md) | +| API Stability & Shipping | [API Stability](docs/en/stability.md) · [Building & Shipping](docs/en/shipping.md) | [API 稳定性](docs/zh/stability.md) · [构建与发布](docs/zh/shipping.md) | + +## Repository Layout + +```text +game/ +├─ go.work workspace linking packages/game, examples and templates +├─ packages/game/ Go module github.com/nsgo-dev/game/packages/game (141 packages + CLI) +├─ template/ 16 Go-module starter templates for game new / nsgo init +├─ examples/ 8 playable sample games and the 9-chapter tutorial +├─ library/ shared asset, plugin and template library index +├─ skills/ Agent Skills package (bunx skills add nsgo-dev/game) +├─ docs/ bilingual site documentation (en/ and zh/) +├─ apps/website/ official site at https://game.nsgo.dev (TanStack Start + React) +├─ benchmarks/ cross-engine & runtime benchmarks +└─ changelog.d/ release changelog fragments +``` + +## Targets & Compatibility + +| `game` | Go | NSGo | Targets | +| --- | --- | --- | --- | +| `v0.1.0` | `1.27+` | `v0.3.4+` | macOS, iOS, Windows, Linux, Android, Web | + +Consoles (Nintendo Switch, PlayStation and Xbox) are out of scope: their SDKs are under NDA and require C toolchains, whereas NSGo and this repository are pure Go with no hand-written C. See [Building and Shipping](docs/en/shipping.md) for signing, notarization, store packaging and cross-target `nsgo check`. -## Networking +## Contributing & License -`game/net` provides cross-target WebSocket, UDP and loopback transports with snapshot replication and deterministic lockstep/rollback helpers over `game.Loop` ([#41](https://github.com/nsgo-dev/game/issues/41)). Matchmaking, hosted backends and account services stay out of the `game` layer: games use Go's standard library or any networking package directly. Local multiplayer on one device belongs in `game/input` ([#3](https://github.com/nsgo-dev/game/issues/3), [#128](https://github.com/nsgo-dev/game/issues/128)). +Contributions are welcome—see [CONTRIBUTING.md](CONTRIBUTING.md) for local test commands, cross-target checks, coding conventions and pull request guidelines. +Licensed under the [Apache-2.0 License](LICENSE). diff --git a/apps/website/plugins/content.ts b/apps/website/plugins/content.ts index 499877bac..d2df82224 100644 --- a/apps/website/plugins/content.ts +++ b/apps/website/plugins/content.ts @@ -1,4 +1,4 @@ -// Build-time content: the docs from the repository's Markdown in each language, the API reference from the Go packages' doc comments, the home page's Go snippets, the playground's example sources, and the roadmap from GitHub's API. Each is a virtual module the routes import, so the pages carry the result and nothing is read from the repository or fetched from GitHub in the browser. +// Build-time content: the docs from the repository's Markdown in each language, the API reference from the Go packages' doc comments, the home page's Go snippets, and the playground's example sources. Each is a virtual module the routes import, so the pages carry the result and nothing is read from the repository in the browser. import { execFile } from 'node:child_process' import { readdir, readFile, stat } from 'node:fs/promises' @@ -13,18 +13,16 @@ import { codeToHtml } from 'shiki' import { type Plugin as UnifiedPlugin, unified } from 'unified' import type { Plugin } from 'vite' import { PLAYGROUND_BUILDS, PLAYGROUND_IDS, type PlaygroundId, isPlaygroundId } from '../src/content/playground.ts' -import type { ApiPackage, ApiReference, ApiSummary, DocHeading, DocPackage, DocPage, DocSummary, PackageStatus, PlaygroundExample, PlaygroundFile, PlaygroundSource, Roadmap, RoadmapGroup, RoadmapIssue, RoadmapStage, Snippet } from '../src/content/types' +import type { ApiPackage, ApiReference, ApiSummary, DocHeading, DocPackage, DocPage, DocSummary, PackageStatus, PlaygroundExample, PlaygroundFile, PlaygroundSource, Snippet } from '../src/content/types' import { LANGS, type Lang, NON_DEFAULT_LANGS } from '../src/locales.ts' import { loadSite, toTraditional } from './site.ts' const REPO = 'nsgo-dev/game' -const PLAN = { repo: 'nsgo-dev/nsgo', number: 1047 } const SNIPPETS: Snippet['id'][] = ['game', 'loop', 'sprite', 'sound'] const THEMES = { light: 'github-light', dark: 'github-dark' } as const const modules = { 'virtual:snippets': loadSnippetsModule, - 'virtual:roadmap': loadRoadmapModule, 'virtual:playground': loadPlaygroundModule, 'virtual:site': loadSiteModule, } as const @@ -50,8 +48,7 @@ interface Context { export function siteContent(): Plugin { let ctx: Context | undefined - // The client and server builds both load each module; the roadmap is fetched, and the API reference generated, once for both. - const cache = new Map>() + // The client and server builds both load the API reference; generate it once for both. let api: Promise | undefined // The docs are rendered once for the client and server builds, and again after a Markdown file changes. let docs: Promise | undefined @@ -81,7 +78,6 @@ export function siteContent(): Plugin { configureServer(server) { server.watcher.on('add', (file) => { if (!ctx || path.basename(file) !== 'nsgo.json' || !file.startsWith(path.join(ctx.publicDir, PLAYGROUND_BUILDS))) return - cache.delete('virtual:playground') for (const environment of Object.values(server.environments)) { const mod = environment.moduleGraph.getModuleById('\0virtual:playground') if (mod) environment.moduleGraph.invalidateModule(mod) @@ -163,12 +159,7 @@ export function siteContent(): Plugin { if (moduleId === 'virtual:snippets') { for (const snippet of SNIPPETS) this.addWatchFile(path.join(ctx.snippetsDir, `${snippet}.go.txt`)) } - let code = cache.get(moduleId) - if (!code || moduleId !== 'virtual:roadmap') { - code = modules[moduleId](ctx) - cache.set(moduleId, code) - } - return code + return modules[moduleId](ctx) }, } } @@ -536,263 +527,3 @@ async function loadPlaygroundSource(ctx: Context, id: PlaygroundId): Promise { - pageInfo: GqlPageInfo - nodes: T[] -} - -type GqlStage = GqlIssue & { body: string; subIssues: GqlConnection } - -// TreeNode is an issue of the plan's tree with the sub-issues read so far. -interface TreeNode { - id: string - issue: RoadmapIssue - // total is how many sub-issues GitHub says the issue has. - total: number - children: TreeNode[] -} - -async function loadRoadmapModule(): Promise { - let roadmap: Roadmap - try { - roadmap = await fetchRoadmap() - } catch (error) { - const reason = error instanceof Error ? error.message : String(error) - // A deploy must not replace the roadmap with an empty one; a local build goes on without it. - if (process.env.CI) throw new Error(`roadmap: ${reason}`) - console.warn(`[roadmap] skipped: ${reason}`) - roadmap = { status: 'unavailable', reason } - } - return `export const roadmap = ${JSON.stringify(roadmap)}` -} - -async function fetchRoadmap(): Promise { - const token = process.env.GITHUB_TOKEN - if (!token) throw new Error('GITHUB_TOKEN is not set, and GitHub’s GraphQL API needs a token') - const client = new GraphQL(token) - const [stages, gameIssues] = await Promise.all([fetchTree(client), fetchGameIssues(client)]) - const planned = new Set() - const roadmapStages = stages.map((stage, index) => { - const built = buildStage(stage, index) - for (const node of descendants(stage.node)) planned.add(issueKey(node.issue)) - return built - }) - const unplanned = gameIssues.filter((issue) => !planned.has(issueKey(issue))).sort((a, b) => a.number - b.number) - console.info(`[roadmap] ${client.requests} GraphQL requests; ${roadmapStages.map((s) => `stage ${s.number} ${s.closed}/${s.open + s.closed}`).join(', ')}; ${unplanned.length} unplanned`) - return { status: 'ok', fetchedAt: new Date().toISOString(), stages: roadmapStages, unplanned } -} - -// fetchTree reads the plan's stages with their bodies and two levels below them in one request, then each further level, a request per 100 issues that have sub-issues. -async function fetchTree(client: GraphQL): Promise<{ node: TreeNode; body: string }[]> { - const data = await client.query<{ repository: { issue: { subIssues: GqlConnection } | null } }>( - `query($owner: String!, $name: String!, $number: Int!) { - repository(owner: $owner, name: $name) { - issue(number: $number) { - subIssues(first: ${PAGE}) { pageInfo { hasNextPage endCursor } nodes { ...IssueFields body ${SUB_ISSUES} } } - } - } - } - ${ISSUE_FIELDS}`, - { owner: PLAN.repo.split('/')[0], name: PLAN.repo.split('/')[1], number: PLAN.number }, - ) - const plan = data.repository.issue - if (!plan) throw new Error(`${PLAN.repo}#${PLAN.number} was not found`) - if (plan.subIssues.pageInfo.hasNextPage) throw new Error(`${PLAN.repo}#${PLAN.number} has more than ${PAGE} stages`) - // Issues whose sub-issues are still to be read, and those with more pages of them. - let pending: TreeNode[] = [] - const more: { node: TreeNode; after: string }[] = [] - const attach = (node: TreeNode, connection: GqlConnection) => { - for (const raw of connection.nodes) { - const child = treeNode(raw) - node.children.push(child) - if (child.total > 0) pending.push(child) - } - if (connection.pageInfo.hasNextPage && connection.pageInfo.endCursor) more.push({ node, after: connection.pageInfo.endCursor }) - } - const stages = plan.subIssues.nodes.map((raw) => { - const node = treeNode(raw) - attach(node, raw.subIssues) - return { node, body: raw.body } - }) - while (pending.length || more.length) { - const level = pending - pending = [] - for (let i = 0; i < level.length; i += PAGE) { - const batch = level.slice(i, i + PAGE) - const result = await client.query<{ nodes: ({ id: string; subIssues: GqlConnection } | null)[] }>( - `query($ids: [ID!]!) { nodes(ids: $ids) { ... on Issue { id ${SUB_ISSUES} } } } - ${ISSUE_FIELDS}`, - { ids: batch.map((node) => node.id) }, - ) - result.nodes.forEach((raw, j) => { - if (raw) attach(batch[j]!, raw.subIssues) - }) - } - // An issue with more than 100 sub-issues reads the rest a page at a time. - for (const { node, after } of more.splice(0)) { - const result = await client.query<{ node: { subIssues: GqlConnection } | null }>( - `query($id: ID!, $after: String!) { node(id: $id) { ... on Issue { subIssues(first: ${PAGE}, after: $after) { pageInfo { hasNextPage endCursor } nodes { ...IssueFields } } } } } - ${ISSUE_FIELDS}`, - { id: node.id, after }, - ) - if (result.node) attach(node, result.node.subIssues) - } - } - return stages -} - -// fetchGameIssues reads every issue of the game's repository, to list those in no stage. -async function fetchGameIssues(client: GraphQL): Promise { - const [owner, name] = REPO.split('/') - const issues: RoadmapIssue[] = [] - let after: string | null = null - do { - const data: { repository: { issues: GqlConnection> } } = await client.query( - `query($owner: String!, $name: String!, $after: String) { - repository(owner: $owner, name: $name) { - issues(first: ${PAGE}, after: $after, orderBy: { field: CREATED_AT, direction: ASC }) { - pageInfo { hasNextPage endCursor } - nodes { number title state url repository { nameWithOwner } } - } - } - }`, - { owner, name, after }, - ) - const page = data.repository.issues - for (const raw of page.nodes) issues.push(toIssue(raw)) - after = page.pageInfo.hasNextPage ? page.pageInfo.endCursor : null - } while (after) - return issues -} - -function treeNode(raw: GqlIssue): TreeNode { - return { id: raw.id, issue: toIssue(raw), total: raw.subIssuesSummary.total, children: [] } -} - -function toIssue(raw: Pick): RoadmapIssue { - return { repo: raw.repository.nameWithOwner, number: raw.number, title: raw.title, state: raw.state === 'CLOSED' ? 'closed' : 'open', url: raw.url } -} - -function issueKey(issue: RoadmapIssue): string { - return `${issue.repo}#${issue.number}` -} - -// descendants lists the issues below node, depth first in GitHub's order. -function descendants(node: TreeNode): TreeNode[] { - return node.children.flatMap((child) => [child, ...descendants(child)]) -} - -const STAGE_TITLE = /^Games stage (\d+):\s*(.+)$/i - -// buildStage turns a stage's subtree into areas: each sub-issue with sub-issues of its own is an area listing everything below it, and the rest share one group after them. -function buildStage({ node, body }: { node: TreeNode; body: string }, index: number): RoadmapStage { - const match = STAGE_TITLE.exec(node.issue.title) - const title = match ? match[2]! : node.issue.title - const stage: RoadmapStage = { - number: match ? Number(match[1]) : index + 1, - title: title.charAt(0).toUpperCase() + title.slice(1), - description: stageDescription(body), - url: node.issue.url, - groups: [], - open: 0, - closed: 0, - } - const single: RoadmapGroup = { epic: null, area: '', items: [], open: 0, closed: 0 } - for (const child of node.children) { - if (child.children.length === 0) { - single.items.push({ ...child.issue, depth: 0 }) - single[child.issue.state]++ - continue - } - const group: RoadmapGroup = { epic: child.issue, area: areaName(child.issue.title), items: [], open: 0, closed: 0 } - group[child.issue.state]++ - const visit = (parent: TreeNode, depth: 0 | 1) => { - for (const item of parent.children) { - group.items.push({ ...item.issue, depth }) - group[item.issue.state]++ - visit(item, 1) - } - } - visit(child, 0) - stage.groups.push(group) - } - if (single.items.length) stage.groups.push(single) - for (const group of stage.groups) { - stage.open += group.open - stage.closed += group.closed - } - return stage -} - -// areaName is an epic's title up to its colon, without a leading tag such as "[Feature]": "Input: named actions…" is Input. -function areaName(title: string): string { - const untagged = title.replace(/^\[[^\]]*\]\s*/, '') - const colon = untagged.indexOf(':') - return colon > 0 ? untagged.slice(0, colon) : untagged -} - -// stageDescription is the first paragraph of the stage issue's Context section, or of its body, without the sentence naming the plan it belongs to. -function stageDescription(body: string): string { - const text = body.replace(/\r\n/g, '\n') - const context = /^#{1,6}\s*Context\s*\n([\s\S]*?)(?=^#{1,6}\s|$(?![\s\S]))/im.exec(text) - const paragraphs = (context ? context[1]! : text).split(/\n\s*\n/).map((p) => p.trim().replace(/\s*\n\s*/g, ' ')) - const first = paragraphs.find((p) => p && !p.startsWith('#')) ?? '' - return first - .replace(/^A stage of [\w/-]*#\d+\.\s*/i, '') - .replace(/`([^`]*)`/g, '$1') - .replace(/\*\*([^*]+)\*\*/g, '$1') -} - -class GraphQL { - requests = 0 - constructor(private readonly token: string) {} - - async query(query: string, variables: Record): Promise { - this.requests++ - const res = await fetch(GRAPHQL_URL, { - method: 'POST', - headers: { - Authorization: `Bearer ${this.token}`, - 'Content-Type': 'application/json', - 'User-Agent': 'game-website-build', - }, - body: JSON.stringify({ query, variables }), - signal: AbortSignal.timeout(30_000), - }) - if (!res.ok) { - const hint = res.status === 403 || res.status === 429 ? ' (rate limited)' : '' - throw new Error(`GraphQL answered ${res.status} ${res.statusText}${hint}`) - } - const json = (await res.json()) as { data?: T; errors?: { message: string }[] } - if (json.errors?.length) throw new Error(`GraphQL: ${json.errors.map((e) => e.message).join('; ')}`) - if (!json.data) throw new Error('GraphQL answered without data') - return json.data - } -} diff --git a/apps/website/plugins/llms.ts b/apps/website/plugins/llms.ts index 742d5f2be..3096d5f45 100644 --- a/apps/website/plugins/llms.ts +++ b/apps/website/plugins/llms.ts @@ -127,13 +127,14 @@ export function buildLlms(pages: readonly LlmsPage[], site: string): { index: st const index = `${[ '# NSGo Game', `> ${copy.site.description}`, - `NSGo Game is early and its APIs will change: read the packages' source, \`go list -m -f '{{.Dir}}' github.com/nsgo-dev/game/packages/game\`, before relying on a signature. Each page below is a page of the site; ${site}${LLMS_FULL} holds their Markdown in full.`, + `NSGo Game v0.1.0 ships both stable and experimental packages (see API Stability). Read the packages' source, \`go list -m -f '{{.Dir}}' github.com/nsgo-dev/game/packages/game\`, before relying on a signature. Each page below is a page of the site; ${site}${LLMS_FULL} holds their Markdown in full.`, ...sections, [ '## Optional', '', `- [NSGo for language models](${NSGO_LLMS_URL}): the docs of the UI engine the game layer runs on`, - `- [Roadmap](${site}roadmap/): what is planned and what is done, by stage`, + `- [API reference](${site}docs/api/): every exported identifier of the game packages`, + `- [Showcase](${site}showcase/): games, official examples and starter templates`, `- [Changelog](${CHANGELOG_URL})`, `- [Source](${GITHUB_URL})`, ].join('\n'), diff --git a/apps/website/src/components/Footer.tsx b/apps/website/src/components/Footer.tsx index ef30e369a..4930536a3 100644 --- a/apps/website/src/components/Footer.tsx +++ b/apps/website/src/components/Footer.tsx @@ -1,6 +1,6 @@ import { copies } from '../copy' import { type Lang, useLang } from '../i18n' -import { AWESOME_URL, CHANGELOG_URL, CONTRIBUTING_URL, GITHUB_URL, LICENSE_URL, LLMS_FULL, LLMS_INDEX, nsgoUrl, PLAN_URL, TELEGRAM_URL, X_URL } from '../links' +import { AWESOME_URL, CHANGELOG_URL, CONTRIBUTING_URL, GITHUB_URL, LICENSE_URL, LLMS_FULL, LLMS_INDEX, nsgoUrl, TELEGRAM_URL, X_URL } from '../links' import { Logo } from './Brand' import { LocaleLink, type LocaleTarget } from './LocaleLink' @@ -27,8 +27,8 @@ function columns(lang: Lang): { title: string; links: FooterLink[] }[] { { label: words.playground, to: { page: 'playground' } }, { label: words.examples, to: { page: 'examples' } }, { label: words.showcase, to: { page: 'showcase' } }, - { label: words.roadmap, to: { page: 'roadmap' } }, - { label: 'nsgo#1047', href: PLAN_URL }, + { label: words.editor, to: { page: 'doc', slug: 'editor' } }, + { label: words.templates, to: { page: 'doc', slug: 'templates' } }, { label: words.changelog, href: CHANGELOG_URL }, ], }, diff --git a/apps/website/src/components/Header.tsx b/apps/website/src/components/Header.tsx index b80d5f61a..9134547aa 100644 --- a/apps/website/src/components/Header.tsx +++ b/apps/website/src/components/Header.tsx @@ -28,8 +28,8 @@ export function Header() { {copy.playground} - - {copy.roadmap} + + {copy.showcase} ) diff --git a/apps/website/src/components/LocaleLink.tsx b/apps/website/src/components/LocaleLink.tsx index d700ed808..d43fdf0ec 100644 --- a/apps/website/src/components/LocaleLink.tsx +++ b/apps/website/src/components/LocaleLink.tsx @@ -2,7 +2,7 @@ import { Link } from '@tanstack/react-router' import type { MouseEventHandler, ReactNode } from 'react' import { type Lang, useLang } from '../i18n' -export type SimplePage = 'home' | 'docs' | 'api' | 'playground' | 'showcase' | 'roadmap' | 'tutorial' | 'packages' | 'examples' +export type SimplePage = 'home' | 'docs' | 'api' | 'playground' | 'showcase' | 'tutorial' | 'packages' | 'examples' export type LocaleTarget = | { page: SimplePage } @@ -119,16 +119,6 @@ export function LocaleLink(props: LocaleLinkProps) { {props.children} ) - case 'roadmap': - return lang === 'en' ? ( - - {props.children} - - ) : ( - - {props.children} - - ) case 'tutorial': return lang === 'en' ? ( diff --git a/apps/website/src/components/Segments.tsx b/apps/website/src/components/Segments.tsx deleted file mode 100644 index b31a1244c..000000000 --- a/apps/website/src/components/Segments.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import type { CSSProperties } from 'react' - -// A segmented bar, a segment per issue, filled for the closed ones. Decorative: its numbers are given in words beside it. -export function Segments({ closed, total }: { closed: number; total: number }) { - return ( -