Change imports
This commit is contained in:
+24
-24
@@ -1,21 +1,21 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// engine access: mods importing bworld/engine and hooking the engine's methods. see docs/modding/misc/engine.md
|
||||
// engine access: mods importing cubi/engine and hooking the engine's methods. see docs/modding/misc/engine.md
|
||||
import { assert, assertEquals, assertStringIncludes, assertThrows } from "@std/assert";
|
||||
import { clear_hooks, expose_engine, hook, loading_mod } from "$/common/hooks.ts";
|
||||
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 { load_and_check } from "$/tools/check_mods.ts";
|
||||
import { pack_mod } from "$/tools/pack_mod.ts";
|
||||
import { load_client_mods } from "$/client/mods.ts";
|
||||
import { LocalPlayer } from "$/client/entity/local_player.ts";
|
||||
import { Options } from "$/client/options.ts";
|
||||
import type { Client } from "$/client/client.ts";
|
||||
import type { ModListing } from "$/common/mod_loader.ts";
|
||||
import { clear_hooks, expose_engine, hook, loading_mod } from "@/common/hooks.ts";
|
||||
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 { load_and_check } from "@/tools/check_mods.ts";
|
||||
import { pack_mod } from "@/tools/pack_mod.ts";
|
||||
import { load_client_mods } from "@/client/mods.ts";
|
||||
import { LocalPlayer } from "@/client/entity/local_player.ts";
|
||||
import { Options } from "@/client/options.ts";
|
||||
import type { Client } from "@/client/client.ts";
|
||||
import type { ModListing } from "@/common/mod_loader.ts";
|
||||
import { copy_dir, test_game } from "./helpers.ts";
|
||||
import { game_with_pool } from "./chunk_loading.ts";
|
||||
|
||||
@@ -83,7 +83,7 @@ Deno.test("a server mod hooks GameServer to drop twice, like the plan's example"
|
||||
write_mod(dir, "double_drops", {
|
||||
server: [
|
||||
"server.ts",
|
||||
`import { engine, hook } from "bworld/engine";
|
||||
`import { engine, hook } from "cubi/engine";
|
||||
export function setup() {
|
||||
hook(engine.server.GameServer.prototype, "pop_item", {
|
||||
after(game, [x, y, z, stack], entity) {
|
||||
@@ -108,7 +108,7 @@ Deno.test("a worldgen mod hooks the terrain in engine.common", async () => {
|
||||
write_mod(dir, "flat_sea", {
|
||||
worldgen: [
|
||||
"worldgen.ts",
|
||||
`import { engine, hook } from "bworld/engine";
|
||||
`import { engine, hook } from "cubi/engine";
|
||||
// no ground anywhere, so it's all sea
|
||||
export function setup() {
|
||||
hook(engine.common.OverworldTerrain.prototype, "density", { replace: () => -1 });
|
||||
@@ -134,7 +134,7 @@ Deno.test({
|
||||
write_mod(dir, "flat_sea", {
|
||||
worldgen: [
|
||||
"worldgen.ts",
|
||||
`import { engine, hook } from "bworld/engine";
|
||||
`import { engine, hook } from "cubi/engine";
|
||||
export function setup() {
|
||||
hook(engine.common.OverworldTerrain.prototype, "density", { replace: () => -1 });
|
||||
}`,
|
||||
@@ -162,7 +162,7 @@ Deno.test("a client mod hooks LocalPlayer from its .bmod", async () => {
|
||||
write_mod(dir, "floaty", {
|
||||
client: [
|
||||
"client.ts",
|
||||
`import { engine, hook } from "bworld/engine";
|
||||
`import { engine, hook } from "cubi/engine";
|
||||
// everyone is a block higher than they think
|
||||
export function setup() {
|
||||
hook(engine.client.LocalPlayer.prototype, "set_position", {
|
||||
@@ -325,7 +325,7 @@ Deno.test("hook needs a loading mod with engine access", async () => {
|
||||
assertThrows(() => hook(new Counter(), "count", {}), Error, "isn't a method");
|
||||
});
|
||||
|
||||
// importing bworld/engine at all
|
||||
// importing cubi/engine at all
|
||||
expose_engine({});
|
||||
const shim = new URL("../common/mod_api/engine.ts", import.meta.url).href;
|
||||
let import_error: Error | undefined;
|
||||
@@ -334,24 +334,24 @@ Deno.test("hook needs a loading mod with engine access", async () => {
|
||||
} catch (e) {
|
||||
import_error = e as Error;
|
||||
}
|
||||
assertStringIncludes(String(import_error), `sneaky imports bworld/engine without "engine_access"`);
|
||||
assertStringIncludes(String(import_error), `sneaky imports cubi/engine without "engine_access"`);
|
||||
});
|
||||
|
||||
Deno.test("bworld/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 .bmod", async () => {
|
||||
const dir = Deno.makeTempDirSync({ prefix: "bworld_engine_" });
|
||||
const script = `import { engine } from "bworld/engine";
|
||||
const script = `import { engine } from "cubi/engine";
|
||||
export function setup() {
|
||||
console.log(engine.common.physics);
|
||||
}`;
|
||||
write_mod(dir, "sneaky", { server: ["server.ts", script] }, {});
|
||||
const [mod] = load_and_check(dir);
|
||||
assertEquals(mod.report.errors, [
|
||||
`scripts/server.ts imports bworld/engine, which needs "engine_access": true in manifest.json`,
|
||||
`scripts/server.ts imports cubi/engine, which needs "engine_access": true in manifest.json`,
|
||||
]);
|
||||
|
||||
// packed anyway, the bundle gives it away
|
||||
const bytes = await pack_mod(mod);
|
||||
assertThrows(() => read_bmod(bytes, "sneaky.bmod"), Error, "a script uses bworld/engine");
|
||||
assertThrows(() => read_bmod(bytes, "sneaky.bmod"), Error, "a script uses cubi/engine");
|
||||
Deno.removeSync(dir, { recursive: true });
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user