Export schematics
This commit is contained in:
@@ -10,6 +10,7 @@ import { load_mods } from "./load_mods.ts";
|
||||
import { list_chunks, read_chunk, write_chunks } from "./regions.ts";
|
||||
import { default_worldgen_workers, start_worldgen_workers } from "./worldgen_workers.ts";
|
||||
import type { SavedChunk } from "./game/saves.ts";
|
||||
import { SCHEMATIC_EXTENSION } from "@/common/schematic.ts";
|
||||
|
||||
const MAX_MESSAGE_SIZE = 4096;
|
||||
// in build/, see build.ts
|
||||
@@ -141,6 +142,17 @@ export async function start_host(options: HostOptions): Promise<Host> {
|
||||
post({ type: "downloaded", id: message.id, error: e instanceof Error ? e.message : String(e) }),
|
||||
);
|
||||
break;
|
||||
case "write_schematic":
|
||||
write_schematic(message.bytes).then(
|
||||
(path) => post({ type: "wrote_schematic", id: message.id, path }),
|
||||
(e) =>
|
||||
post({
|
||||
type: "wrote_schematic",
|
||||
id: message.id,
|
||||
error: e instanceof Error ? e.message : String(e),
|
||||
}),
|
||||
);
|
||||
break;
|
||||
}
|
||||
};
|
||||
game.onerror = (event) => {
|
||||
@@ -242,6 +254,14 @@ export async function start_host(options: HostOptions): Promise<Host> {
|
||||
};
|
||||
}
|
||||
|
||||
// an exported schematic in a new file in the system's temporary directory, for whoever runs the server to pick up.
|
||||
// returns where it is
|
||||
async function write_schematic(bytes: Uint8Array): Promise<string> {
|
||||
const path = await Deno.makeTempFile({ prefix: "schematic_", suffix: SCHEMATIC_EXTENSION });
|
||||
await Deno.writeFile(path, bytes);
|
||||
return path;
|
||||
}
|
||||
|
||||
// for the game worker, which has no network access. errors are told to players, so they say what went wrong simply
|
||||
async function download(url: string, max_bytes: number): Promise<Uint8Array> {
|
||||
let parsed: URL;
|
||||
|
||||
Reference in New Issue
Block a user