32 lines
1.4 KiB
TypeScript
32 lines
1.4 KiB
TypeScript
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
// the client's level in tests, apart from tests/helpers.ts so tests that don't use it don't load the renderer
|
|
import { ClientLevel } from "@/client/level/client_level.ts";
|
|
import { AssetManager } from "@/client/assets.ts";
|
|
import type { ToChunkWorker } from "@/client/workers/chunk_messages.ts";
|
|
import { type BlockRegistry, EverythingRegistry } from "@/common/everything_registry.ts";
|
|
import type { WorldShape } from "@/common/world_shape.ts";
|
|
|
|
// a client's level for the loaded mods' blocks, numbered the same as the server's, without a gpu or chunk workers: what
|
|
// it asks its workers to mesh is kept in requests instead of being sent
|
|
export function client_level(shape: WorldShape) {
|
|
AssetManager.instance.assets["cubi:textures"] = { width: 16, height: 16 };
|
|
AssetManager.instance.assets["cubi:textures_info"] = {};
|
|
const requests: Extract<ToChunkWorker, { type: "mesh" }>[] = [];
|
|
const real = globalThis.Worker;
|
|
globalThis.Worker = class {
|
|
postMessage(message: ToChunkWorker) {
|
|
if (message.type === "mesh") requests.push(message);
|
|
}
|
|
terminate() {}
|
|
} as unknown as typeof Worker;
|
|
try {
|
|
const blocks = EverythingRegistry.get_registry<BlockRegistry>("blocks");
|
|
const level = new ClientLevel(Array.from(blocks, (block) => block?.id), shape, 2);
|
|
return { level, requests };
|
|
} finally {
|
|
globalThis.Worker = real;
|
|
}
|
|
}
|