1
0
Fork 0
Go to file
Pabloader 33fde737ba Catprinter 2025-09-16 12:11:49 +00:00
build Fix life 2025-09-11 13:08:35 +00:00
src Catprinter 2025-09-16 12:11:49 +00:00
.clang-format Image data c api 2025-05-19 14:48:03 +00:00
.clangd Migrate to WASI 2025-06-10 07:42:00 +00:00
.gitignore Remove asmscript from build 2025-05-08 23:40:53 +03:00
README.md Upgrade to bun v1.2, remove extra dependency 2025-03-14 15:20:28 +00:00
bun.lock Catprinter 2025-09-16 12:11:49 +00:00
compile_flags.txt Compile flags 2025-06-25 13:39:22 +00:00
package.json Catprinter 2025-09-16 12:11:49 +00:00
tsconfig.json Add README, more examples and audio imports 2024-07-09 12:38:03 +00:00

README.md

TS-Games

Custom framework/build system for simple single-file TypeScript games.

Installing dependencies

bun install

Make a game

  • Create your game folder in src/games
  • Create src/games/<yourgame>/index.ts with 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 .html file without any dependencies, all assets are inlined as data-urls.

    • src/games/<yourgame>/assets/favicon.ico is 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:..." />
      
  • Import audio as HTMLAudioElement

    • WAV, MP3 & OGG
      import heal from './assets/heal.ogg';
      console.log(heal); // <audio src="data:..." />
      heal.play()
      
  • 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
    • 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
  • Import *.c/*.cpp files (compile to wasm on the fly)

    • Example: src/games/life/life.c
    • To use, clang and wasm toochain should be present in the system
      sudo apt install clang lld wabt
      
    • Supports only function exports & memory
      • EXPORT(jsName) void c_function();
    • No stdlib

Publishing

  • Make sure you have scp installed (it most certainly is)

  • Make .env file

    PUBLISH_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