@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/lib/assets.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { NavGraphSchema } from './navigation.js';
|
|
3
|
+
import { LocationMetaSchema } from './registry.js';
|
|
4
|
+
/*
|
|
5
|
+
* Asset extraction (docs/plugin-architecture.md § Asset extraction). A plugin lists what it can
|
|
6
|
+
* build from the player's files and builds one asset at a time, returning data, never files:
|
|
7
|
+
* the core validates each output against these schemas, picks every file name and writes it.
|
|
8
|
+
* A floorplan is a drawing the core turns into SVG, so a plugin can't put markup in front of the
|
|
9
|
+
* browser; an image is RGBA the core encodes.
|
|
10
|
+
*/
|
|
11
|
+
/** An asset or output id: also its file name, so plain lower-case words, dots and dashes. */
|
|
12
|
+
export const AssetIdSchema = z
|
|
13
|
+
.string()
|
|
14
|
+
.regex(/^[a-z0-9][a-z0-9._-]{0,119}$/, 'asset ids are lower-case words, dots and dashes')
|
|
15
|
+
.refine(id => !id.includes('..'), 'asset ids have no ".."');
|
|
16
|
+
export const AssetDescriptorSchema = z.object({
|
|
17
|
+
id: AssetIdSchema,
|
|
18
|
+
label: z.string().min(1).max(200),
|
|
19
|
+
});
|
|
20
|
+
export const AssetListSchema = z.object({
|
|
21
|
+
assets: z.array(AssetDescriptorSchema).max(10_000),
|
|
22
|
+
/** things the plugin found but can't build (shown to the player as plain text) */
|
|
23
|
+
notes: z.array(z.string().max(500)).max(1000),
|
|
24
|
+
});
|
|
25
|
+
const Colour = z.string().regex(/^#[0-9a-fA-F]{6}$/, 'a #rrggbb colour');
|
|
26
|
+
/* path data: move/line/close commands and numbers, nothing that could become markup */
|
|
27
|
+
const PathData = z.string().regex(/^[MLHVZmlhvz0-9 .,eE+-]*$/, 'path data');
|
|
28
|
+
const Size = z.number().positive().max(100_000);
|
|
29
|
+
export const FloorplanLayerSchema = z.object({
|
|
30
|
+
/** a filled layer draws each path as its own shape; an unfilled one strokes them as one */
|
|
31
|
+
fill: Colour.optional(),
|
|
32
|
+
fillRule: z.enum(['evenodd', 'nonzero']).optional(),
|
|
33
|
+
stroke: Colour.optional(),
|
|
34
|
+
strokeWidth: z.number().positive().max(100).optional(),
|
|
35
|
+
strokeOpacity: z.number().min(0).max(1).optional(),
|
|
36
|
+
lineCap: z.enum(['round', 'butt', 'square']).optional(),
|
|
37
|
+
paths: z.array(PathData),
|
|
38
|
+
});
|
|
39
|
+
export const FloorplanDrawingSchema = z.object({
|
|
40
|
+
width: Size,
|
|
41
|
+
height: Size,
|
|
42
|
+
background: Colour,
|
|
43
|
+
/** bottom to top */
|
|
44
|
+
layers: z.array(FloorplanLayerSchema).max(100),
|
|
45
|
+
});
|
|
46
|
+
function layerToSvg(layer) {
|
|
47
|
+
if (layer.fill) {
|
|
48
|
+
const rule = layer.fillRule ? ` fill-rule="${layer.fillRule}"` : '';
|
|
49
|
+
return [
|
|
50
|
+
` <g fill="${layer.fill}"${rule} stroke="none">`,
|
|
51
|
+
...layer.paths.map(d => ` <path d="${d}"/>`),
|
|
52
|
+
' </g>',
|
|
53
|
+
];
|
|
54
|
+
}
|
|
55
|
+
if (layer.paths.length === 0)
|
|
56
|
+
return [];
|
|
57
|
+
const attrs = [
|
|
58
|
+
layer.stroke ? `stroke="${layer.stroke}"` : '',
|
|
59
|
+
layer.strokeOpacity !== undefined ? `stroke-opacity="${layer.strokeOpacity}"` : '',
|
|
60
|
+
layer.strokeWidth !== undefined ? `stroke-width="${layer.strokeWidth}"` : '',
|
|
61
|
+
layer.lineCap ? `stroke-linecap="${layer.lineCap}"` : '',
|
|
62
|
+
'fill="none"',
|
|
63
|
+
].filter(Boolean);
|
|
64
|
+
return [` <path ${attrs.join(' ')} d="${layer.paths.join('')}"/>`];
|
|
65
|
+
}
|
|
66
|
+
/** The SVG for a drawing. Every value in it has passed the schema, so it's safe to serve. */
|
|
67
|
+
export function floorplanToSvg(drawing) {
|
|
68
|
+
const { width: w, height: h } = drawing;
|
|
69
|
+
return [
|
|
70
|
+
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${w} ${h}" width="${w}" height="${h}">`,
|
|
71
|
+
` <rect x="0" y="0" width="${w}" height="${h}" fill="${drawing.background}"/>`,
|
|
72
|
+
...drawing.layers.flatMap(layerToSvg),
|
|
73
|
+
'</svg>',
|
|
74
|
+
'',
|
|
75
|
+
].join('\n');
|
|
76
|
+
}
|
|
77
|
+
/** Binary data in an output: in plugin code a Uint8Array; across the sandbox boundary, an index
|
|
78
|
+
* into the chunks the guest handed the core during that call. */
|
|
79
|
+
const BinaryRef = z.number().int().nonnegative();
|
|
80
|
+
/**
|
|
81
|
+
* One file-shaped result of building an asset; the core decides where each goes:
|
|
82
|
+
* floorplan → maps/<id>.svg location → manifest.json (locations[id])
|
|
83
|
+
* nav → navs/<id>.json mesh → meshes/<id>.bin (+ its atlas as meshes/<id>.png)
|
|
84
|
+
* image → atlases/<id>.png
|
|
85
|
+
*/
|
|
86
|
+
export const AssetOutputSchema = z.discriminatedUnion('kind', [
|
|
87
|
+
z.object({ kind: z.literal('floorplan'), id: AssetIdSchema, drawing: FloorplanDrawingSchema }),
|
|
88
|
+
z.object({ kind: z.literal('location'), id: AssetIdSchema, location: LocationMetaSchema }),
|
|
89
|
+
z.object({ kind: z.literal('nav'), id: AssetIdSchema, graph: NavGraphSchema }),
|
|
90
|
+
z.object({
|
|
91
|
+
kind: z.literal('mesh'),
|
|
92
|
+
id: AssetIdSchema,
|
|
93
|
+
/** GS3D, checked by the core */
|
|
94
|
+
data: BinaryRef,
|
|
95
|
+
/** the image output (built by this run) that textures it */
|
|
96
|
+
atlas: AssetIdSchema,
|
|
97
|
+
}),
|
|
98
|
+
z.object({
|
|
99
|
+
kind: z.literal('image'),
|
|
100
|
+
id: AssetIdSchema,
|
|
101
|
+
width: z.number().int().positive().max(16_384),
|
|
102
|
+
height: z.number().int().positive().max(16_384),
|
|
103
|
+
/** RGBA, width × height × 4 bytes */
|
|
104
|
+
pixels: BinaryRef,
|
|
105
|
+
}),
|
|
106
|
+
]);
|
|
107
|
+
export const AssetResultSchema = z.object({ outputs: z.array(AssetOutputSchema).max(1000) });
|
package/lib/bytes.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export declare class Bytes {
|
|
2
|
+
readonly data: Uint8Array;
|
|
3
|
+
private readonly view;
|
|
4
|
+
constructor(data: Uint8Array);
|
|
5
|
+
/** A copy of `length` bytes from an ArrayBuffer (e.g. one returned by a capability call). */
|
|
6
|
+
static fromArrayBuffer(buffer: ArrayBuffer): Bytes;
|
|
7
|
+
get length(): number;
|
|
8
|
+
/** A view of bytes [start, end), sharing memory, like Buffer.subarray. */
|
|
9
|
+
subarray(start?: number, end?: number): Bytes;
|
|
10
|
+
readUInt8(offset?: number): number;
|
|
11
|
+
readInt8(offset?: number): number;
|
|
12
|
+
readUInt16LE(offset?: number): number;
|
|
13
|
+
readUInt16BE(offset?: number): number;
|
|
14
|
+
readInt16LE(offset?: number): number;
|
|
15
|
+
readInt16BE(offset?: number): number;
|
|
16
|
+
readUInt32LE(offset?: number): number;
|
|
17
|
+
readUInt32BE(offset?: number): number;
|
|
18
|
+
readInt32LE(offset?: number): number;
|
|
19
|
+
readInt32BE(offset?: number): number;
|
|
20
|
+
readFloatLE(offset?: number): number;
|
|
21
|
+
readFloatBE(offset?: number): number;
|
|
22
|
+
readDoubleLE(offset?: number): number;
|
|
23
|
+
readBigUInt64LE(offset?: number): bigint;
|
|
24
|
+
readBigUInt64BE(offset?: number): bigint;
|
|
25
|
+
readBigInt64LE(offset?: number): bigint;
|
|
26
|
+
/** The first index of `byte` at or after `from`, or -1. */
|
|
27
|
+
indexOf(byte: number, from?: number): number;
|
|
28
|
+
/**
|
|
29
|
+
* Text in bytes [start, end). `latin1` maps each byte to the same code point; `ascii` also
|
|
30
|
+
* clears the high bit first, as Buffer does.
|
|
31
|
+
*/
|
|
32
|
+
toString(encoding: 'latin1' | 'ascii', start?: number, end?: number): string;
|
|
33
|
+
}
|
package/lib/bytes.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Bytes read from game memory or an input file: the read methods packs need, on a plain
|
|
3
|
+
* Uint8Array. Plugins run in a sandbox without Node, so they can't use Buffer; the method names
|
|
4
|
+
* match Buffer's so decoders read the same either way. Reads past the end throw a RangeError,
|
|
5
|
+
* as Buffer's do.
|
|
6
|
+
*/
|
|
7
|
+
export class Bytes {
|
|
8
|
+
data;
|
|
9
|
+
view;
|
|
10
|
+
constructor(data) {
|
|
11
|
+
this.data = data;
|
|
12
|
+
this.view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
13
|
+
}
|
|
14
|
+
/** A copy of `length` bytes from an ArrayBuffer (e.g. one returned by a capability call). */
|
|
15
|
+
static fromArrayBuffer(buffer) {
|
|
16
|
+
return new Bytes(new Uint8Array(buffer));
|
|
17
|
+
}
|
|
18
|
+
get length() {
|
|
19
|
+
return this.data.length;
|
|
20
|
+
}
|
|
21
|
+
/** A view of bytes [start, end), sharing memory, like Buffer.subarray. */
|
|
22
|
+
subarray(start = 0, end = this.data.length) {
|
|
23
|
+
return new Bytes(this.data.subarray(start, end));
|
|
24
|
+
}
|
|
25
|
+
readUInt8(offset = 0) {
|
|
26
|
+
return this.view.getUint8(offset);
|
|
27
|
+
}
|
|
28
|
+
readInt8(offset = 0) {
|
|
29
|
+
return this.view.getInt8(offset);
|
|
30
|
+
}
|
|
31
|
+
readUInt16LE(offset = 0) {
|
|
32
|
+
return this.view.getUint16(offset, true);
|
|
33
|
+
}
|
|
34
|
+
readUInt16BE(offset = 0) {
|
|
35
|
+
return this.view.getUint16(offset, false);
|
|
36
|
+
}
|
|
37
|
+
readInt16LE(offset = 0) {
|
|
38
|
+
return this.view.getInt16(offset, true);
|
|
39
|
+
}
|
|
40
|
+
readInt16BE(offset = 0) {
|
|
41
|
+
return this.view.getInt16(offset, false);
|
|
42
|
+
}
|
|
43
|
+
readUInt32LE(offset = 0) {
|
|
44
|
+
return this.view.getUint32(offset, true);
|
|
45
|
+
}
|
|
46
|
+
readUInt32BE(offset = 0) {
|
|
47
|
+
return this.view.getUint32(offset, false);
|
|
48
|
+
}
|
|
49
|
+
readInt32LE(offset = 0) {
|
|
50
|
+
return this.view.getInt32(offset, true);
|
|
51
|
+
}
|
|
52
|
+
readInt32BE(offset = 0) {
|
|
53
|
+
return this.view.getInt32(offset, false);
|
|
54
|
+
}
|
|
55
|
+
readFloatLE(offset = 0) {
|
|
56
|
+
return this.view.getFloat32(offset, true);
|
|
57
|
+
}
|
|
58
|
+
readFloatBE(offset = 0) {
|
|
59
|
+
return this.view.getFloat32(offset, false);
|
|
60
|
+
}
|
|
61
|
+
readDoubleLE(offset = 0) {
|
|
62
|
+
return this.view.getFloat64(offset, true);
|
|
63
|
+
}
|
|
64
|
+
readBigUInt64LE(offset = 0) {
|
|
65
|
+
return this.view.getBigUint64(offset, true);
|
|
66
|
+
}
|
|
67
|
+
readBigUInt64BE(offset = 0) {
|
|
68
|
+
return this.view.getBigUint64(offset, false);
|
|
69
|
+
}
|
|
70
|
+
readBigInt64LE(offset = 0) {
|
|
71
|
+
return this.view.getBigInt64(offset, true);
|
|
72
|
+
}
|
|
73
|
+
/** The first index of `byte` at or after `from`, or -1. */
|
|
74
|
+
indexOf(byte, from = 0) {
|
|
75
|
+
return this.data.indexOf(byte, from);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Text in bytes [start, end). `latin1` maps each byte to the same code point; `ascii` also
|
|
79
|
+
* clears the high bit first, as Buffer does.
|
|
80
|
+
*/
|
|
81
|
+
toString(encoding, start = 0, end = this.data.length) {
|
|
82
|
+
const mask = encoding === 'ascii' ? 0x7f : 0xff;
|
|
83
|
+
let out = '';
|
|
84
|
+
for (let i = Math.max(0, start); i < Math.min(end, this.data.length); i++) {
|
|
85
|
+
out += String.fromCharCode((this.data[i] ?? 0) & mask);
|
|
86
|
+
}
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
89
|
+
}
|