Rename bmod to just mod
This commit is contained in:
@@ -8,7 +8,7 @@ import { GAME_VERSION } from "@/common/constants.ts";
|
||||
import { engine_version_problem, validate_manifest } from "@/common/mod_data.ts";
|
||||
import { ItemStack } from "@/common/inventory.ts";
|
||||
import { EverythingRegistry } from "@/common/everything_registry.ts";
|
||||
import { read_bmod } from "@/common/bmod.ts";
|
||||
import { read_mod } from "@/common/mod.ts";
|
||||
import { load_and_check } from "@/tools/check_mods.ts";
|
||||
import { pack_mod } from "@/tools/pack_mod.ts";
|
||||
import { load_client_mods } from "@/client/mods.ts";
|
||||
@@ -157,7 +157,7 @@ Deno.test({
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test("a client mod hooks LocalPlayer from its .bmod", async () => {
|
||||
Deno.test("a client mod hooks LocalPlayer from its .cubi", async () => {
|
||||
const dir = Deno.makeTempDirSync({ prefix: "bworld_engine_" });
|
||||
write_mod(dir, "floaty", {
|
||||
client: [
|
||||
@@ -175,7 +175,7 @@ Deno.test("a client mod hooks LocalPlayer from its .bmod", async () => {
|
||||
});
|
||||
const mod = load_and_check(dir)[0];
|
||||
assertEquals(mod.report.errors, []);
|
||||
const bmod = read_bmod(await pack_mod(mod), "floaty.bmod");
|
||||
const packed = read_mod(await pack_mod(mod), "floaty.cubi");
|
||||
const listing: ModListing = {
|
||||
id: "floaty",
|
||||
name: "floaty",
|
||||
@@ -186,7 +186,7 @@ Deno.test("a client mod hooks LocalPlayer from its .bmod", async () => {
|
||||
engine_access: true,
|
||||
};
|
||||
EverythingRegistry.clear();
|
||||
await load_client_mods([listing], [bmod]);
|
||||
await load_client_mods([listing], [packed]);
|
||||
|
||||
const client = { options: new Options(), level: {}, connection: { send() {} } };
|
||||
const player = new LocalPlayer(client as unknown as Client, "id", "alice");
|
||||
@@ -337,7 +337,7 @@ Deno.test("hook needs a loading mod with engine access", async () => {
|
||||
assertStringIncludes(String(import_error), `sneaky imports cubi/engine without "engine_access"`);
|
||||
});
|
||||
|
||||
Deno.test("cubi/engine without engine_access is an error in check-mods and in a .bmod", async () => {
|
||||
Deno.test("cubi/engine without engine_access is an error in check-mods and in a .cubi", async () => {
|
||||
const dir = Deno.makeTempDirSync({ prefix: "bworld_engine_" });
|
||||
const script = `import { engine } from "cubi/engine";
|
||||
export function setup() {
|
||||
@@ -351,7 +351,7 @@ Deno.test("cubi/engine without engine_access is an error in check-mods and in a
|
||||
|
||||
// packed anyway, the bundle gives it away
|
||||
const bytes = await pack_mod(mod);
|
||||
assertThrows(() => read_bmod(bytes, "sneaky.bmod"), Error, "a script uses cubi/engine");
|
||||
assertThrows(() => read_mod(bytes, "sneaky.cubi"), Error, "a script uses cubi/engine");
|
||||
Deno.removeSync(dir, { recursive: true });
|
||||
});
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import { EverythingRegistry } from "@/common/everything_registry.ts";
|
||||
import type { FluidJson } from "@/common/mod_data.ts";
|
||||
import type { ModListing } from "@/common/mod_loader.ts";
|
||||
import type { FluidApi } from "@/common/mod_api/shared.ts";
|
||||
import { read_bmod } from "@/common/bmod.ts";
|
||||
import { read_mod } from "@/common/mod.ts";
|
||||
import { register_mod_data } from "@/common/mod_loader.ts";
|
||||
import { load_client_mods } from "@/client/mods.ts";
|
||||
import { fluid_rules } from "@/client/fluid_rules.ts";
|
||||
@@ -38,7 +38,7 @@ function fluid_mod(dir: string, fluids: Record<string, unknown>, shared_script?:
|
||||
}
|
||||
}
|
||||
|
||||
Deno.test("a mod's fluids/ file registers a fluid, packed into its .bmod", async () => {
|
||||
Deno.test("a mod's fluids/ file registers a fluid, packed into its .cubi", async () => {
|
||||
const dir = Deno.makeTempDirSync({ prefix: "bworld_fluids_" });
|
||||
const syrup = { id: "testfluids:syrup", name: "Maple Syrup", color: "#a0522d", texture: "testfluids:syrup_still" };
|
||||
fluid_mod(dir, { "syrup.json": syrup });
|
||||
@@ -48,9 +48,9 @@ Deno.test("a mod's fluids/ file registers a fluid, packed into its .bmod", async
|
||||
assertEquals(mods[0].report.warnings, [
|
||||
"fluids/syrup.json: texture testfluids:syrup_still doesn't exist, it will show as missing",
|
||||
]);
|
||||
const bmod = read_bmod(await pack_mod(mods[0]), "testfluids.bmod");
|
||||
const mod = read_mod(await pack_mod(mods[0]), "testfluids.cubi");
|
||||
EverythingRegistry.clear();
|
||||
register_mod_data([{ id: "testfluids", data: bmod.data }]);
|
||||
register_mod_data([{ id: "testfluids", data: mod.data }]);
|
||||
assertEquals(EverythingRegistry.get<FluidJson>("fluids", "testfluids:syrup"), syrup);
|
||||
Deno.removeSync(dir, { recursive: true });
|
||||
});
|
||||
@@ -87,11 +87,11 @@ async function both_sides(ask: (fluids: FluidApi) => unknown) {
|
||||
const server = ask(game.mods.fluid_rules.api());
|
||||
|
||||
const mod = load_and_check(dir).find((m) => m.id === "testfluids")!;
|
||||
const bmod = read_bmod(await pack_mod(mod), "testfluids.bmod");
|
||||
const packed = read_mod(await pack_mod(mod), "testfluids.cubi");
|
||||
Deno.removeSync(dir, { recursive: true });
|
||||
const listing: ModListing = { id: "testfluids", name: "Test", version: "1.0.0", sha256: "", file: "", size: 0 };
|
||||
EverythingRegistry.clear();
|
||||
await load_client_mods([listing], [bmod]);
|
||||
await load_client_mods([listing], [packed]);
|
||||
return { server, client: ask(fluid_rules.api()) };
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -8,7 +8,7 @@ import { mod_data } from "@/common/mod_check.ts";
|
||||
import type { ServerModSource } from "@/server/game/load_mods.ts";
|
||||
import { GameServer } from "@/server/game/game_server.ts";
|
||||
import { start_game } from "@/server/game/load_mods.ts";
|
||||
import { apply_config } from "@/server/load_bmods.ts";
|
||||
import { apply_config } from "@/server/load_mods.ts";
|
||||
import { AIR_ID, PROTOCOL_VERSION } from "@/common/protocol.ts";
|
||||
import { decode_level_chunk } from "@/common/chunk_streaming.ts";
|
||||
import { CHUNK_AREA, CHUNK_SIZE, ID_MASK } from "@/common/constants.ts";
|
||||
@@ -45,7 +45,7 @@ function read_mod_sources(mods_dir: string): ServerModSource[] {
|
||||
name: String(mod.manifest?.name),
|
||||
version: String(mod.manifest?.version),
|
||||
sha256: "source",
|
||||
file: `mods/${mod.id}.bmod`,
|
||||
file: `mods/${mod.id}.cubi`,
|
||||
size: 0,
|
||||
...(mod.manifest?.engine_access === true ? { engine_access: true } : {}),
|
||||
},
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
// mods' config.json: their settings, which servers and tests can change, see docs/modding/misc/config.md
|
||||
import { assert, assertEquals, assertRejects } from "@std/assert";
|
||||
import { read_bmod, write_bmod } from "@/common/bmod.ts";
|
||||
import { read_mod, write_mod } from "@/common/mod.ts";
|
||||
import type { ModData } from "@/common/mod_loader.ts";
|
||||
import { apply_config, load_bmods } from "@/server/load_bmods.ts";
|
||||
import { apply_config, load_mods } from "@/server/load_mods.ts";
|
||||
import { load_and_check } from "@/tools/check_mods.ts";
|
||||
import { create_mod } from "@/tools/new_mod.ts";
|
||||
import { copy_dir, test_game } from "./helpers.ts";
|
||||
@@ -90,22 +90,22 @@ Deno.test("a server changes a mod's settings with config/<mod id>.json, and play
|
||||
Deno.mkdirSync(`${dir}/server_mods`);
|
||||
Deno.mkdirSync(`${dir}/config`);
|
||||
Deno.writeFileSync(
|
||||
`${dir}/server_mods/tiny.bmod`,
|
||||
write_bmod({
|
||||
`${dir}/server_mods/tiny.cubi`,
|
||||
write_mod({
|
||||
manifest: { format_version: 1, id: "tiny", name: "Tiny", version: "1.0.0" },
|
||||
data,
|
||||
scripts: {},
|
||||
textures: new Map(),
|
||||
}),
|
||||
);
|
||||
const config_of = async () => (await load_bmods(`${dir}/server_mods`, [], `${dir}/config`))[0].bmod.data.config;
|
||||
const config_of = async () => (await load_mods(`${dir}/server_mods`, [], `${dir}/config`))[0].mod.data.config;
|
||||
|
||||
assertEquals(await config_of(), data.config, "without a file, the mod's own");
|
||||
|
||||
Deno.writeTextFileSync(`${dir}/config/tiny.json`, config_file({ ore: { depth: 50 } }));
|
||||
assertEquals(await config_of(), { speed: 16, ore: { size: 4, depth: 50 } });
|
||||
const [mod] = await load_bmods(`${dir}/server_mods`, [], `${dir}/config`);
|
||||
assertEquals(read_bmod(mod.client_bytes, mod.listing.file).data.config, undefined);
|
||||
const [mod] = await load_mods(`${dir}/server_mods`, [], `${dir}/config`);
|
||||
assertEquals(read_mod(mod.client_bytes, mod.listing.file).data.config, undefined);
|
||||
|
||||
Deno.writeTextFileSync(`${dir}/config/tiny.json`, config_file({ ore: { depht: 50 } }));
|
||||
await assertRejects(config_of, Error, "ore.depht");
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// .bmod files: packing mods, reading them back, and the server loading a folder of them
|
||||
// .cubi files: packing mods, reading them back, and the server loading a folder of them
|
||||
import { assert, assertEquals, assertRejects, assertStringIncludes, assertThrows } from "@std/assert";
|
||||
import { zipSync } from "fflate";
|
||||
import { ATLAS_BORDER, atlas_layout, extrude_borders } from "@/client/atlas.ts";
|
||||
import { MAX_TEXTURE_SIZE } from "@/common/constants.ts";
|
||||
import { type Bmod, read_bmod, write_bmod } from "@/common/bmod.ts";
|
||||
import { type Mod, read_mod, write_mod } from "@/common/mod.ts";
|
||||
import { load_and_check } from "@/tools/check_mods.ts";
|
||||
import { pack_mod } from "@/tools/pack_mod.ts";
|
||||
import { create_mod } from "@/tools/new_mod.ts";
|
||||
import { load_bmods } from "@/server/load_bmods.ts";
|
||||
import { load_mods } from "@/server/load_mods.ts";
|
||||
import { start_host } from "@/server/host.ts";
|
||||
import { copy_dir } from "./helpers.ts";
|
||||
import { PROTOCOL_VERSION } from "@/common/protocol.ts";
|
||||
@@ -20,35 +20,35 @@ import { list_chunks, read_chunk, write_chunks } from "@/server/regions.ts";
|
||||
|
||||
const ENGINE_TEXTURES = ["cubi:missing", ...Array.from({ length: 9 }, (_, i) => `cubi:break_${i}`)];
|
||||
|
||||
// mods/bworld and one made from the template, packed into a folder of .bmod files
|
||||
// mods/bworld and one made from the template, packed into a folder of .cubi files
|
||||
async function packed_mods() {
|
||||
const sources = Deno.makeTempDirSync({ prefix: "bworld_bmod_src_" });
|
||||
const sources = Deno.makeTempDirSync({ prefix: "bworld_mod_src_" });
|
||||
copy_dir("mods/bworld", `${sources}/bworld`);
|
||||
create_mod("copper_tools", "Copper Tools", sources);
|
||||
const mods = load_and_check(sources);
|
||||
for (const mod of mods) assertEquals(mod.report.errors, [], mod.id);
|
||||
|
||||
const folder = Deno.makeTempDirSync({ prefix: "bworld_bmod_" });
|
||||
for (const mod of mods) Deno.writeFileSync(`${folder}/${mod.id}.bmod`, await pack_mod(mod));
|
||||
const folder = Deno.makeTempDirSync({ prefix: "bworld_mod_" });
|
||||
for (const mod of mods) Deno.writeFileSync(`${folder}/${mod.id}.cubi`, await pack_mod(mod));
|
||||
return { sources, folder, mods };
|
||||
}
|
||||
|
||||
Deno.test("packing a mod keeps its data, scripts, 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.bmod`);
|
||||
const bytes = Deno.readFileSync(`${folder}/copper_tools.cubi`);
|
||||
assertEquals(await pack_mod(template), bytes);
|
||||
|
||||
const bmod = read_bmod(bytes, "copper_tools.bmod");
|
||||
assertEquals(bmod.manifest.id, "copper_tools");
|
||||
assertEquals(bmod.data.blocks.map((b) => b.id), template.blocks.map((b) => b.json.id));
|
||||
assertEquals(bmod.data.recipes, template.recipes.map((r) => r.json));
|
||||
assertEquals([...bmod.textures.keys()].sort(), [...template.textures].sort());
|
||||
assertEquals(Object.keys(bmod.scripts).sort(), ["client", "server", "worldgen"]);
|
||||
assertStringIncludes(bmod.scripts.server!, "setup");
|
||||
assert(bmod.credits);
|
||||
const mod = read_mod(bytes, "copper_tools.cubi");
|
||||
assertEquals(mod.manifest.id, "copper_tools");
|
||||
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");
|
||||
assert(mod.credits);
|
||||
|
||||
const bworld = read_bmod(Deno.readFileSync(`${folder}/bworld.bmod`), "bworld.bmod");
|
||||
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"]);
|
||||
|
||||
@@ -56,33 +56,33 @@ Deno.test("packing a mod keeps its data, scripts, textures and credits, and give
|
||||
Deno.removeSync(folder, { recursive: true });
|
||||
});
|
||||
|
||||
Deno.test("broken .bmod files are turned away, saying why", () => {
|
||||
Deno.test("broken .cubi files are turned away, saying why", () => {
|
||||
const text = (value: unknown) => new TextEncoder().encode(JSON.stringify(value));
|
||||
const manifest = { format_version: 1, id: "broken", name: "Broken", version: "1.0.0" };
|
||||
const zip = (files: Record<string, Uint8Array>) => zipSync(files);
|
||||
|
||||
assertThrows(() => read_bmod(new TextEncoder().encode("not a zip"), "a.bmod"), Error, "isn't a readable .bmod");
|
||||
assertThrows(() => read_bmod(zip({ "data.json": text({}) }), "b.bmod"), Error, "manifest.json is missing");
|
||||
assertThrows(() => read_mod(new TextEncoder().encode("not a zip"), "a.cubi"), Error, "isn't a readable .cubi");
|
||||
assertThrows(() => read_mod(zip({ "data.json": text({}) }), "b.cubi"), Error, "manifest.json is missing");
|
||||
assertThrows(
|
||||
() =>
|
||||
read_bmod(
|
||||
read_mod(
|
||||
zip({
|
||||
"manifest.json": text(manifest),
|
||||
"data.json": text({ blocks: [{ id: "other:thing", textures: "broken:x" }, { id: "broken:y" }] }),
|
||||
}),
|
||||
"c.bmod",
|
||||
"c.cubi",
|
||||
),
|
||||
Error,
|
||||
"other:thing isn't in this mod's namespace",
|
||||
);
|
||||
assertThrows(
|
||||
() =>
|
||||
read_bmod(
|
||||
read_mod(
|
||||
zip({
|
||||
"manifest.json": text({ ...manifest, scripts: { server: "scripts/server.js" } }),
|
||||
"data.json": text({}),
|
||||
}),
|
||||
"d.bmod",
|
||||
"d.cubi",
|
||||
),
|
||||
Error,
|
||||
"scripts.server scripts/server.js isn't in the file",
|
||||
@@ -94,9 +94,9 @@ Deno.test("broken .bmod files are turned away, saying why", () => {
|
||||
new DataView(big.buffer).setUint32(20, 16);
|
||||
assertThrows(
|
||||
() =>
|
||||
read_bmod(
|
||||
read_mod(
|
||||
zip({ "manifest.json": text(manifest), "data.json": text({}), "textures/big.png": big }),
|
||||
"e.bmod",
|
||||
"e.cubi",
|
||||
),
|
||||
Error,
|
||||
`textures can be at most ${MAX_TEXTURE_SIZE}×${MAX_TEXTURE_SIZE}`,
|
||||
@@ -104,46 +104,46 @@ Deno.test("broken .bmod files are turned away, saying why", () => {
|
||||
// too much once unzipped, without unzipping it all
|
||||
const huge = new Uint8Array(65 * 1024 * 1024);
|
||||
assertThrows(
|
||||
() => read_bmod(zip({ "manifest.json": text(manifest), "data.json": text({}), "big.bin": huge }), "f.bmod"),
|
||||
() => read_mod(zip({ "manifest.json": text(manifest), "data.json": text({}), "big.bin": huge }), "f.cubi"),
|
||||
Error,
|
||||
"unzips to more than",
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("the server loads every .bmod 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 server scripts", async () => {
|
||||
const { sources, folder } = await packed_mods();
|
||||
const mods = await load_bmods(folder, ENGINE_TEXTURES);
|
||||
const mods = await load_mods(folder, ENGINE_TEXTURES);
|
||||
assertEquals(mods.map((mod) => mod.listing.id), ["bworld", "copper_tools"]);
|
||||
|
||||
for (const mod of mods) {
|
||||
assertEquals(mod.listing.file, `mods/${mod.listing.sha256}.bmod`);
|
||||
assertEquals(mod.listing.file, `mods/${mod.listing.sha256}.cubi`);
|
||||
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_bmod(mod.client_bytes, mod.listing.file);
|
||||
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.bmod.scripts.shared, "players run the shared rules too");
|
||||
assertEquals(copy.scripts.shared, mod.mod.scripts.shared, "players run the shared rules too");
|
||||
// the terrain's data stays on the server too, the rest is the same
|
||||
const { noises, density_functions, noise_settings, biome_sources, ...data } = mod.bmod.data;
|
||||
const { noises, density_functions, noise_settings, biome_sources, ...data } = mod.mod.data;
|
||||
assertEquals(copy.data, { ...data, noises: [], density_functions: [], noise_settings: [], biome_sources: [] });
|
||||
if (mod.listing.id === "bworld") {
|
||||
assert([noises, density_functions, noise_settings, biome_sources].every((list) => list!.length > 0));
|
||||
}
|
||||
}
|
||||
assert(mods[1].bmod.scripts.server, "the server still has it");
|
||||
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.bmod`, `${folder}/copper_tools_again.bmod`);
|
||||
await assertRejects(() => load_bmods(folder, ENGINE_TEXTURES), Error, 'are both the mod "copper_tools"');
|
||||
Deno.removeSync(`${folder}/copper_tools_again.bmod`);
|
||||
Deno.removeSync(`${folder}/bworld.bmod`);
|
||||
await assertRejects(() => load_bmods(folder, ENGINE_TEXTURES), Error, `depends on "bworld"`);
|
||||
Deno.copyFileSync(`${folder}/copper_tools.cubi`, `${folder}/copper_tools_again.cubi`);
|
||||
await assertRejects(() => load_mods(folder, ENGINE_TEXTURES), Error, 'are both the mod "copper_tools"');
|
||||
Deno.removeSync(`${folder}/copper_tools_again.cubi`);
|
||||
Deno.removeSync(`${folder}/bworld.cubi`);
|
||||
await assertRejects(() => load_mods(folder, ENGINE_TEXTURES), Error, `depends on "bworld"`);
|
||||
|
||||
Deno.removeSync(sources, { recursive: true });
|
||||
Deno.removeSync(folder, { recursive: true });
|
||||
});
|
||||
|
||||
Deno.test("the host serves each mod's player copy by its hash, and a game made from .bmod files plays", async () => {
|
||||
Deno.test("the host serves each mod's player copy by its hash, and a game made from .cubi files plays", async () => {
|
||||
const { sources, folder } = await packed_mods();
|
||||
const build = Deno.makeTempDirSync({ prefix: "bworld_build_" });
|
||||
Deno.mkdirSync(`${build}/assets/textures`, { recursive: true });
|
||||
@@ -157,31 +157,31 @@ Deno.test("the host serves each mod's player copy by its hash, and a game made f
|
||||
build_dir: build,
|
||||
server_mods_dir: folder,
|
||||
world_dir: world,
|
||||
seed: "bmod-seed",
|
||||
seed: "mod-seed",
|
||||
on_fatal: (message) => {
|
||||
throw new Error(message);
|
||||
},
|
||||
});
|
||||
const listings = (await load_bmods(folder, ENGINE_TEXTURES)).map((mod) => mod.listing);
|
||||
const listings = (await load_mods(folder, ENGINE_TEXTURES)).map((mod) => mod.listing);
|
||||
for (const listing of listings) {
|
||||
const response = await host.handle(new Request(`http://localhost/${listing.file}`));
|
||||
assertEquals(response.status, 200);
|
||||
assertEquals(response.headers.get("access-control-allow-origin"), "*");
|
||||
const bmod = read_bmod(new Uint8Array(await response.arrayBuffer()), listing.file);
|
||||
assertEquals(bmod.manifest.id, listing.id);
|
||||
const mod = read_mod(new Uint8Array(await response.arrayBuffer()), listing.file);
|
||||
assertEquals(mod.manifest.id, listing.id);
|
||||
}
|
||||
assertEquals((await host.handle(new Request("http://localhost/mods/nope.bmod"))).status, 404);
|
||||
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
|
||||
await host.shutdown();
|
||||
const saved = JSON.parse(Deno.readTextFileSync(`${world}/level.json`));
|
||||
assertEquals(saved.seed, "bmod-seed");
|
||||
assertEquals(saved.seed, "mod-seed");
|
||||
|
||||
for (const dir of [sources, folder, build]) Deno.removeSync(dir, { recursive: true });
|
||||
});
|
||||
|
||||
Deno.test("a mod with its own deno.json is bundled with it", async () => {
|
||||
const sources = Deno.makeTempDirSync({ prefix: "bworld_bmod_project_" });
|
||||
const sources = Deno.makeTempDirSync({ prefix: "bworld_mod_project_" });
|
||||
copy_dir("mods/bworld", `${sources}/bworld`);
|
||||
const mod = `${sources}/project`;
|
||||
Deno.mkdirSync(`${mod}/scripts/lib`, { recursive: true });
|
||||
@@ -205,8 +205,8 @@ Deno.test("a mod with its own deno.json is bundled with it", async () => {
|
||||
|
||||
const project = load_and_check(sources).find((m) => m.id === "project")!;
|
||||
assertEquals(project.report.errors, []);
|
||||
const bmod = read_bmod(await pack_mod(project), "project.bmod");
|
||||
assertStringIncludes(bmod.scripts.server!, "hello from a deno project");
|
||||
const packed = read_mod(await pack_mod(project), "project.cubi");
|
||||
assertStringIncludes(packed.scripts.server!, "hello from a deno project");
|
||||
Deno.removeSync(sources, { recursive: true });
|
||||
});
|
||||
|
||||
@@ -415,9 +415,9 @@ Deno.test({
|
||||
},
|
||||
});
|
||||
|
||||
// write_bmod without anything optional still makes a file read_bmod takes
|
||||
// write_mod without anything optional still makes a file read_mod takes
|
||||
Deno.test("a mod with only data packs and reads", () => {
|
||||
const bmod: Bmod = {
|
||||
const mod: Mod = {
|
||||
manifest: { format_version: 1, id: "tiny", name: "Tiny", version: "1.0.0" },
|
||||
data: {
|
||||
blocks: [],
|
||||
@@ -435,5 +435,5 @@ Deno.test("a mod with only data packs and reads", () => {
|
||||
scripts: {},
|
||||
textures: new Map(),
|
||||
};
|
||||
assertEquals(read_bmod(write_bmod(bmod), "tiny.bmod").manifest.id, "tiny");
|
||||
assertEquals(read_mod(write_mod(mod), "tiny.cubi").manifest.id, "tiny");
|
||||
});
|
||||
@@ -6,7 +6,7 @@
|
||||
import { assert, assertEquals, assertRejects } from "@std/assert";
|
||||
import { EverythingRegistry } from "@/common/everything_registry.ts";
|
||||
import type { ModListing } from "@/common/mod_loader.ts";
|
||||
import { read_bmod } from "@/common/bmod.ts";
|
||||
import { read_mod } from "@/common/mod.ts";
|
||||
import { load_client_mods } from "@/client/mods.ts";
|
||||
import { load_order } from "@/common/mod_check.ts";
|
||||
import { load_and_check } from "@/tools/check_mods.ts";
|
||||
@@ -89,11 +89,11 @@ const seen = globalThis as unknown as Record<string, unknown>;
|
||||
async function load_client(dir: string) {
|
||||
const mod = load_and_check(dir).find((m) => m.id === "testrecipes")!;
|
||||
assertEquals(mod.report.errors, []);
|
||||
const bmod = read_bmod(await pack_mod(mod), "testrecipes.bmod");
|
||||
const packed = read_mod(await pack_mod(mod), "testrecipes.cubi");
|
||||
Deno.removeSync(dir, { recursive: true });
|
||||
const listing: ModListing = { id: "testrecipes", name: "Test", version: "1.0.0", sha256: "", file: "", size: 0 };
|
||||
EverythingRegistry.clear();
|
||||
await load_client_mods([listing], [bmod]);
|
||||
await load_client_mods([listing], [packed]);
|
||||
}
|
||||
|
||||
Deno.test("recipes a shared script registers are on the server and clients, for their scripts and crafting", async () => {
|
||||
@@ -223,7 +223,7 @@ Deno.test("recipes can only be registered while shared scripts set up", async ()
|
||||
|
||||
Deno.test("every mod's recipe types are registered on a client too, so it loads them", async () => {
|
||||
const mods = load_order(load_and_check("mods"));
|
||||
const bmods = await Promise.all(mods.map(async (mod) => read_bmod(await pack_mod(mod), `${mod.id}.bmod`)));
|
||||
const packed = await Promise.all(mods.map(async (mod) => read_mod(await pack_mod(mod), `${mod.id}.cubi`)));
|
||||
const listings = mods.map((mod): ModListing => ({
|
||||
id: mod.id,
|
||||
name: mod.id,
|
||||
@@ -233,5 +233,5 @@ Deno.test("every mod's recipe types are registered on a client too, so it loads
|
||||
size: 0,
|
||||
}));
|
||||
EverythingRegistry.clear();
|
||||
await load_client_mods(listings, bmods);
|
||||
await load_client_mods(listings, packed);
|
||||
});
|
||||
|
||||
+4
-4
@@ -9,7 +9,7 @@ import { type BlockRegistry, EverythingRegistry } from "@/common/everything_regi
|
||||
import type { ManifestJson, TagJson } from "@/common/mod_data.ts";
|
||||
import { resolve_tags, tag_api, type TagSource } from "@/common/tags.ts";
|
||||
import { can_stand_on } from "@/common/utils.ts";
|
||||
import { read_bmod, write_bmod } from "@/common/bmod.ts";
|
||||
import { read_mod, write_mod } from "@/common/mod.ts";
|
||||
import { update_crafting_result } from "@/server/game/crafting.ts";
|
||||
import { check_mods } from "@/tools/check_mods.ts";
|
||||
import { copy_dir, test_game } from "./helpers.ts";
|
||||
@@ -208,7 +208,7 @@ Deno.test("check-mods finds broken tags and tags nobody defines", async () => {
|
||||
Deno.removeSync(dir, { recursive: true });
|
||||
});
|
||||
|
||||
Deno.test("tags survive packing into a .bmod", () => {
|
||||
Deno.test("tags survive packing into a .cubi", () => {
|
||||
const tag: TagJson = { registry: "items", id: "c:ingots/tin", values: ["x:tin", { id: "y:tin", required: false }] };
|
||||
const data = {
|
||||
blocks: [],
|
||||
@@ -224,6 +224,6 @@ Deno.test("tags survive packing into a .bmod", () => {
|
||||
tags: [tag],
|
||||
};
|
||||
const manifest: ManifestJson = { format_version: 1, id: "x", name: "X", version: "1.0.0" };
|
||||
const bmod = read_bmod(write_bmod({ manifest, data, scripts: {}, textures: new Map() }), "x.bmod");
|
||||
assertEquals(bmod.data.tags, [tag]);
|
||||
const mod = read_mod(write_mod({ manifest, data, scripts: {}, textures: new Map() }), "x.cubi");
|
||||
assertEquals(mod.data.tags, [tag]);
|
||||
});
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// animated textures: textures/<name>.json, carrying it through .bmod files, and playing it a tick at a time
|
||||
// animated textures: textures/<name>.json, carrying it through .cubi files, and playing it a tick at a time
|
||||
import { assertEquals, assertThrows } from "@std/assert";
|
||||
import { zipSync } from "fflate";
|
||||
import { read_bmod, texture_size_problem } from "@/common/bmod.ts";
|
||||
import { read_mod, texture_size_problem } from "@/common/mod.ts";
|
||||
import { texture_animation, validate_texture_json } from "@/common/texture_animation.ts";
|
||||
import { AnimatedTexture } from "@/client/texture_animations.ts";
|
||||
import { load_and_check } from "@/tools/check_mods.ts";
|
||||
@@ -70,7 +70,7 @@ Deno.test("an animated texture's frames have to fit the size limit, not its whol
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("a texture's .json is checked, packed into the .bmod and read back", async () => {
|
||||
Deno.test("a texture's .json is checked, packed into the .cubi and read back", async () => {
|
||||
const sources = Deno.makeTempDirSync({ prefix: "bworld_anim_src_" });
|
||||
copy_dir("mods/bworld", `${sources}/bworld`);
|
||||
create_mod("lava_lamps", "Lava Lamps", sources);
|
||||
@@ -83,8 +83,8 @@ Deno.test("a texture's .json is checked, packed into the .bmod and read back", a
|
||||
const lamps = () => load_and_check(sources).find((m) => m.id === "lava_lamps")!;
|
||||
const mod = lamps();
|
||||
assertEquals(mod.report.errors, []);
|
||||
const bmod = read_bmod(await pack_mod(mod), "lava_lamps.bmod");
|
||||
assertEquals([...bmod.texture_json!], [["lava_lamps:lamps_goo", json]]);
|
||||
const packed = read_mod(await pack_mod(mod), "lava_lamps.cubi");
|
||||
assertEquals([...packed.texture_json!], [["lava_lamps:lamps_goo", json]]);
|
||||
|
||||
// a .json without its png, or one that doesn't fit it, is an error
|
||||
Deno.writeTextFileSync(`${textures}/stray.json`, JSON.stringify(json));
|
||||
@@ -103,14 +103,14 @@ Deno.test("a texture's .json is checked, packed into the .bmod and read back", a
|
||||
const manifest = { format_version: 1, id: "broken", name: "Broken", version: "1.0.0" };
|
||||
assertThrows(
|
||||
() =>
|
||||
read_bmod(
|
||||
read_mod(
|
||||
zipSync({
|
||||
"manifest.json": text(manifest),
|
||||
"data.json": text({}),
|
||||
"textures/goo.png": png_header(16, 32),
|
||||
"textures/goo.json": text({ animation: { frames: [2] } }),
|
||||
}),
|
||||
"broken.bmod",
|
||||
"broken.cubi",
|
||||
),
|
||||
Error,
|
||||
"textures/goo.json: animation.frames[0] isn't one of the png's frames, 0 to 1",
|
||||
|
||||
@@ -9,7 +9,7 @@ import { BlockRegistry, EverythingRegistry } from "@/common/everything_registry.
|
||||
import { CHUNK_AREA, CHUNK_HEIGHT, CHUNK_SIZE } from "@/common/constants.ts";
|
||||
import { block_value } from "@/common/utils.ts";
|
||||
import type { ModListing } from "@/common/mod_loader.ts";
|
||||
import { read_bmod } from "@/common/bmod.ts";
|
||||
import { read_mod } from "@/common/mod.ts";
|
||||
import type { FluidInstance, Instances, RotatingInstance, Visual } from "@/common/mod_api/client.ts";
|
||||
import { block_visuals, instance_quads, InstanceGroup, pack_model, Visuals } from "@/client/rendering/visuals.ts";
|
||||
import { INSTANCE_FLOATS, INSTANCED_BUFFERS, terrain_shader_src, type Texture } from "@/client/renderer/mod.ts";
|
||||
@@ -492,11 +492,11 @@ Deno.test("client scripts register visuals during setup, for blocks that exist",
|
||||
const dir = Deno.makeTempDirSync({ prefix: "bworld_visuals_" });
|
||||
write_testmod(dir, script);
|
||||
const mod = load_and_check(dir)[0];
|
||||
const bmod = read_bmod(await pack_mod(mod), "testmod.bmod");
|
||||
const packed = read_mod(await pack_mod(mod), "testmod.cubi");
|
||||
Deno.removeSync(dir, { recursive: true });
|
||||
const listing: ModListing = { id: "testmod", name: "Test", version: "1.0.0", sha256: "", file: "", size: 0 };
|
||||
EverythingRegistry.clear();
|
||||
await load_client_mods([listing], [bmod]);
|
||||
await load_client_mods([listing], [packed]);
|
||||
};
|
||||
await load(`
|
||||
import type { ClientContext } from "cubi/client";
|
||||
|
||||
Reference in New Issue
Block a user