thrunium 0.0.0-stage → 1.2.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +198 -2
- package/dist/cli.mjs +1150 -0
- package/dist/thrunium-global.mjs +20 -0
- package/dist/thrunium.js +2241 -0
- package/dist/thrunium.min.js +3 -0
- package/dist/thrunium.min.js.map +7 -0
- package/dist/thrunium.mjs +2 -0
- package/dist/types/ajax.d.ts +47 -0
- package/dist/types/collider.d.ts +130 -0
- package/dist/types/elem.d.ts +241 -0
- package/dist/types/env.d.ts +78 -0
- package/dist/types/game.d.ts +702 -0
- package/dist/types/namespace.d.ts +40 -0
- package/dist/types/reference.d.ts +52 -0
- package/dist/types/sprite.d.ts +348 -0
- package/dist/types/storage-token.d.ts +20 -0
- package/dist/types/storage.d.ts +38 -0
- package/dist/types/vector.d.ts +295 -0
- package/package.json +62 -4
- package/templates/js/game.js +17 -0
- package/templates/js/game.json +1 -0
- package/templates/js/gitignore +2 -0
- package/templates/js/package.json +13 -0
- package/templates/pnpm/pnpm-workspace.yaml +4 -0
- package/templates/ts/game.json +1 -0
- package/templates/ts/game.ts +17 -0
- package/templates/ts/gitignore +2 -0
- package/templates/ts/package.json +14 -0
- package/templates/ts/tsconfig.json +12 -0
package/README.md
CHANGED
|
@@ -1,3 +1,199 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Thrunium
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The official Thrungames game engine — a single-file, dependency-free browser
|
|
4
|
+
game library.
|
|
5
|
+
|
|
6
|
+
## Usage
|
|
7
|
+
|
|
8
|
+
```html
|
|
9
|
+
<script src="https://cdn.thrungames.com/thrunium/v1.1.0/thrunium.js"></script>
|
|
10
|
+
<!-- or the minified build (with a source map): -->
|
|
11
|
+
<script src="https://cdn.thrungames.com/thrunium/v1.1.0/thrunium.min.js"></script>
|
|
12
|
+
<script>
|
|
13
|
+
var v = new THRUNIUM.Vector(10, 10);
|
|
14
|
+
</script>
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
The [CDN image](#cdn-image) serves the files at its root (`/thrunium.js`,
|
|
18
|
+
`/thrunium.min.js`). The CDN maps them under `/thrunium/v<version>/`, and
|
|
19
|
+
`https://cdn.thrungames.com/thrunium/versions.json` lists the published versions.
|
|
20
|
+
|
|
21
|
+
The engine attaches itself to the global `THRUNIUM` namespace. It has no runtime
|
|
22
|
+
dependencies. The source is TypeScript in `src/`; `npm run build` bundles it with
|
|
23
|
+
esbuild into a classic (non-module) script, `dist/thrunium.js` (readable) and
|
|
24
|
+
`dist/thrunium.min.js` plus `dist/thrunium.min.js.map` (minified). Both start
|
|
25
|
+
with a `/*! THRUNIUM v<version> | (c) Infobits ApS | MIT License */` banner and target ES2017.
|
|
26
|
+
|
|
27
|
+
> The `Storage` user-token members (`reqToken`, `userToken`, `timeout`,
|
|
28
|
+
> `loginPopup`, `accessRequested`, `_options`, `setReqToken`, `reqUserToken`,
|
|
29
|
+
> `_receiveMessage`, `request`) are work in progress: they talk to endpoints that no
|
|
30
|
+
> longer exist and will change when authentication is added.
|
|
31
|
+
|
|
32
|
+
## Package and CLI
|
|
33
|
+
|
|
34
|
+
The engine is also on npm as `thrunium` (Node 24 or newer):
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npx thrunium init my-game # new TypeScript project; add --js for JavaScript
|
|
38
|
+
cd my-game && npm run dev # init installs for you; use pnpm dev, yarn dev or bun run dev
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { Game } from 'thrunium';
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
`exports` in `package.json`:
|
|
46
|
+
|
|
47
|
+
| Import | Gives you |
|
|
48
|
+
|---|---|
|
|
49
|
+
| `thrunium` | the engine as an ES module, with types |
|
|
50
|
+
| `thrunium/thrunium.js` | the readable classic script |
|
|
51
|
+
| `thrunium/thrunium.min.js` | the minified classic script |
|
|
52
|
+
| `thrunium/package.json` | the package manifest |
|
|
53
|
+
|
|
54
|
+
Commands (`thrunium --help`, `--version`):
|
|
55
|
+
|
|
56
|
+
| Command | Options |
|
|
57
|
+
|---|---|
|
|
58
|
+
| `thrunium dev` | `--port <n>` (default 3000, tries the next 10 ports if busy), `--host <name>` (default `localhost`), `--no-open` |
|
|
59
|
+
| `thrunium build` | `--out <dir>` (default `dist`), `--engine cdn\|bundle` |
|
|
60
|
+
| `thrunium init [dir]` | `--js` (TypeScript by default), `--pm npm\|pnpm\|yarn\|bun` (default: the one that ran it, else npm), `--no-install`; the folder must be empty. Installs by default; if that fails the project is kept and the command is printed |
|
|
61
|
+
|
|
62
|
+
A project needs no `index.html`: without one, `dev` and `build` generate the page
|
|
63
|
+
from `game.json` (`entry`, else the first of `game.ts`, `game.js`, `src/game.ts`,
|
|
64
|
+
`src/game.js`; the title is `name`, else the folder name). A hand-written
|
|
65
|
+
`index.html` is used as written, and having both it and `entry` is an error.
|
|
66
|
+
`import './style.css'` from game code is bundled and linked, with `url()` fonts and
|
|
67
|
+
images; remote `@import` stays remote.
|
|
68
|
+
|
|
69
|
+
`dev` never uses the CDN. For a project with a module entry
|
|
70
|
+
(a generated page, or `<script type="module" src=...>` importing `thrunium`), `build` has two engine
|
|
71
|
+
modes. `cdn` (the default) adds a script tag for
|
|
72
|
+
`https://cdn.thrungames.com/thrunium/v<version>/thrunium.min.js` with a `sha384`
|
|
73
|
+
integrity hash, pinned to the installed version. It fails, and leaves the output
|
|
74
|
+
folder alone, if that version is not on the CDN or the CDN's file differs from
|
|
75
|
+
the installed one (for example with `npm link` or local changes). `bundle` copies
|
|
76
|
+
`thrunium.min.js` next to the game. Set `"thrunium": { "engine": "bundle" }` in
|
|
77
|
+
the game's `package.json` to make it the default; `--engine` wins. A script-tag
|
|
78
|
+
folder (no module entry) keeps its own Thrunium tag: `build` copies it unchanged,
|
|
79
|
+
without a CDN check, and `--engine bundle` is an error. The
|
|
80
|
+
`THRUNIUM_CDN_URL` environment variable replaces the CDN base URL (for tests).
|
|
81
|
+
See `docs/guides/getting-started.md` and `docs/guides/dev-and-build.md` for the full guides.
|
|
82
|
+
|
|
83
|
+
The release stages the npm package after the CDN publish succeeds, from the
|
|
84
|
+
tarball inside the scanned image. Prereleases (`1.2.0-rc.1`) go under the `next`
|
|
85
|
+
dist-tag, stable versions under `latest`. It needs the `NPM_TOKEN` Actions secret:
|
|
86
|
+
an npm granular token with "Read and write (stage only)" on `thrunium` and no
|
|
87
|
+
organization access. npm does not let CI tokens publish directly, so the version
|
|
88
|
+
goes live only when a maintainer approves it with 2FA:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
npm stage list thrunium # the id is also in the release log
|
|
92
|
+
npm stage approve <id> --otp <code>
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
It refuses to stage if `license` is missing from `package.json`.
|
|
96
|
+
|
|
97
|
+
## Development
|
|
98
|
+
|
|
99
|
+
Requires Node 24.
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
npm ci
|
|
103
|
+
npm run build # dist/thrunium.js, dist/thrunium.min.js, source map
|
|
104
|
+
npm test # typecheck + build + unit and bundle tests, 90% line coverage
|
|
105
|
+
npm run coverage # unit and bundle tests with coverage (after a build)
|
|
106
|
+
npm run test:browser # real-Chromium tests (builds first)
|
|
107
|
+
npm run test:games # smoke-tests the sibling game repos against the built engine
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
`VERSION=1.2.3 npm run build` stamps another version into the banner and
|
|
111
|
+
`THRUNIUM.version`; it defaults to `version` in `package.json` and must look like
|
|
112
|
+
`1.2.3` or `1.2.3-rc.1`.
|
|
113
|
+
|
|
114
|
+
`test:games` needs the game repositories checked out next to this one. Set
|
|
115
|
+
`GAMES_ENGINE_FILE` to point it at a different engine file (for example a 1.0.0
|
|
116
|
+
copy) to compare behavior.
|
|
117
|
+
|
|
118
|
+
Browser tests use Playwright's Chromium, or the system Chromium when
|
|
119
|
+
`CHROME_BIN` is set (as on the arm64 CI runner, where `--no-sandbox` is added
|
|
120
|
+
because it runs as root). Without `CHROME_BIN`, `test:browser` and `test:games`
|
|
121
|
+
need Playwright's Chromium installed once with `npx playwright-core install chromium`.
|
|
122
|
+
|
|
123
|
+
## Docs
|
|
124
|
+
|
|
125
|
+
`VERSION=1.2.3 npm run docs` writes the versioned docs to `dist/docs/`: guides from
|
|
126
|
+
`docs/guides/` (listed in `docs/guides.json`) and one reference page per part of the
|
|
127
|
+
`THRUNIUM` global, generated from the doc comments in `src/`. It fails if a public
|
|
128
|
+
member has no description. The release image carries them at `/usr/share/thrunium/docs`
|
|
129
|
+
(never served over HTTP) and the release publishes them to the CDN next to the JS.
|
|
130
|
+
|
|
131
|
+
## CDN image
|
|
132
|
+
|
|
133
|
+
The engine is distributed as a hardened static image serving the file over HTTP.
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
docker build --build-arg VERSION=1.1.0 -t thrunium-game-engine:dev .
|
|
137
|
+
|
|
138
|
+
docker run --read-only --tmpfs /tmp \
|
|
139
|
+
--cap-drop ALL --security-opt no-new-privileges \
|
|
140
|
+
-p 8080:8080 thrunium-game-engine:dev
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
`VERSION` is required and is stamped into the bundle. The image builds the
|
|
144
|
+
bundle in a Node 24 stage and serves only the output.
|
|
145
|
+
|
|
146
|
+
The hardening flags above are supplied by the operator and cannot be baked into
|
|
147
|
+
the image — run it this way in every environment.
|
|
148
|
+
|
|
149
|
+
| Route | Response |
|
|
150
|
+
|---|---|
|
|
151
|
+
| `GET /thrunium.js` | the engine, `Cache-Control: public, max-age=3600`, CORS `*` |
|
|
152
|
+
| `GET /thrunium.min.js` | the minified engine, same headers |
|
|
153
|
+
| `GET /thrunium.min.js.map` | its source map (`application/json`), same headers |
|
|
154
|
+
| `GET /healthz` | `200 ok` |
|
|
155
|
+
| anything else | `404` |
|
|
156
|
+
|
|
157
|
+
The container listens on **8080** as **UID 101**. It never runs as root.
|
|
158
|
+
|
|
159
|
+
## Releases
|
|
160
|
+
|
|
161
|
+
Publishing a release on Forgejo builds the image for `linux/arm64` (the
|
|
162
|
+
cluster's architecture), scans it, and pushes it to Scaleway Container
|
|
163
|
+
Registry:
|
|
164
|
+
|
|
165
|
+
```
|
|
166
|
+
rg.fr-par.scw.cloud/infobits/thrunium-game-engine:<version>
|
|
167
|
+
rg.fr-par.scw.cloud/infobits/thrunium-game-engine:latest
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
The release tag must match the `version` in `package.json`, or the workflow
|
|
171
|
+
fails before building.
|
|
172
|
+
|
|
173
|
+
It then publishes the image's files to the `infobits-thrunium-cdn` bucket, which
|
|
174
|
+
`cdn.thrungames.com` serves, so a release needs no deploy step:
|
|
175
|
+
|
|
176
|
+
| CDN path | Holds |
|
|
177
|
+
|---|---|
|
|
178
|
+
| `/thrunium/v<version>/` | that version, never changed once published |
|
|
179
|
+
| `/thrunium/v<major>/`, `/thrunium/v<major>.<minor>/` | the newest release in that range |
|
|
180
|
+
| `/thrunium/latest/` | the newest release |
|
|
181
|
+
| `/thrunium/versions.json` (also `/thrunium/`) | JSON list of versions, aliases and files |
|
|
182
|
+
|
|
183
|
+
Prereleases (`1.2.0-rc.1`) get an exact-version path but never an alias.
|
|
184
|
+
Publishing a version again is a no-op if its files are unchanged, and fails if
|
|
185
|
+
they differ. To publish an already-released version (for example, one released
|
|
186
|
+
before the bucket existed), dispatch `publish-cdn.yml` with its version:
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
fj actions dispatch publish-cdn.yml main -I version=1.1.0
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
Both workflows need the `THRUNIUM_CDN_ACCESS_KEY` and `THRUNIUM_CDN_SECRET_KEY`
|
|
193
|
+
Actions secrets.
|
|
194
|
+
|
|
195
|
+
## License
|
|
196
|
+
|
|
197
|
+
MIT, see [LICENSE](LICENSE). The names "Thrunium" and "ThrunGames" are
|
|
198
|
+
trademarks of Infobits ApS: [TRADEMARKS.md](TRADEMARKS.md) explains how you
|
|
199
|
+
can use them.
|