@gameslate/sdk 0.0.0-stage → 0.3.0
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/LICENSE +21 -0
- package/README.md +38 -2
- package/bin/gameslate-plugin.mjs +26 -0
- package/build/build-plugin.mjs +103 -0
- package/lib/assets.d.ts +1788 -0
- package/lib/assets.js +107 -0
- package/lib/bytes.d.ts +33 -0
- package/lib/bytes.js +89 -0
- package/lib/catalogue.d.ts +1228 -0
- package/lib/catalogue.js +305 -0
- package/lib/chips.d.ts +18 -0
- package/lib/chips.js +28 -0
- package/lib/condition.d.ts +58 -0
- package/lib/condition.js +125 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.js +16 -0
- package/lib/logic.d.ts +68 -0
- package/lib/logic.js +194 -0
- package/lib/navigation.d.ts +139 -0
- package/lib/navigation.js +38 -0
- package/lib/pack.d.ts +933 -0
- package/lib/pack.js +29 -0
- package/lib/pins.d.ts +19 -0
- package/lib/pins.js +35 -0
- package/lib/plugin/contract.d.ts +111 -0
- package/lib/plugin/contract.js +1 -0
- package/lib/plugin/index.d.ts +3 -0
- package/lib/plugin/index.js +9 -0
- package/lib/plugin/sandbox-guest.d.ts +12 -0
- package/lib/plugin/sandbox-guest.js +128 -0
- package/lib/plugin/seqlock.d.ts +8 -0
- package/lib/plugin/seqlock.js +19 -0
- package/lib/plugin-manifest.d.ts +131 -0
- package/lib/plugin-manifest.js +54 -0
- package/lib/plugins-api.d.ts +445 -0
- package/lib/plugins-api.js +38 -0
- package/lib/registry.d.ts +2231 -0
- package/lib/registry.js +170 -0
- package/lib/sandbox-protocol.d.ts +1363 -0
- package/lib/sandbox-protocol.js +39 -0
- package/lib/status.d.ts +24 -0
- package/lib/status.js +75 -0
- package/lib/types.d.ts +2684 -0
- package/lib/types.js +282 -0
- package/lib/views.d.ts +204 -0
- package/lib/views.js +35 -0
- package/package.json +53 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ryan Powell
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,39 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @gameslate/sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Build plugins for **GameSlate**, a second-screen companion for PC games: a daemon on the gaming
|
|
4
|
+
PC reads the game and streams it to a web app on phones and tablets (map, inventory, missions,
|
|
5
|
+
AI hints).
|
|
6
|
+
|
|
7
|
+
A plugin teaches GameSlate one family of games. It only **decodes**: the core attaches to the game,
|
|
8
|
+
runs the plugin in a QuickJS sandbox, validates everything it returns, and owns the UI.
|
|
9
|
+
|
|
10
|
+
## What's in the package
|
|
11
|
+
|
|
12
|
+
| Import | For |
|
|
13
|
+
|---|---|
|
|
14
|
+
| `@gameslate/sdk` | Game state, catalogue (items, missions, collectibles, pins), conditions, map and asset schemas, `Bytes` |
|
|
15
|
+
| `@gameslate/sdk/plugin` | The plugin contract (`GamePlugin`, `GameMemory`, `AssetExtractor`, `PluginModule`), `seqlockSample`, and the sandbox adapters |
|
|
16
|
+
| `gameslate-plugin build` | Builds a plugin folder into what the core loads |
|
|
17
|
+
|
|
18
|
+
## A plugin folder
|
|
19
|
+
|
|
20
|
+
```text
|
|
21
|
+
manifest.json id, name, version, sdkApi, games (and where their files usually are)
|
|
22
|
+
live.ts default export: { id, packs, sources }: game data and memory readers
|
|
23
|
+
assets.ts optional, default export: { id, extractors }: maps and meshes from the player's files
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
gameslate-plugin build ./my-plugin --out ./dist/my-plugin --tested-with 2.3.0
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
`live.js` and `assets.js` run in the core's sandbox, built for a neutral platform: no Node APIs,
|
|
31
|
+
no file system, no network. Read the game through `GameMemory`, the player's files through
|
|
32
|
+
`InputFile`, and bytes with `Bytes`. Return data (states, drawings, pixels, meshes); the core
|
|
33
|
+
validates it and writes every file.
|
|
34
|
+
|
|
35
|
+
## Versions
|
|
36
|
+
|
|
37
|
+
`0.3.x` speaks plugin contract (`sdkApi`) 3. The core refuses a plugin built for another contract.
|
|
38
|
+
|
|
39
|
+
MIT licensed.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { parseArgs } from 'node:util';
|
|
4
|
+
import { buildPlugin } from '../build/build-plugin.mjs';
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
* `gameslate-plugin build <pluginDir> --out <dir> [--tested-with <coreVersion> ...]`
|
|
8
|
+
* Builds a plugin folder into what the GameSlate core loads (see build/build-plugin.mjs).
|
|
9
|
+
*/
|
|
10
|
+
const { values, positionals } = parseArgs({
|
|
11
|
+
options: { out: { type: 'string' }, 'tested-with': { type: 'string', multiple: true } },
|
|
12
|
+
allowPositionals: true,
|
|
13
|
+
});
|
|
14
|
+
const [command, dir] = positionals;
|
|
15
|
+
if (command !== 'build' || !dir || !values.out) {
|
|
16
|
+
console.error(
|
|
17
|
+
'usage: gameslate-plugin build <pluginDir> --out <dir> [--tested-with <version>]',
|
|
18
|
+
);
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
const built = await buildPlugin({
|
|
22
|
+
srcDir: path.resolve(dir),
|
|
23
|
+
outDir: path.resolve(values.out),
|
|
24
|
+
testedWith: values['tested-with'] ?? [],
|
|
25
|
+
});
|
|
26
|
+
console.log(`built ${built.id} ${built.version} -> ${values.out}`);
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import * as esbuild from 'esbuild';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
* Builds one plugin folder (manifest.json, live.ts, optionally assets.ts and extract.ts) into what
|
|
8
|
+
* the GameSlate core loads, with a manifest carrying each code file's hash:
|
|
9
|
+
* live.js live.ts's default export behind `exposeToHost`, for the core's QuickJS sandbox
|
|
10
|
+
* assets.js assets.ts's default export behind `exposeAssetsToHost`, for extraction jobs
|
|
11
|
+
* extract.mjs extract.ts, Node code the core runs unsandboxed (legacy hooks; avoid)
|
|
12
|
+
* Sandbox scripts are built for a neutral platform, so a Node API in them fails the build.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const LIVE_FILE = 'live.js';
|
|
16
|
+
const ASSETS_FILE = 'assets.js';
|
|
17
|
+
const EXTRACT_FILE = 'extract.mjs';
|
|
18
|
+
|
|
19
|
+
const hashOf = file => createHash('sha256').update(fs.readFileSync(file)).digest('hex');
|
|
20
|
+
|
|
21
|
+
/* a sandbox script: `entry`'s default export handed to the sdk's `expose` function */
|
|
22
|
+
async function buildSandboxed({ srcDir, entry, expose, outfile, alias }) {
|
|
23
|
+
await esbuild.build({
|
|
24
|
+
absWorkingDir: srcDir,
|
|
25
|
+
stdin: {
|
|
26
|
+
contents: [
|
|
27
|
+
`import plugin from './${entry}';`,
|
|
28
|
+
`import { ${expose} } from '@gameslate/sdk/plugin';`,
|
|
29
|
+
`${expose}(plugin);`,
|
|
30
|
+
].join('\n'),
|
|
31
|
+
resolveDir: srcDir,
|
|
32
|
+
sourcefile: 'sandbox-entry.ts',
|
|
33
|
+
loader: 'ts',
|
|
34
|
+
},
|
|
35
|
+
outfile,
|
|
36
|
+
bundle: true,
|
|
37
|
+
platform: 'neutral',
|
|
38
|
+
mainFields: ['module', 'main'],
|
|
39
|
+
conditions: ['import', 'default'],
|
|
40
|
+
format: 'iife',
|
|
41
|
+
target: 'es2022',
|
|
42
|
+
alias,
|
|
43
|
+
logLevel: 'warning',
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function buildNode(srcDir, entry, outfile, alias) {
|
|
48
|
+
await esbuild.build({
|
|
49
|
+
absWorkingDir: srcDir,
|
|
50
|
+
entryPoints: [path.join(srcDir, entry)],
|
|
51
|
+
outfile,
|
|
52
|
+
bundle: true,
|
|
53
|
+
platform: 'node',
|
|
54
|
+
target: 'node20',
|
|
55
|
+
format: 'esm',
|
|
56
|
+
alias,
|
|
57
|
+
banner: {
|
|
58
|
+
js: [
|
|
59
|
+
"import { createRequire as __gsCreateRequire } from 'node:module';",
|
|
60
|
+
'const require = __gsCreateRequire(import.meta.url);',
|
|
61
|
+
].join('\n'),
|
|
62
|
+
},
|
|
63
|
+
logLevel: 'warning',
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Builds `srcDir` into `outDir` (replaced). `testedWith`: the core versions it was tested with.
|
|
69
|
+
* `alias` / `nodeAlias`: esbuild aliases for the sandbox and Node builds (a monorepo pointing at
|
|
70
|
+
* sources). Returns the built manifest.
|
|
71
|
+
*/
|
|
72
|
+
export async function buildPlugin({ srcDir, outDir, testedWith, alias = {}, nodeAlias = alias }) {
|
|
73
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(srcDir, 'manifest.json'), 'utf8'));
|
|
74
|
+
fs.rmSync(outDir, { recursive: true, force: true });
|
|
75
|
+
fs.mkdirSync(outDir, { recursive: true });
|
|
76
|
+
const live = path.join(outDir, LIVE_FILE);
|
|
77
|
+
await buildSandboxed({
|
|
78
|
+
srcDir,
|
|
79
|
+
entry: 'live.ts',
|
|
80
|
+
expose: 'exposeToHost',
|
|
81
|
+
outfile: live,
|
|
82
|
+
alias,
|
|
83
|
+
});
|
|
84
|
+
const built = { ...manifest, testedWith, code: { file: LIVE_FILE, sha256: hashOf(live) } };
|
|
85
|
+
if (fs.existsSync(path.join(srcDir, 'assets.ts'))) {
|
|
86
|
+
const out = path.join(outDir, ASSETS_FILE);
|
|
87
|
+
await buildSandboxed({
|
|
88
|
+
srcDir,
|
|
89
|
+
entry: 'assets.ts',
|
|
90
|
+
expose: 'exposeAssetsToHost',
|
|
91
|
+
outfile: out,
|
|
92
|
+
alias,
|
|
93
|
+
});
|
|
94
|
+
built.assets = { file: ASSETS_FILE, sha256: hashOf(out) };
|
|
95
|
+
}
|
|
96
|
+
if (fs.existsSync(path.join(srcDir, 'extract.ts'))) {
|
|
97
|
+
const out = path.join(outDir, EXTRACT_FILE);
|
|
98
|
+
await buildNode(srcDir, 'extract.ts', out, nodeAlias);
|
|
99
|
+
built.extract = { file: EXTRACT_FILE, sha256: hashOf(out) };
|
|
100
|
+
}
|
|
101
|
+
fs.writeFileSync(path.join(outDir, 'manifest.json'), `${JSON.stringify(built, null, 4)}\n`);
|
|
102
|
+
return built;
|
|
103
|
+
}
|