Fluid registry

This commit is contained in:
2026-10-25 14:05:57 -03:00
parent 0cfa4d9b4a
commit 17d83acfc8
18 changed files with 144 additions and 17 deletions
+1
View File
@@ -429,6 +429,7 @@ Deno.test("a mod with only data packs and reads", () => {
entities: [],
entity_models: [],
effects: [],
fluids: [],
tags: [],
},
scripts: {},
+43
View File
@@ -0,0 +1,43 @@
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
// SPDX-License-Identifier: AGPL-3.0-or-later
import { assert, assertEquals } from "@std/assert";
import { EverythingRegistry } from "$/common/everything_registry.ts";
import type { FluidJson } from "$/common/mod_data.ts";
import { read_bmod } from "$/common/bmod.ts";
import { register_mod_data } from "$/common/mod_loader.ts";
import { load_and_check } from "$/tools/check_mods.ts";
import { pack_mod } from "$/tools/pack_mod.ts";
// a mod with only a manifest and the given fluids/ files, by file name
function fluid_mod(fluids: Record<string, unknown>) {
const dir = Deno.makeTempDirSync({ prefix: "bworld_fluids_" });
Deno.mkdirSync(`${dir}/testfluids/fluids`, { recursive: true });
Deno.writeTextFileSync(
`${dir}/testfluids/manifest.json`,
JSON.stringify({ format_version: 1, id: "testfluids", name: "Test Fluids", version: "1.0.0" }),
);
for (const [file, fluid] of Object.entries(fluids)) {
Deno.writeTextFileSync(`${dir}/testfluids/fluids/${file}`, JSON.stringify({ format_version: 1, fluid }));
}
return dir;
}
Deno.test("a mod's fluids/ file registers a fluid, packed into its .bmod", async () => {
const syrup = { id: "testfluids:syrup", name: "Maple Syrup", color: "#a0522d" };
const dir = fluid_mod({ "syrup.json": syrup });
const mods = load_and_check(dir);
assertEquals(mods[0].report.errors, []);
const bmod = read_bmod(await pack_mod(mods[0]), "testfluids.bmod");
EverythingRegistry.clear();
register_mod_data([{ id: "testfluids", data: bmod.data }]);
assertEquals(EverythingRegistry.get<FluidJson>("fluids", "testfluids:syrup"), syrup);
Deno.removeSync(dir, { recursive: true });
});
Deno.test("a fluid with a bad color fails loading", () => {
const dir = fluid_mod({ "syrup.json": { id: "testfluids:syrup", color: "brown" } });
const errors = load_and_check(dir)[0].report.errors;
assert(errors.some((e) => e.startsWith("fluids/syrup.json:") && e.includes("color")), errors.join("\n"));
Deno.removeSync(dir, { recursive: true });
});
+1
View File
@@ -83,6 +83,7 @@ Deno.test("a server changes a mod's settings with config/<mod id>.json, and play
entities: [],
entity_models: [],
effects: [],
fluids: [],
tags: [],
config: { speed: 16, ore: { size: 4, depth: 30 } },
};
+1
View File
@@ -215,6 +215,7 @@ Deno.test("tags survive packing into a .bmod", () => {
entities: [],
entity_models: [],
effects: [],
fluids: [],
tags: [tag],
};
const manifest: ManifestJson = { format_version: 1, id: "x", name: "X", version: "1.0.0" };