Single module modding
This commit is contained in:
+15
-16
@@ -32,7 +32,7 @@ async function packed_mods() {
|
||||
return { sources, folder, mods };
|
||||
}
|
||||
|
||||
Deno.test("packing a mod keeps its data, scripts, textures and credits, and gives the same bytes every time", async () => {
|
||||
Deno.test("packing a mod keeps its data, script, textures 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,13 +43,12 @@ Deno.test("packing a mod keeps its data, scripts, textures and credits, and give
|
||||
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());
|
||||
assertEquals(Object.keys(mod.scripts).sort(), ["client", "server", "worldgen"]);
|
||||
assertStringIncludes(mod.scripts.server!, "setup");
|
||||
assertStringIncludes(mod.script!, "function server");
|
||||
assert(mod.credits);
|
||||
|
||||
const bworld = read_mod(Deno.readFileSync(`${folder}/bworld.cubi`), "bworld.cubi");
|
||||
assertEquals(bworld.data.blocks.length, [...Deno.readDirSync("mods/bworld/blocks")].length);
|
||||
assertEquals(Object.keys(bworld.scripts), ["server", "client", "worldgen", "shared", "content"]);
|
||||
assert(bworld.script);
|
||||
|
||||
Deno.removeSync(sources, { recursive: true });
|
||||
Deno.removeSync(folder, { recursive: true });
|
||||
@@ -78,13 +77,13 @@ Deno.test("broken .cubi files are turned away, saying why", () => {
|
||||
() =>
|
||||
read_mod(
|
||||
zip({
|
||||
"manifest.json": text({ ...manifest, scripts: { server: "scripts/server.js" } }),
|
||||
"manifest.json": text({ ...manifest, main: "script.js" }),
|
||||
"data.json": text({}),
|
||||
}),
|
||||
"d.cubi",
|
||||
),
|
||||
Error,
|
||||
"scripts.server scripts/server.js isn't in the file",
|
||||
"main script.js isn't in the file",
|
||||
);
|
||||
// a texture bigger than MAX_TEXTURE_SIZE. only its header is read
|
||||
const big = new Uint8Array(24);
|
||||
@@ -109,7 +108,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 server scripts", async () => {
|
||||
Deno.test("the server loads every .cubi in its folder, dependencies first, and players get them without the terrain", 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"]);
|
||||
@@ -119,9 +118,11 @@ Deno.test("the server loads every .cubi in its folder, dependencies first, and p
|
||||
const digest = new Uint8Array(await crypto.subtle.digest("SHA-256", mod.client_bytes));
|
||||
assertEquals([...digest].map((b) => b.toString(16).padStart(2, "0")).join(""), mod.listing.sha256);
|
||||
const copy = read_mod(mod.client_bytes, mod.listing.file);
|
||||
assertEquals(copy.scripts.server, undefined, "server scripts never go to players");
|
||||
assertEquals(copy.scripts.worldgen, undefined, "players get the world from the server, not its generator");
|
||||
assertEquals(copy.scripts.shared, mod.mod.scripts.shared, "players run the shared rules too");
|
||||
assertEquals(
|
||||
copy.script,
|
||||
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: [] };
|
||||
@@ -131,7 +132,6 @@ Deno.test("the server loads every .cubi in its folder, dependencies first, and p
|
||||
assert(terrain.every((list) => list!.length > 0));
|
||||
}
|
||||
}
|
||||
assert(mods[1].mod.scripts.server, "the server still has it");
|
||||
|
||||
// the same mod twice, and a mod whose dependency isn't there
|
||||
Deno.copyFileSync(`${folder}/copper_tools.cubi`, `${folder}/copper_tools_again.cubi`);
|
||||
@@ -173,7 +173,7 @@ Deno.test("the host serves each mod's player copy by its hash, and a game made f
|
||||
}
|
||||
assertEquals((await host.handle(new Request("http://localhost/mods/nope.cubi"))).status, 404);
|
||||
|
||||
// the game worker loaded both mods, including the template's server script, and saves
|
||||
// the game worker loaded both mods, including the template's server phase, and saves
|
||||
await host.shutdown();
|
||||
const saved = JSON.parse(Deno.readTextFileSync(`${world}/level.json`));
|
||||
assertEquals(saved.seed, "mod-seed");
|
||||
@@ -193,7 +193,7 @@ Deno.test("a mod with its own deno.json is bundled with it", async () => {
|
||||
id: "project",
|
||||
name: "Project",
|
||||
version: "1.0.0",
|
||||
scripts: { server: "scripts/server.ts" },
|
||||
main: "scripts/server.ts",
|
||||
}),
|
||||
);
|
||||
// only the mod's own import map knows "lib/"
|
||||
@@ -201,13 +201,13 @@ Deno.test("a mod with its own deno.json is bundled with it", async () => {
|
||||
Deno.writeTextFileSync(`${mod}/scripts/lib/greeting.ts`, `export const GREETING = "hello from a deno project";\n`);
|
||||
Deno.writeTextFileSync(
|
||||
`${mod}/scripts/server.ts`,
|
||||
`import { GREETING } from "lib/greeting.ts";\n// deno-lint-ignore no-explicit-any\nexport function setup(ctx: any) {\n\tctx.log(GREETING);\n}\n`,
|
||||
`import { GREETING } from "lib/greeting.ts";\n// deno-lint-ignore no-explicit-any\nexport function server(ctx: any) {\n\tctx.log(GREETING);\n}\n`,
|
||||
);
|
||||
|
||||
const project = (await load_and_check(sources)).find((m) => m.id === "project")!;
|
||||
assertEquals(project.report.errors, []);
|
||||
const packed = read_mod(await pack_mod(project), "project.cubi");
|
||||
assertStringIncludes(packed.scripts.server!, "hello from a deno project");
|
||||
assertStringIncludes(packed.script!, "hello from a deno project");
|
||||
Deno.removeSync(sources, { recursive: true });
|
||||
});
|
||||
|
||||
@@ -438,7 +438,6 @@ Deno.test("a mod with only data packs and reads", () => {
|
||||
fluids: [],
|
||||
tags: [],
|
||||
},
|
||||
scripts: {},
|
||||
textures: new Map(),
|
||||
};
|
||||
assertEquals(read_mod(write_mod(mod), "tiny.cubi").manifest.id, "tiny");
|
||||
|
||||
Reference in New Issue
Block a user