Full game

This commit is contained in:
2025-10-31 16:21:56 -07:00
parent 965253386a
commit eeab08af75
20 changed files with 1125 additions and 560 deletions

View File

@@ -2,34 +2,40 @@
let worker: Worker | null = null;
export async function runScript(
export function sendDataToScript(data: String) {
if (worker) {
worker.postMessage({ type: "data", data });
}
}
export async function startScript(
script: string,
appendOutput: (line: string) => void,
appendTerminal?: (line: string) => void
appendTerminal: (line: string) => void
): Promise<void> {
return new Promise((resolve, reject) => {
if (worker) {
worker.terminate();
}
worker = new Worker(new URL('./script-runner.worker.ts', import.meta.url));
worker = new Worker(new URL("./worker.ts", import.meta.url));
worker.onmessage = (event) => {
const { type, line, error } = event.data;
if (type === 'output') {
if (type === "output") {
appendOutput(line);
} else if (type === 'terminal') {
appendTerminal?.(line);
} else if (type === 'complete') {
} else if (type === "terminal") {
appendTerminal(line);
} else if (type === "complete") {
worker?.terminate();
worker = null;
resolve();
} else if (type === 'error') {
} else if (type === "error") {
worker?.terminate();
worker = null;
reject(new Error(error));
} else if (type === 'stopped') {
} else if (type === "stopped") {
worker?.terminate();
worker = null;
resolve();
@@ -42,12 +48,12 @@ export async function runScript(
reject(error);
};
worker.postMessage({ type: 'run', script });
worker.postMessage({ type: "run", script });
});
}
export function stopScript(): void {
if (worker) {
worker.postMessage({ type: 'stop' });
worker.postMessage({ type: "stop" });
}
}