|
|
||
|---|---|---|
| build | ||
| src | ||
| .clang-format | ||
| .clangd | ||
| .gitignore | ||
| README.md | ||
| bun.lock | ||
| compile_flags.txt | ||
| package.json | ||
| tsconfig.json | ||
README.md
TS-Games
Custom framework/build system for simple single-file TypeScript games.
Installing dependencies
- Install bun (https://bun.sh/)
bun install
Make a game
- Create your game folder in
src/games - Create
src/games/<yourgame>/index.tswith default exported function.
Running:
bun start
Navigate to http://localhost:3000 to see the list of your games.
Game rebuilds on each reload.
Building
bun run build <project>
Will create <project>.html in dist folder.
Or to select project from list:
bun run build
Features
-
Bun ♥
-
TypeScript
-
Building into single
.htmlfile without any dependencies, all assets are inlined as data-urls.src/games/<yourgame>/assets/favicon.icois used as page icon if present.
-
TSX supported with Preact, because it's lightweight.
-
Import images as
HTMLImageElement- PNG & JPG
import spritesheet from './assets/spritesheet.png'; console.log(spritesheet); // <img src="data:..." />
- PNG & JPG
-
Import audio as
HTMLAudioElement- WAV, MP3 & OGG
import heal from './assets/heal.ogg'; console.log(heal); // <audio src="data:..." /> heal.play()
- WAV, MP3 & OGG
-
Import CSS
-
Regular CSS
import "./assets/styles.css"; -
CSS modules is supported
import styles from './assets/styles.module.css'; console.log(styles.awoo); // G7sddg_awoo export default <div className={styles.root}></div>; -
Modern CSS features are transpiled
- Nested CSS
.root { display: flex; .row { display: flex; flex-direction: row; } } - Vendor prefixed if needed
- Nested CSS
-
Import fonts (see example in
src/common/assets/vga.font.css)import "./assets/lcd.font.css";
-
-
AssemblyScript support (TypeScript-like language compiled into WebAssembly)
- Example:
src/games/playground/awoo.wasm.ts - Triggered by file name
*.wasm.ts
- Example:
-
Import
*.c/*.cppfiles (compile to wasm on the fly)- Example:
src/games/life/life.c - To use,
clangand wasm toochain should be present in the systemsudo apt install clang lld wabt - Supports only function exports &
memoryEXPORT(jsName) void c_function();
- No stdlib
- Example:
Publishing
-
Make sure you have
scpinstalled (it most certainly is) -
Make
.envfilePUBLISH_LOCATION=ssh.example.com:/var/www/games/ PUBLISH_URL=https://example.com/ -
Run build & publish
bun run build <project>Or to select project from list:
bun run build