@crowdedkingdoms/crowdyjs 9.0.0 → 10.0.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/MIGRATION.md +56 -34
- package/README.md +83 -50
- package/dist/crowdy-client.d.ts +3 -0
- package/dist/crowdy-client.d.ts.map +1 -1
- package/dist/crowdy-client.js +2 -0
- package/dist/domains/playerCodeProjects.d.ts +25 -0
- package/dist/domains/playerCodeProjects.d.ts.map +1 -0
- package/dist/domains/playerCodeProjects.js +299 -0
- package/dist/domains/playerCompute.d.ts +1 -1
- package/dist/domains/playerCompute.js +1 -1
- package/dist/generated/graphql.d.ts +792 -7
- package/dist/generated/graphql.d.ts.map +1 -1
- package/dist/generated/graphql.js +57 -0
- package/dist/index.d.ts +3 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -5
- package/dist/kit/npcs.d.ts.map +1 -1
- package/dist/kit/social.d.ts.map +1 -1
- package/dist/live-coding/rust-analysis.d.ts.map +1 -1
- package/dist/live-coding/rust-analysis.js +64 -1
- package/dist/live-coding/worker-transport.d.ts +3 -0
- package/dist/live-coding/worker-transport.d.ts.map +1 -1
- package/dist/live-coding/worker-transport.js +13 -0
- package/dist/mod-studio/controller.d.ts +188 -0
- package/dist/mod-studio/controller.d.ts.map +1 -0
- package/dist/mod-studio/controller.js +915 -0
- package/dist/mod-studio/diagnostics.d.ts +22 -0
- package/dist/mod-studio/diagnostics.d.ts.map +1 -0
- package/dist/mod-studio/diagnostics.js +141 -0
- package/dist/mod-studio/dom-shell.d.ts +55 -0
- package/dist/mod-studio/dom-shell.d.ts.map +1 -0
- package/dist/mod-studio/dom-shell.js +527 -0
- package/dist/mod-studio/editor.d.ts +17 -0
- package/dist/mod-studio/editor.d.ts.map +1 -0
- package/dist/mod-studio/editor.js +1 -0
- package/dist/mod-studio/index.d.ts +10 -0
- package/dist/mod-studio/index.d.ts.map +1 -0
- package/dist/mod-studio/index.js +9 -0
- package/dist/mod-studio/models.d.ts +149 -0
- package/dist/mod-studio/models.d.ts.map +1 -0
- package/dist/mod-studio/models.js +62 -0
- package/dist/mod-studio/monaco-editor.d.ts +16 -0
- package/dist/mod-studio/monaco-editor.d.ts.map +1 -0
- package/dist/mod-studio/monaco-editor.js +548 -0
- package/dist/mod-studio/mount.d.ts +17 -0
- package/dist/mod-studio/mount.d.ts.map +1 -0
- package/dist/mod-studio/mount.js +86 -0
- package/dist/mod-studio/starter-projects.d.ts +11 -0
- package/dist/mod-studio/starter-projects.d.ts.map +1 -0
- package/dist/mod-studio/starter-projects.js +102 -0
- package/dist/mod-studio/styles.d.ts +2 -0
- package/dist/mod-studio/styles.d.ts.map +1 -0
- package/dist/mod-studio/styles.js +14 -0
- package/dist/mod-studio/textarea-editor.d.ts +8 -0
- package/dist/mod-studio/textarea-editor.d.ts.map +1 -0
- package/dist/mod-studio/textarea-editor.js +71 -0
- package/package.json +4 -4
- package/dist/live-coding/ide.d.ts +0 -23
- package/dist/live-coding/ide.d.ts.map +0 -1
- package/dist/live-coding/ide.js +0 -514
- package/dist/live-coding/index.d.ts +0 -8
- package/dist/live-coding/index.d.ts.map +0 -1
- package/dist/live-coding/index.js +0 -7
- package/dist/live-coding/live-coding-controller.d.ts +0 -75
- package/dist/live-coding/live-coding-controller.d.ts.map +0 -1
- package/dist/live-coding/live-coding-controller.js +0 -141
- package/dist/live-coding/mount.d.ts +0 -26
- package/dist/live-coding/mount.d.ts.map +0 -1
- package/dist/live-coding/mount.js +0 -108
- package/dist/live-coding/templates.d.ts +0 -17
- package/dist/live-coding/templates.d.ts.map +0 -1
- package/dist/live-coding/templates.js +0 -59
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { PlayerCodeBroker, } from '../player-runtime/player-code-broker.js';
|
|
2
|
-
/**
|
|
3
|
-
* Headless driver for the live-coding deploy loop (08), shared by the DOM
|
|
4
|
-
* panel and any custom host UI. It owns the edit -> deploy -> compile-poll ->
|
|
5
|
-
* (server) enable / (client) fetch+respawn state machine, surfaces compile
|
|
6
|
-
* feedback and the quota/wallet meters, and manages the client broker
|
|
7
|
-
* lifecycle. All IO is injected so it is unit-testable without a browser.
|
|
8
|
-
*/
|
|
9
|
-
export class LiveCodingController {
|
|
10
|
-
constructor(options) {
|
|
11
|
-
this.options = options;
|
|
12
|
-
this.broker = null;
|
|
13
|
-
this.status = { phase: 'idle', target: 'server' };
|
|
14
|
-
}
|
|
15
|
-
getStatus() {
|
|
16
|
-
return this.status;
|
|
17
|
-
}
|
|
18
|
-
set(next) {
|
|
19
|
-
this.status = { ...this.status, ...next };
|
|
20
|
-
this.options.onStatus?.(this.status);
|
|
21
|
-
}
|
|
22
|
-
sleep(ms) {
|
|
23
|
-
return (this.options.sleep ?? ((d) => new Promise((r) => setTimeout(r, d))))(ms);
|
|
24
|
-
}
|
|
25
|
-
/** Refresh the quota/wallet meter for the panel. */
|
|
26
|
-
async refreshUsage() {
|
|
27
|
-
const usage = await this.options.playerCompute.usage({
|
|
28
|
-
appId: this.options.appId,
|
|
29
|
-
});
|
|
30
|
-
this.set({
|
|
31
|
-
usage: {
|
|
32
|
-
hourUnitsUsed: String(usage.hourUnitsUsed),
|
|
33
|
-
unitsPerHour: usage.unitsPerHour != null ? String(usage.unitsPerHour) : null,
|
|
34
|
-
compilesThisHour: usage.compilesThisHour,
|
|
35
|
-
maxCompilesPerHour: usage.maxCompilesPerHour,
|
|
36
|
-
gateStatus: usage.gateStatus,
|
|
37
|
-
gateReason: usage.gateReason ?? null,
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Deploy source and run it. For server targets: deploy -> poll compile ->
|
|
43
|
-
* enable. For client targets: deploy -> poll compile -> fetch bytes ->
|
|
44
|
-
* (re)spawn the broker worker. Draft mode suppresses server egress to other
|
|
45
|
-
* sessions while iterating.
|
|
46
|
-
*/
|
|
47
|
-
async deploy(input) {
|
|
48
|
-
const { name, target } = input;
|
|
49
|
-
this.set({ phase: 'deploying', target, message: undefined, compileLog: null });
|
|
50
|
-
let version;
|
|
51
|
-
try {
|
|
52
|
-
version = await this.options.playerCompute.deploy({
|
|
53
|
-
appId: this.options.appId,
|
|
54
|
-
gridId: this.options.gridId,
|
|
55
|
-
name,
|
|
56
|
-
target: target === 'server' ? 'SERVER' : 'CLIENT',
|
|
57
|
-
sourceFilesJson: input.sourceFilesJson,
|
|
58
|
-
tickHz: input.tickHz,
|
|
59
|
-
draft: input.draft,
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
catch (err) {
|
|
63
|
-
// Compile-quota refusals and cap breaches surface here (P2 governor).
|
|
64
|
-
this.set({ phase: 'error', message: err.message });
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
const compiled = await this.pollCompile(name, version.versionId);
|
|
68
|
-
if (!compiled.ok) {
|
|
69
|
-
this.set({
|
|
70
|
-
phase: 'compile_failed',
|
|
71
|
-
message: 'compile failed',
|
|
72
|
-
compileLog: compiled.log,
|
|
73
|
-
});
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
if (target === 'server') {
|
|
77
|
-
this.set({ phase: 'enabling' });
|
|
78
|
-
await this.options.playerCompute.setEnabled({
|
|
79
|
-
appId: this.options.appId,
|
|
80
|
-
gridId: this.options.gridId,
|
|
81
|
-
name,
|
|
82
|
-
enabled: true,
|
|
83
|
-
});
|
|
84
|
-
this.set({ phase: 'running', message: 'server module live' });
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
await this.runClient(name);
|
|
88
|
-
}
|
|
89
|
-
await this.refreshUsage().catch(() => { });
|
|
90
|
-
}
|
|
91
|
-
async pollCompile(name, versionId) {
|
|
92
|
-
this.set({ phase: 'compiling' });
|
|
93
|
-
const pollMs = this.options.pollMs ?? 1500;
|
|
94
|
-
for (let i = 0; i < 60; i++) {
|
|
95
|
-
const versions = await this.options.playerCompute.versions({
|
|
96
|
-
appId: this.options.appId,
|
|
97
|
-
gridId: this.options.gridId,
|
|
98
|
-
name,
|
|
99
|
-
});
|
|
100
|
-
const v = versions.find((row) => row.versionId === versionId);
|
|
101
|
-
if (v?.compileStatus === 'succeeded')
|
|
102
|
-
return { ok: true, log: v.compileLog ?? null };
|
|
103
|
-
if (v?.compileStatus === 'failed')
|
|
104
|
-
return { ok: false, log: v.compileLog ?? null };
|
|
105
|
-
await this.sleep(pollMs);
|
|
106
|
-
}
|
|
107
|
-
return { ok: false, log: 'compile timed out' };
|
|
108
|
-
}
|
|
109
|
-
async runClient(name) {
|
|
110
|
-
const artifact = await this.options.playerCompute.artifactBytes({
|
|
111
|
-
appId: this.options.appId,
|
|
112
|
-
gridId: this.options.gridId,
|
|
113
|
-
name,
|
|
114
|
-
});
|
|
115
|
-
const options = {
|
|
116
|
-
workerUrl: this.options.workerUrl,
|
|
117
|
-
grid: this.options.grid,
|
|
118
|
-
artifactHash: artifact.artifactHash,
|
|
119
|
-
fuelPerDispatch: artifact.fuelPerDispatch,
|
|
120
|
-
onHostCall: this.options.onHostCall,
|
|
121
|
-
onPresentation: this.options.onPresentation,
|
|
122
|
-
tickIntervalMs: this.options.clientTickIntervalMs ?? 1000,
|
|
123
|
-
};
|
|
124
|
-
const broker = this.options.brokerFactory?.(options) ?? new PlayerCodeBroker(options);
|
|
125
|
-
if (this.broker) {
|
|
126
|
-
await broker.start(artifact.bytes);
|
|
127
|
-
this.broker.stop();
|
|
128
|
-
this.broker = broker;
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
await broker.start(artifact.bytes);
|
|
132
|
-
this.broker = broker;
|
|
133
|
-
}
|
|
134
|
-
this.set({ phase: 'running', message: 'client module live in the sandbox' });
|
|
135
|
-
}
|
|
136
|
-
stop() {
|
|
137
|
-
this.broker?.stop();
|
|
138
|
-
this.broker = null;
|
|
139
|
-
this.set({ phase: 'idle' });
|
|
140
|
-
}
|
|
141
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { LiveCodingController, type LiveCodingControllerOptions } from './live-coding-controller.js';
|
|
2
|
-
import { type PlayerCodeTemplate } from './templates.js';
|
|
3
|
-
export interface MountLiveCodingOptions extends Omit<LiveCodingControllerOptions, 'onStatus'> {
|
|
4
|
-
/** Module name to deploy under; defaults to a per-grid scratch name. */
|
|
5
|
-
moduleName?: string;
|
|
6
|
-
/** Templates offered in the picker; defaults to the built-in starter set. */
|
|
7
|
-
templates?: PlayerCodeTemplate[];
|
|
8
|
-
/** Deploy in draft mode by default (server egress suppressed while iterating). */
|
|
9
|
-
draftByDefault?: boolean;
|
|
10
|
-
}
|
|
11
|
-
export interface LiveCodingHandle {
|
|
12
|
-
controller: LiveCodingController;
|
|
13
|
-
destroy: () => void;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Mount the live-coding panel into a host element (08 option A). Deliberately
|
|
17
|
-
* dependency-free DOM: a textarea editor, target + template pickers, deploy /
|
|
18
|
-
* draft-deploy / stop buttons, a status+console line, and the quota/wallet
|
|
19
|
-
* meter. Games skin it via the returned nodes or their own CSS; a game that
|
|
20
|
-
* wants a custom UI can drive LiveCodingController directly instead.
|
|
21
|
-
*
|
|
22
|
-
* Safe to import in non-DOM contexts; mounting throws only if called without
|
|
23
|
-
* a document.
|
|
24
|
-
*/
|
|
25
|
-
export declare function mountLiveCoding(el: HTMLElement, options: MountLiveCodingOptions): LiveCodingHandle;
|
|
26
|
-
//# sourceMappingURL=mount.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mount.d.ts","sourceRoot":"","sources":["../../src/live-coding/mount.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,KAAK,2BAA2B,EAEjC,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAEL,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AAExB,MAAM,WAAW,sBACf,SAAQ,IAAI,CAAC,2BAA2B,EAAE,UAAU,CAAC;IACrD,wEAAwE;IACxE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,6EAA6E;IAC7E,SAAS,CAAC,EAAE,kBAAkB,EAAE,CAAC;IACjC,kFAAkF;IAClF,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,oBAAoB,CAAC;IACjC,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC7B,EAAE,EAAE,WAAW,EACf,OAAO,EAAE,sBAAsB,GAC9B,gBAAgB,CAmFlB"}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { LiveCodingController, } from './live-coding-controller.js';
|
|
2
|
-
import { PLAYER_CODE_TEMPLATES, } from './templates.js';
|
|
3
|
-
/**
|
|
4
|
-
* Mount the live-coding panel into a host element (08 option A). Deliberately
|
|
5
|
-
* dependency-free DOM: a textarea editor, target + template pickers, deploy /
|
|
6
|
-
* draft-deploy / stop buttons, a status+console line, and the quota/wallet
|
|
7
|
-
* meter. Games skin it via the returned nodes or their own CSS; a game that
|
|
8
|
-
* wants a custom UI can drive LiveCodingController directly instead.
|
|
9
|
-
*
|
|
10
|
-
* Safe to import in non-DOM contexts; mounting throws only if called without
|
|
11
|
-
* a document.
|
|
12
|
-
*/
|
|
13
|
-
export function mountLiveCoding(el, options) {
|
|
14
|
-
if (typeof document === 'undefined') {
|
|
15
|
-
throw new Error('mountLiveCoding requires a DOM document');
|
|
16
|
-
}
|
|
17
|
-
const templates = options.templates ?? PLAYER_CODE_TEMPLATES;
|
|
18
|
-
const moduleName = options.moduleName ?? 'scratch-mod';
|
|
19
|
-
const root = document.createElement('div');
|
|
20
|
-
root.className = 'ck-live-coding';
|
|
21
|
-
const targetSelect = document.createElement('select');
|
|
22
|
-
for (const t of ['server', 'client']) {
|
|
23
|
-
const opt = document.createElement('option');
|
|
24
|
-
opt.value = t;
|
|
25
|
-
opt.textContent = t;
|
|
26
|
-
targetSelect.appendChild(opt);
|
|
27
|
-
}
|
|
28
|
-
const templateSelect = document.createElement('select');
|
|
29
|
-
const editor = document.createElement('textarea');
|
|
30
|
-
editor.className = 'ck-live-coding-editor';
|
|
31
|
-
editor.rows = 20;
|
|
32
|
-
const refreshTemplates = () => {
|
|
33
|
-
templateSelect.innerHTML = '';
|
|
34
|
-
for (const t of templates.filter((t) => t.target === targetSelect.value)) {
|
|
35
|
-
const opt = document.createElement('option');
|
|
36
|
-
opt.value = t.id;
|
|
37
|
-
opt.textContent = t.title;
|
|
38
|
-
templateSelect.appendChild(opt);
|
|
39
|
-
}
|
|
40
|
-
const first = templates.find((t) => t.target === targetSelect.value);
|
|
41
|
-
if (first)
|
|
42
|
-
editor.value = first.sourceFilesJson;
|
|
43
|
-
};
|
|
44
|
-
templateSelect.addEventListener('change', () => {
|
|
45
|
-
const t = templates.find((t) => t.id === templateSelect.value);
|
|
46
|
-
if (t)
|
|
47
|
-
editor.value = t.sourceFilesJson;
|
|
48
|
-
});
|
|
49
|
-
targetSelect.addEventListener('change', refreshTemplates);
|
|
50
|
-
const deployBtn = button('Deploy');
|
|
51
|
-
const draftBtn = button('Deploy draft');
|
|
52
|
-
const stopBtn = button('Stop');
|
|
53
|
-
const status = document.createElement('pre');
|
|
54
|
-
status.className = 'ck-live-coding-status';
|
|
55
|
-
const meter = document.createElement('div');
|
|
56
|
-
meter.className = 'ck-live-coding-meter';
|
|
57
|
-
const controller = new LiveCodingController({
|
|
58
|
-
...options,
|
|
59
|
-
onStatus: (s) => renderStatus(status, meter, s),
|
|
60
|
-
});
|
|
61
|
-
const doDeploy = (draft) => void controller
|
|
62
|
-
.deploy({
|
|
63
|
-
name: moduleName,
|
|
64
|
-
target: targetSelect.value,
|
|
65
|
-
sourceFilesJson: editor.value,
|
|
66
|
-
draft: draft || options.draftByDefault,
|
|
67
|
-
})
|
|
68
|
-
.catch((err) => {
|
|
69
|
-
status.textContent = `error: ${err.message}`;
|
|
70
|
-
});
|
|
71
|
-
deployBtn.addEventListener('click', () => doDeploy(false));
|
|
72
|
-
draftBtn.addEventListener('click', () => doDeploy(true));
|
|
73
|
-
stopBtn.addEventListener('click', () => controller.stop());
|
|
74
|
-
const controls = document.createElement('div');
|
|
75
|
-
controls.className = 'ck-live-coding-controls';
|
|
76
|
-
controls.append(targetSelect, templateSelect, deployBtn, draftBtn, stopBtn);
|
|
77
|
-
root.append(controls, editor, status, meter);
|
|
78
|
-
el.appendChild(root);
|
|
79
|
-
refreshTemplates();
|
|
80
|
-
void controller.refreshUsage().catch(() => { });
|
|
81
|
-
return {
|
|
82
|
-
controller,
|
|
83
|
-
destroy: () => {
|
|
84
|
-
controller.stop();
|
|
85
|
-
root.remove();
|
|
86
|
-
},
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
function button(label) {
|
|
90
|
-
const b = document.createElement('button');
|
|
91
|
-
b.type = 'button';
|
|
92
|
-
b.textContent = label;
|
|
93
|
-
return b;
|
|
94
|
-
}
|
|
95
|
-
function renderStatus(status, meter, s) {
|
|
96
|
-
const parts = [`[${s.target}] ${s.phase}`];
|
|
97
|
-
if (s.message)
|
|
98
|
-
parts.push(s.message);
|
|
99
|
-
if (s.compileLog)
|
|
100
|
-
parts.push('\n' + s.compileLog);
|
|
101
|
-
status.textContent = parts.join(' ');
|
|
102
|
-
if (s.usage) {
|
|
103
|
-
const gate = s.usage.gateStatus === 'active'
|
|
104
|
-
? 'active'
|
|
105
|
-
: `${s.usage.gateStatus}${s.usage.gateReason ? ` (${s.usage.gateReason})` : ''}`;
|
|
106
|
-
meter.textContent = `units ${s.usage.hourUnitsUsed}/${s.usage.unitsPerHour ?? '∞'} · compiles ${s.usage.compilesThisHour}/${s.usage.maxCompilesPerHour} · gate ${gate}`;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Starter templates for the live-coding panel (08 §5). These are minimal,
|
|
3
|
-
* compile-ready single-file mods written against the public host surface —
|
|
4
|
-
* the panel seeds them and games (BWF) supply their own richer set. Each
|
|
5
|
-
* value is the JSON source map playerComputeDeploy expects.
|
|
6
|
-
*/
|
|
7
|
-
export interface PlayerCodeTemplate {
|
|
8
|
-
id: string;
|
|
9
|
-
title: string;
|
|
10
|
-
target: 'server' | 'client';
|
|
11
|
-
description: string;
|
|
12
|
-
/** JSON string: { "Cargo.toml": "...", "src/lib.rs": "..." } */
|
|
13
|
-
sourceFilesJson: string;
|
|
14
|
-
}
|
|
15
|
-
export declare const PLAYER_CODE_TEMPLATES: PlayerCodeTemplate[];
|
|
16
|
-
export declare function templateById(id: string): PlayerCodeTemplate | undefined;
|
|
17
|
-
//# sourceMappingURL=templates.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../src/live-coding/templates.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,gEAAgE;IAChE,eAAe,EAAE,MAAM,CAAC;CACzB;AAoBD,eAAO,MAAM,qBAAqB,EAAE,kBAAkB,EAiDrD,CAAC;AAEF,wBAAgB,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS,CAEvE"}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
function cargo(name) {
|
|
2
|
-
return `[package]
|
|
3
|
-
name = "${name}"
|
|
4
|
-
version = "0.1.0"
|
|
5
|
-
edition = "2021"
|
|
6
|
-
|
|
7
|
-
[lib]
|
|
8
|
-
crate-type = ["cdylib"]
|
|
9
|
-
|
|
10
|
-
[dependencies]
|
|
11
|
-
crowdy-compute-sdk = "0.1.5"
|
|
12
|
-
`;
|
|
13
|
-
}
|
|
14
|
-
function src(name, lib) {
|
|
15
|
-
return JSON.stringify({ 'Cargo.toml': cargo(name), 'src/lib.rs': lib });
|
|
16
|
-
}
|
|
17
|
-
export const PLAYER_CODE_TEMPLATES = [
|
|
18
|
-
{
|
|
19
|
-
id: 'server-ticker',
|
|
20
|
-
title: 'Grid ticker (server)',
|
|
21
|
-
target: 'server',
|
|
22
|
-
description: 'A low-rate server tick you can grow into an auto-farm or spawner.',
|
|
23
|
-
sourceFilesJson: src('grid-ticker', `fn on_init() {}
|
|
24
|
-
fn on_tick(_dt: u32) {
|
|
25
|
-
// Runs on the server as the grid owner while someone is in the grid.
|
|
26
|
-
// Read/write only inside your grid; egress is grid-clamped.
|
|
27
|
-
}
|
|
28
|
-
fn on_invoke(_payload: &[u8]) -> Vec<u8> { Vec::new() }
|
|
29
|
-
crowdy_compute_sdk::register_module!(init: on_init, tick: on_tick, invoke: on_invoke);`),
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
id: 'server-invoke',
|
|
33
|
-
title: 'Invoke tool (server)',
|
|
34
|
-
target: 'server',
|
|
35
|
-
description: 'A callable export a client tool or automation can invoke as you.',
|
|
36
|
-
sourceFilesJson: src('invoke-tool', `fn on_init() {}
|
|
37
|
-
fn on_tick(_dt: u32) {}
|
|
38
|
-
fn on_invoke(_payload: &[u8]) -> Vec<u8> {
|
|
39
|
-
b"{\\"ok\\":true}".to_vec()
|
|
40
|
-
}
|
|
41
|
-
crowdy_compute_sdk::register_module!(init: on_init, tick: on_tick, invoke: on_invoke);`),
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
id: 'client-hud',
|
|
45
|
-
title: 'Grid HUD (client)',
|
|
46
|
-
target: 'client',
|
|
47
|
-
description: 'A browser mod that draws a HUD panel for your grid via the presentation hook.',
|
|
48
|
-
sourceFilesJson: src('grid-hud', `fn on_init() {}
|
|
49
|
-
fn on_tick(_dt: u32) {
|
|
50
|
-
// Client-side, runs as you in the browser sandbox. Use the hud_set host
|
|
51
|
-
// call (via the SDK) to render into the game's mod HUD region.
|
|
52
|
-
}
|
|
53
|
-
fn on_invoke(_payload: &[u8]) -> Vec<u8> { Vec::new() }
|
|
54
|
-
crowdy_compute_sdk::register_module!(init: on_init, tick: on_tick, invoke: on_invoke);`),
|
|
55
|
-
},
|
|
56
|
-
];
|
|
57
|
-
export function templateById(id) {
|
|
58
|
-
return PLAYER_CODE_TEMPLATES.find((t) => t.id === id);
|
|
59
|
-
}
|