Skip to content

Commit 1b492fa

Browse files
Add TypeScript Blackholio server + client (#5140)
# Description of Changes Adding the TypeScript version of Blackholio, both the server and client side. - Mirrored the server-rust building server-ts targetting same name/accessors to have no client binding differences - Added new TypeScript client using Phaser 4 - designed to be as close to others for future tutorial - No doc updates yet # API and ABI breaking changes N/A # Expected complexity level and risk 1 - Additive only for the /demo/Blackholio # Testing - [x] Tested client against server-rust and new server-ts - [x] Server tested against new client and new bindings generation
1 parent 1b0ac07 commit 1b492fa

54 files changed

Lines changed: 3582 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

demo/Blackholio/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ You should be prompted for a username and you should be able to move around, eat
6666
Blackholio/
6767
├── client-unity/ # Unity client project
6868
├── client-unreal/ # Unreal Engine client project
69+
├── client-ts/ # Browser client using Phaser and TypeScript
6970
├── server-csharp/ # SpacetimeDB server module (C# implementation)
7071
├── server-rust/ # SpacetimeDB server module (Rust implementation)
72+
├── server-ts/ # SpacetimeDB server module (TypeScript implementation)
7173
├── DEVELOP.md # Development guidelines
7274
└── README.md # This file
7375
```
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
dist
3+
*.log
4+
5+
.DS_Store

demo/Blackholio/client-ts/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
minimum-release-age=1440
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Blackholio Phaser Client
2+
3+
Browser client for the existing Blackholio Rust SpacetimeDB module, built with
4+
TypeScript and Phaser.
5+
6+
## Requirements
7+
8+
- Node.js 18 or later
9+
- pnpm 10.16.0 or later
10+
- A locally available SpacetimeDB CLI/server
11+
12+
This is a standalone pnpm project. Its local `pnpm-workspace.yaml` prevents
13+
pnpm from selecting the repository workspace, and its local dependency
14+
configuration enforces a 1440-minute minimum release age.
15+
16+
The checked-in dependency configuration links the TypeScript SDK from this
17+
repository during development:
18+
19+
```json
20+
"spacetimedb": "link:../../../crates/bindings-typescript"
21+
```
22+
23+
When publishing this demo outside the SpacetimeDB repository, replace the local
24+
link with the current published npm package version:
25+
26+
```json
27+
"spacetimedb": "<latest-published-version>"
28+
```
29+
30+
`package.json` does not support commented dependency alternatives, so the
31+
published form is documented here rather than left as an invalid commented
32+
entry in the manifest.
33+
34+
## Run Locally
35+
36+
Start the existing Rust server using its normal development workflow, then
37+
from this directory:
38+
39+
```bash
40+
pnpm install
41+
pnpm dev
42+
```
43+
44+
To regenerate this client's checked-in TypeScript bindings without changing
45+
the server project:
46+
47+
```bash
48+
spacetime generate --lang typescript --out-dir src/module_bindings --module-path ../server-rust
49+
```
50+
51+
## Source Layout
52+
53+
The client follows the same controller boundaries as the Unity example:
54+
55+
- `GameManager.ts`: SpacetimeDB connection, subscriptions, and entity/player registries
56+
- `PlayerController.ts`: local input and owned-circle state
57+
- `EntityController.ts`, `CircleController.ts`, and `FoodController.ts`: rendered entities
58+
- `CameraController.ts`: center-of-mass following and zoom
59+
- `ui/`: username chooser, death screen, leaderboard, and browser HUD
60+
61+
The client connects to `ws://localhost:3000` and database `blackholio` by
62+
default. Override either value when starting Vite:
63+
64+
```bash
65+
VITE_SPACETIMEDB_HOST=ws://localhost:3000 \
66+
VITE_SPACETIMEDB_DB_NAME=blackholio \
67+
pnpm dev
68+
```
69+
70+
## Controls
71+
72+
- Pointer: steer
73+
- `Space`: split
74+
- `Q`: lock or unlock steering direction
75+
- `S`: self-destruct
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Blackholio - Phaser Client</title>
7+
</head>
8+
<body>
9+
<main id="app">
10+
<div id="game"></div>
11+
<header class="hud">
12+
<div class="status">Status: <strong id="status">Connecting</strong></div>
13+
<div id="mass" class="mass hidden">Mass: <strong>0</strong></div>
14+
</header>
15+
<aside id="leaderboard" class="leaderboard hidden">
16+
<h2>Leaderboard</h2>
17+
<ol></ol>
18+
</aside>
19+
<section id="join-overlay" class="overlay hidden">
20+
<form id="join-form" class="panel">
21+
<h1>Blackholio</h1>
22+
<p>Consume, grow, and become the largest black hole.</p>
23+
<label for="name-input">Player name</label>
24+
<input id="name-input" maxlength="24" autocomplete="nickname" />
25+
<button type="submit">Enter game</button>
26+
</form>
27+
</section>
28+
<section id="death-overlay" class="overlay hidden">
29+
<div class="panel">
30+
<h1>You were consumed</h1>
31+
<button id="respawn-button" type="button">Respawn</button>
32+
</div>
33+
</section>
34+
<footer class="controls">
35+
Move with the pointer. <kbd>Space</kbd> split. <kbd>Q</kbd> lock
36+
direction. <kbd>S</kbd> self-destruct.
37+
</footer>
38+
</main>
39+
<script type="module" src="/src/main.ts"></script>
40+
</body>
41+
</html>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "@clockworklabs/blackholio-client-ts",
3+
"private": true,
4+
"version": "0.0.1",
5+
"type": "module",
6+
"packageManager": "pnpm@10.16.0",
7+
"engines": {
8+
"node": ">=18",
9+
"pnpm": ">=10.16.0"
10+
},
11+
"scripts": {
12+
"dev": "vite",
13+
"build": "pnpm run typecheck && vite build",
14+
"lint": "pnpm run typecheck",
15+
"test": "vitest run",
16+
"typecheck": "tsc --noEmit",
17+
"spacetime:generate": "spacetime generate --lang typescript --out-dir src/module_bindings --module-path ../server-rust"
18+
},
19+
"dependencies": {
20+
"phaser": "4.1.0",
21+
"spacetimedb": "link:../../../crates/bindings-typescript"
22+
},
23+
"devDependencies": {
24+
"typescript": "~5.6.2",
25+
"vite": "^7.1.5",
26+
"vitest": "^3.2.4"
27+
}
28+
}

0 commit comments

Comments
 (0)