Change whole gui system
This commit is contained in:
+17
-15
@@ -1,6 +1,6 @@
|
||||
// curios: accessory slots for items in the curios tags, opened over mod channels, see mods/curios
|
||||
import { assert, assertEquals } from "@std/assert";
|
||||
import { copy_dir, test_game } from "./helpers.ts";
|
||||
import { copy_dir, menu_items, opened_menu, test_game } from "./helpers.ts";
|
||||
|
||||
// deno-lint-ignore no-explicit-any
|
||||
type Msg = any;
|
||||
@@ -35,40 +35,42 @@ async function setup() {
|
||||
Deno.test("the curios screen shows the slot types some item goes in, with their icons", async () => {
|
||||
const t = await setup();
|
||||
t.send(1, { type: "mod", channel: "curios:open", data: {} });
|
||||
const screen = t.take(1).find((m) => m.type === "open_screen");
|
||||
assertEquals(screen.layout.slots, [
|
||||
{ index: 0, x: 3.5, y: 0, icon: "curios:empty_curio_slot" },
|
||||
{ index: 7, x: 4.5, y: 0, icon: "curios:empty_ring_slot" },
|
||||
const menu = opened_menu(t.take(1));
|
||||
assertEquals(menu.menu_type, "curios:curios");
|
||||
// in the middle of the row, then the player's inventory
|
||||
assertEquals(menu.slots.slice(0, 2), [
|
||||
{ x: 70, y: 17, icon: "curios:empty_curio_slot" },
|
||||
{ x: 88, y: 17, icon: "curios:empty_ring_slot" },
|
||||
]);
|
||||
assertEquals(menu.slots.length, 2 + 36);
|
||||
});
|
||||
|
||||
Deno.test("items only go in the slots they fit, and fall out when the player dies", async () => {
|
||||
const t = await setup();
|
||||
t.send(1, { type: "mod", channel: "curios:open", data: {} });
|
||||
t.take(1);
|
||||
const { id } = opened_menu(t.take(1));
|
||||
|
||||
// coal fits nowhere, the ring only in the ring slot, and #curios:curio items in any slot, the curio slot first
|
||||
t.send(1, { type: "click", container: "inventory", index: 2, button: 0, shift: true });
|
||||
t.send(1, { type: "click", container: "inventory", index: 0, button: 0, shift: true });
|
||||
t.send(1, { type: "click", container: "inventory", index: 1, button: 0, shift: true });
|
||||
// coal fits nowhere, the ring only in the ring slot, and #curios:curio items in any slot, the curio slot first.
|
||||
// the inventory's slots come after the 2 curios ones
|
||||
for (const index of [2, 0, 1]) t.send(1, { type: "click", menu: id, slot: 2 + index, button: 0, shift: true });
|
||||
const messages = t.take(1);
|
||||
assertEquals(last_container(messages, "inventory").slice(0, 3), [null, null, { id: "bworld:coal", count: 1 }]);
|
||||
const curios = last_container(messages, "screen");
|
||||
const curios = menu_items(messages);
|
||||
assertEquals(curios[0], { id: "jewelry:amulet", count: 1 });
|
||||
assertEquals(curios[7], { id: "jewelry:ring", count: 1 });
|
||||
assertEquals(curios[1], { id: "jewelry:ring", count: 1 });
|
||||
|
||||
const player = t.game.players()[0];
|
||||
t.game.damage_player(player, 100, "fall");
|
||||
const dropped = t.game.item_entities().map((e) => e.item.type_id).sort();
|
||||
assertEquals(dropped, ["bworld:coal", "jewelry:amulet", "jewelry:ring"]);
|
||||
t.send(1, { type: "mod", channel: "curios:open", data: {} });
|
||||
assertEquals(last_container(t.take(1), "screen").filter(Boolean), []);
|
||||
assertEquals(menu_items(t.take(1)).filter(Boolean), []);
|
||||
});
|
||||
|
||||
Deno.test("mod messages that are too big or too many are dropped", async () => {
|
||||
const t = await setup();
|
||||
t.send(1, { type: "mod", channel: "curios:open", data: "x".repeat(20_000) });
|
||||
assertEquals(t.take(1).filter((m) => m.type === "open_screen"), []);
|
||||
assertEquals(t.take(1).filter((m) => m.type === "open_menu"), []);
|
||||
for (let i = 0; i < 100; i++) t.send(1, { type: "mod", channel: "curios:open", data: {} });
|
||||
assert(t.take(1).filter((m) => m.type === "open_screen").length < 100);
|
||||
assert(t.take(1).filter((m) => m.type === "open_menu").length < 100);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user