Player skins !

This commit is contained in:
2026-09-27 12:01:52 -03:00
parent edf4b72dc4
commit 60188ff735
14 changed files with 325 additions and 8 deletions
+19
View File
@@ -10,6 +10,9 @@ const SAVE_INTERVAL_MS = 30_000;
let game: GameServer | undefined;
let starting: Promise<void> | undefined;
// downloads waiting for the host, by id
const downloads = new Map<number, { resolve: (bytes: Uint8Array) => void; reject: (error: Error) => void }>();
let next_download = 1;
function post(message: GameToHost) {
self.postMessage(message);
@@ -22,6 +25,16 @@ self.onmessage = async (event: MessageEvent<HostToGame>) => {
starting = init(message);
return;
}
if (message.type === "downloaded") {
const pending = downloads.get(message.id);
downloads.delete(message.id);
if (message.bytes) {
pending?.resolve(message.bytes);
} else {
pending?.reject(new Error(message.error ?? "Couldn't download it"));
}
return;
}
// players can connect while mods are still loading
await starting;
@@ -51,6 +64,12 @@ async function init(message: Extract<HostToGame, { type: "init" }>) {
{
send: (conn, data) => post({ type: "send", conn, data }),
close: (conn) => post({ type: "close", conn }),
download: (url, max_bytes) =>
new Promise((resolve, reject) => {
const id = next_download++;
downloads.set(id, { resolve, reject });
post({ type: "download", id, url, max_bytes });
}),
},
message.save,
message.default_seed,