@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
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { PackDataSchema } from './pack.js';
|
|
3
|
+
import { GameCapabilitySchema } from './types.js';
|
|
4
|
+
/*
|
|
5
|
+
* What crosses the plugin sandbox's boundary (docs/plugin-architecture.md § The sandbox). The guest
|
|
6
|
+
* side (`exposeToHost` in @gameslate/sources) answers these calls with JSON; the core validates
|
|
7
|
+
* every answer against these schemas before it trusts it.
|
|
8
|
+
*/
|
|
9
|
+
/** A memory source as the guest describes it: everything but its code. */
|
|
10
|
+
export const SandboxSourceSchema = z.object({
|
|
11
|
+
gameId: z.string().min(1),
|
|
12
|
+
stateSchemaVersion: z.number().int(),
|
|
13
|
+
capabilities: z.array(GameCapabilitySchema),
|
|
14
|
+
supportedBuildIds: z.array(z.tuple([z.string(), z.object({ region: z.string() })])),
|
|
15
|
+
executableHints: z.array(z.string()),
|
|
16
|
+
wrapperMayOmitStats: z.array(z.string()).optional(),
|
|
17
|
+
unsupportedExecutables: z
|
|
18
|
+
.array(z.object({ executable: z.string(), reason: z.string() }))
|
|
19
|
+
.optional(),
|
|
20
|
+
});
|
|
21
|
+
export const SandboxDescriptionSchema = z.object({
|
|
22
|
+
id: z.string().min(1),
|
|
23
|
+
packs: z.array(PackDataSchema),
|
|
24
|
+
sources: z.array(SandboxSourceSchema),
|
|
25
|
+
});
|
|
26
|
+
/** What the guest learns about the game it's attached to (no pid, no path). */
|
|
27
|
+
export const SandboxMemoryInfoSchema = z.object({
|
|
28
|
+
buildId: z.string().nullable(),
|
|
29
|
+
commandLine: z.array(z.string()),
|
|
30
|
+
/** decimal: bigints don't cross the boundary as JSON */
|
|
31
|
+
moduleBase: z.string().regex(/^\d+$/),
|
|
32
|
+
});
|
|
33
|
+
/** A player's file as the asset guest sees it: a handle for `inputRead`, its name and size. */
|
|
34
|
+
export const SandboxInputFileSchema = z.object({
|
|
35
|
+
handle: z.number().int().positive(),
|
|
36
|
+
name: z.string(),
|
|
37
|
+
size: z.number().int().nonnegative(),
|
|
38
|
+
});
|
|
39
|
+
export const SandboxInputFilesSchema = z.array(SandboxInputFileSchema);
|
package/lib/status.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Catalogue, CatalogueCounter, CatalogueMission, CollectibleEntry, ReferenceEntry } from './catalogue.js';
|
|
2
|
+
import type { EvaluationContext } from './condition.js';
|
|
3
|
+
import type { GameState } from './types.js';
|
|
4
|
+
/** Context whose `{ mission }` conditions resolve against this catalogue (cycles → unknown). */
|
|
5
|
+
export declare function createEvaluationContext(catalogue: Catalogue, state: GameState): EvaluationContext;
|
|
6
|
+
export type MissionStatus = 'done' | 'active' | 'unknown';
|
|
7
|
+
export declare function getMissionStatus(mission: CatalogueMission, state: GameState, ctx: EvaluationContext): MissionStatus;
|
|
8
|
+
/** Missions shown now: availability unmet hides; unknown availability still shows. */
|
|
9
|
+
export declare function isMissionAvailable(mission: CatalogueMission, state: GameState, ctx: EvaluationContext): boolean;
|
|
10
|
+
export declare function getMissionProgress(mission: CatalogueMission, state: GameState): {
|
|
11
|
+
current: number;
|
|
12
|
+
target: number;
|
|
13
|
+
} | null;
|
|
14
|
+
export type Visibility = 'revealed' | 'hidden' | 'unknown';
|
|
15
|
+
export declare function getReferenceVisibility(entry: ReferenceEntry, state: GameState, ctx: EvaluationContext): Visibility;
|
|
16
|
+
export type CollectibleStatus = 'collected' | 'missing' | 'untracked';
|
|
17
|
+
export declare function getCollectibleStatus(entry: CollectibleEntry, state: GameState): CollectibleStatus;
|
|
18
|
+
export interface CounterView {
|
|
19
|
+
value: number;
|
|
20
|
+
text: string;
|
|
21
|
+
max: number | null;
|
|
22
|
+
}
|
|
23
|
+
/** Counter value + display text; null when the counter isn't streamed (unknown, not zero). */
|
|
24
|
+
export declare function getCounterView(counter: CatalogueCounter, state: GameState): CounterView | null;
|
package/lib/status.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { evaluate, readCounter } from './condition.js';
|
|
2
|
+
/*
|
|
3
|
+
* Evaluators the UI calls. They turn catalogue declarations + live state into display status,
|
|
4
|
+
* so widgets never contain per-game or per-item logic.
|
|
5
|
+
*/
|
|
6
|
+
/** Context whose `{ mission }` conditions resolve against this catalogue (cycles → unknown). */
|
|
7
|
+
export function createEvaluationContext(catalogue, state) {
|
|
8
|
+
const byId = new Map(catalogue.missions.map(m => [m.id, m]));
|
|
9
|
+
const cache = new Map();
|
|
10
|
+
const inProgress = new Set();
|
|
11
|
+
const ctx = {
|
|
12
|
+
missionStatus: (id) => {
|
|
13
|
+
const cached = cache.get(id);
|
|
14
|
+
if (cached)
|
|
15
|
+
return cached;
|
|
16
|
+
const mission = byId.get(id);
|
|
17
|
+
if (!mission || inProgress.has(id))
|
|
18
|
+
return 'unknown';
|
|
19
|
+
inProgress.add(id);
|
|
20
|
+
const result = evaluate(mission.done, state, ctx);
|
|
21
|
+
inProgress.delete(id);
|
|
22
|
+
cache.set(id, result);
|
|
23
|
+
return result;
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
return ctx;
|
|
27
|
+
}
|
|
28
|
+
export function getMissionStatus(mission, state, ctx) {
|
|
29
|
+
const result = evaluate(mission.done, state, ctx);
|
|
30
|
+
if (result === 'met')
|
|
31
|
+
return 'done';
|
|
32
|
+
return result === 'unmet' ? 'active' : 'unknown';
|
|
33
|
+
}
|
|
34
|
+
/** Missions shown now: availability unmet hides; unknown availability still shows. */
|
|
35
|
+
export function isMissionAvailable(mission, state, ctx) {
|
|
36
|
+
return !mission.availableWhen || evaluate(mission.availableWhen, state, ctx) !== 'unmet';
|
|
37
|
+
}
|
|
38
|
+
export function getMissionProgress(mission, state) {
|
|
39
|
+
if (!mission.progress)
|
|
40
|
+
return null;
|
|
41
|
+
const current = readCounter(state, mission.progress.counter);
|
|
42
|
+
return current === undefined
|
|
43
|
+
? null
|
|
44
|
+
: { current: Math.min(current, mission.progress.target), target: mission.progress.target };
|
|
45
|
+
}
|
|
46
|
+
export function getReferenceVisibility(entry, state, ctx) {
|
|
47
|
+
if (!entry.revealWhen)
|
|
48
|
+
return 'revealed';
|
|
49
|
+
const result = evaluate(entry.revealWhen, state, ctx);
|
|
50
|
+
if (result === 'met')
|
|
51
|
+
return 'revealed';
|
|
52
|
+
return result === 'unmet' ? 'hidden' : 'unknown';
|
|
53
|
+
}
|
|
54
|
+
export function getCollectibleStatus(entry, state) {
|
|
55
|
+
if (!entry.collectedBy)
|
|
56
|
+
return 'untracked';
|
|
57
|
+
const result = evaluate(entry.collectedBy, state);
|
|
58
|
+
if (result === 'met')
|
|
59
|
+
return 'collected';
|
|
60
|
+
return result === 'unmet' ? 'missing' : 'untracked';
|
|
61
|
+
}
|
|
62
|
+
/** Counter value + display text; null when the counter isn't streamed (unknown, not zero). */
|
|
63
|
+
export function getCounterView(counter, state) {
|
|
64
|
+
const value = readCounter(state, counter.id);
|
|
65
|
+
if (value === undefined)
|
|
66
|
+
return null;
|
|
67
|
+
const max = typeof counter.max === 'number'
|
|
68
|
+
? counter.max
|
|
69
|
+
: counter.max
|
|
70
|
+
? (readCounter(state, counter.max) ?? null)
|
|
71
|
+
: null;
|
|
72
|
+
const mapped = counter.display?.[String(value)];
|
|
73
|
+
const text = mapped ?? (max !== null ? `${value}/${max}` : String(value));
|
|
74
|
+
return { value, text, max };
|
|
75
|
+
}
|