Loading schematics
This commit is contained in:
+28
-6
@@ -18,12 +18,23 @@ import { decode_level_chunk, type LevelChunk } from "@/common/chunk_streaming.ts
|
||||
import { decode_chunk, encode_chunk } from "@/server/game/saves.ts";
|
||||
import { list_chunks, read_chunk, write_chunks } from "@/server/regions.ts";
|
||||
import { section_index } from "@/common/section.ts";
|
||||
import { encode_schematic, type Schematic } from "@/common/schematic.ts";
|
||||
|
||||
// mods/bworld and one made from the template, packed into a folder of .cubi files
|
||||
// a schematic the template mod gets
|
||||
const POST: Schematic = {
|
||||
size: [1, 2, 1],
|
||||
palette: [{ id: "bworld:stone" }],
|
||||
blocks: [{ i: 0, p: [0, 0, 0] }, { i: 0, p: [0, 1, 0] }],
|
||||
entities: [],
|
||||
};
|
||||
|
||||
// mods/bworld and one made from the template, with a schematic, packed into a folder of .cubi files
|
||||
async function packed_mods() {
|
||||
const sources = Deno.makeTempDirSync({ prefix: "bworld_mod_src_" });
|
||||
copy_dir("mods/bworld", `${sources}/bworld`);
|
||||
create_mod("copper_tools", "Copper Tools", sources);
|
||||
Deno.mkdirSync(`${sources}/copper_tools/schematics`);
|
||||
Deno.writeFileSync(`${sources}/copper_tools/schematics/post.cbsm`, encode_schematic(POST));
|
||||
const mods = await load_and_check(sources);
|
||||
for (const mod of mods) assertEquals(mod.report.errors, [], mod.id);
|
||||
|
||||
@@ -32,7 +43,7 @@ async function packed_mods() {
|
||||
return { sources, folder, mods };
|
||||
}
|
||||
|
||||
Deno.test("packing a mod keeps its data, script, textures and credits, and gives the same bytes every time", async () => {
|
||||
Deno.test("packing a mod keeps its data, script, textures, schematics and credits, and gives the same bytes every time", async () => {
|
||||
const { sources, folder, mods } = await packed_mods();
|
||||
const template = mods.find((mod) => mod.id === "copper_tools")!;
|
||||
const bytes = Deno.readFileSync(`${folder}/copper_tools.cubi`);
|
||||
@@ -43,6 +54,8 @@ Deno.test("packing a mod keeps its data, script, textures and credits, and gives
|
||||
assertEquals(mod.data.blocks.map((b) => b.id), template.blocks.map((b) => b.json.id));
|
||||
assertEquals(mod.data.recipes, template.recipes.map((r) => r.json));
|
||||
assertEquals([...mod.textures.keys()].sort(), [...template.textures].sort());
|
||||
// named by their files
|
||||
assertEquals(mod.data.schematics, [{ ...POST, id: "copper_tools:post" }]);
|
||||
assertStringIncludes(mod.script!, "function server");
|
||||
assert(mod.credits);
|
||||
|
||||
@@ -108,7 +121,7 @@ Deno.test("broken .cubi files are turned away, saying why", () => {
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("the server loads every .cubi in its folder, dependencies first, and players get them without the terrain", async () => {
|
||||
Deno.test("the server loads every .cubi in its folder, dependencies first, and players get them without the terrain or schematics", async () => {
|
||||
const { sources, folder } = await packed_mods();
|
||||
const mods = await load_mods(folder, ENGINE_TEXTURES);
|
||||
assertEquals(mods.map((mod) => mod.listing.id), ["bworld", "copper_tools"]);
|
||||
@@ -123,10 +136,19 @@ Deno.test("the server loads every .cubi in its folder, dependencies first, and p
|
||||
mod.mod.script,
|
||||
"players get the whole script, and only run its shared and client phases",
|
||||
);
|
||||
// the terrain's data stays on the server too, the rest is the same
|
||||
const { noises, density_functions, noise_settings, biome_sources, dimensions, ...data } = mod.mod.data;
|
||||
const none = { noises: [], density_functions: [], noise_settings: [], biome_sources: [], dimensions: [] };
|
||||
// the terrain's data and schematics stay on the server too, the rest is the same
|
||||
const { noises, density_functions, noise_settings, biome_sources, dimensions, schematics: _, ...data } =
|
||||
mod.mod.data;
|
||||
const none = {
|
||||
noises: [],
|
||||
density_functions: [],
|
||||
noise_settings: [],
|
||||
biome_sources: [],
|
||||
dimensions: [],
|
||||
schematics: [],
|
||||
};
|
||||
assertEquals(copy.data, { ...data, ...none });
|
||||
if (mod.listing.id === "copper_tools") assertEquals(mod.mod.data.schematics?.length, 1);
|
||||
if (mod.listing.id === "bworld") {
|
||||
const terrain = [noises, density_functions, noise_settings, biome_sources, dimensions];
|
||||
assert(terrain.every((list) => list!.length > 0));
|
||||
|
||||
Reference in New Issue
Block a user