Move curios into the main bworld mod
This commit is contained in:
+36
-12
@@ -1,7 +1,9 @@
|
||||
// curios: accessory slots for items in the curios tags, next to the player's inventory, see mods/curios
|
||||
// curios: accessory slots for items in the curios tags, next to the player's inventory, see
|
||||
// mods/bworld/scripts/curios.ts
|
||||
import { assertEquals } from "@std/assert";
|
||||
import { PLAYER_MENU_EXTRA } from "$/common/protocol.ts";
|
||||
import { copy_dir, test_game } from "./helpers.ts";
|
||||
import type { WorldSave } from "$/server/game/saves.ts";
|
||||
|
||||
// deno-lint-ignore no-explicit-any
|
||||
type Msg = any;
|
||||
@@ -9,22 +11,27 @@ type Msg = any;
|
||||
const last_container = (messages: Msg[], container: string) =>
|
||||
messages.filter((m) => m.type === "container" && m.container === container).at(-1)?.items;
|
||||
|
||||
// the base game, curios, and a mod with a ring and an amulet that goes in any slot
|
||||
async function setup() {
|
||||
// the base game, and a mod with a ring and an amulet that goes in any slot
|
||||
async function setup(save?: WorldSave) {
|
||||
const dir = Deno.makeTempDirSync({ prefix: "bworld_curios_" });
|
||||
copy_dir("mods/bworld", `${dir}/bworld`);
|
||||
copy_dir("mods/curios", `${dir}/curios`);
|
||||
const write = (path: string, json: unknown) => {
|
||||
Deno.mkdirSync(`${dir}/jewelry/${path}`.replace(/\/[^/]+$/, ""), { recursive: true });
|
||||
Deno.writeTextFileSync(`${dir}/jewelry/${path}`, JSON.stringify(json));
|
||||
};
|
||||
write("manifest.json", { format_version: 1, id: "jewelry", name: "Jewelry", version: "1.0.0" });
|
||||
write("manifest.json", {
|
||||
format_version: 1,
|
||||
id: "jewelry",
|
||||
name: "Jewelry",
|
||||
version: "1.0.0",
|
||||
dependencies: [{ id: "bworld", version: "*" }],
|
||||
});
|
||||
write("items/ring.json", { format_version: 1, item: { id: "jewelry:ring", texture: "bworld:coal" } });
|
||||
write("items/amulet.json", { format_version: 1, item: { id: "jewelry:amulet", texture: "bworld:coal" } });
|
||||
write("tags/items/curios/ring.json", { format_version: 1, tag: { values: ["jewelry:ring"] } });
|
||||
write("tags/items/curios/curio.json", { format_version: 1, tag: { values: ["jewelry:amulet"] } });
|
||||
write("tags/items/bworld/curios/ring.json", { format_version: 1, tag: { values: ["jewelry:ring"] } });
|
||||
write("tags/items/bworld/curios/curio.json", { format_version: 1, tag: { values: ["jewelry:amulet"] } });
|
||||
|
||||
const t = await test_game(dir);
|
||||
const t = await test_game(dir, save);
|
||||
t.join(1, "alice");
|
||||
for (const id of ["jewelry:ring", "jewelry:amulet", "bworld:coal"]) {
|
||||
t.send(1, { type: "chat", text: `/give ${id}` });
|
||||
@@ -33,7 +40,7 @@ async function setup() {
|
||||
return t;
|
||||
}
|
||||
|
||||
// what's in the curios slots, the ones curios added to the player's own menu, as last synced
|
||||
// what's in the curios slots, the ones the base game added to the player's own menu, as last synced
|
||||
const curios_items = (messages: Msg[]) => last_container(messages, "extra");
|
||||
|
||||
Deno.test("the slot types some item goes in are in 2 columns left of the inventory, with their icons", async () => {
|
||||
@@ -41,8 +48,8 @@ Deno.test("the slot types some item goes in are in 2 columns left of the invento
|
||||
t.game.on_disconnect(1);
|
||||
const join = t.join(1, "alice");
|
||||
assertEquals(join.player_menu, [
|
||||
{ x: -45, y: 7, icon: "curios:empty_curio_slot" },
|
||||
{ x: -27, y: 7, icon: "curios:empty_ring_slot" },
|
||||
{ x: -45, y: 7, icon: "bworld:empty_curio_slot" },
|
||||
{ x: -27, y: 7, icon: "bworld:empty_ring_slot" },
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -50,7 +57,7 @@ Deno.test("items only go in the slots they fit, and fall out when the player die
|
||||
const t = await setup();
|
||||
|
||||
// coal fits nowhere so it moves to the rest of the inventory, the ring only goes in the ring slot, and
|
||||
// #curios:curio items in any slot, the curio slot first
|
||||
// #bworld:curios/curio items in any slot, the curio slot first
|
||||
for (const slot of [2, 0, 1]) t.send(1, { type: "click", menu: 0, slot, button: 0, shift: true });
|
||||
const messages = t.take(1);
|
||||
assertEquals(last_container(messages, "inventory").slice(0, 3), [null, null, null]);
|
||||
@@ -69,3 +76,20 @@ Deno.test("items only go in the slots they fit, and fall out when the player die
|
||||
t.game.tick();
|
||||
assertEquals(curios_items(t.take(1)), [null, null]);
|
||||
});
|
||||
|
||||
Deno.test("curios worn when curios was a mod of its own are still worn", async () => {
|
||||
const t = await setup();
|
||||
t.send(1, { type: "click", menu: 0, slot: 0, button: 0, shift: true });
|
||||
t.game.on_disconnect(1);
|
||||
|
||||
// how a save from then kept which container is each player's curios
|
||||
const save = t.game.save();
|
||||
const level = JSON.parse(save.level);
|
||||
level.mod_storage.curios = { containers: level.mod_storage.bworld.curios };
|
||||
delete level.mod_storage.bworld.curios;
|
||||
|
||||
const loaded = await setup({ ...save, level: JSON.stringify(level) });
|
||||
const [ring] = loaded.game.players()[0].inventory_menu.extra.slice(1);
|
||||
assertEquals(ring.container.get_item(ring.index)?.to_data(), { id: "jewelry:ring", count: 1 });
|
||||
assertEquals(loaded.game.mods.storage.curios, undefined);
|
||||
});
|
||||
|
||||
@@ -31,7 +31,6 @@ Deno.test("welcome lists what to download, and nothing happens until ready", asy
|
||||
assertEquals(welcome.type, "welcome");
|
||||
assertEquals(welcome.mods.map((m: { id: string }) => m.id), [
|
||||
"bworld",
|
||||
"curios",
|
||||
"artifacts",
|
||||
"farmersdelight",
|
||||
"recipe_viewer",
|
||||
|
||||
Reference in New Issue
Block a user