Change whole gui system
This commit is contained in:
+26
-22
@@ -1,7 +1,7 @@
|
||||
// shift clicking a slot moves its stack to the other part of the screen, like minecraft's quick move
|
||||
import { assertEquals } from "@std/assert";
|
||||
import { CRAFTING_RESULT_SLOT } from "$/common/protocol.ts";
|
||||
import { test_game } from "./helpers.ts";
|
||||
import { CRAFTING_RESULT_SLOT, PLAYER_MENU_CRAFTING } from "$/common/protocol.ts";
|
||||
import { menu_items, opened_menu, test_game } from "./helpers.ts";
|
||||
|
||||
// deno-lint-ignore no-explicit-any
|
||||
type Msg = any;
|
||||
@@ -24,13 +24,13 @@ async function setup(items: [string, number][] = []) {
|
||||
|
||||
Deno.test("without a container open, shift clicking moves between the hotbar and the rest of the inventory", async () => {
|
||||
const t = await setup([["bworld:coal", 10], ["bworld:stick", 5]]);
|
||||
t.send(1, { type: "click", container: "inventory", index: 0, button: 0, shift: true });
|
||||
t.send(1, { type: "click", menu: 0, slot: 0, button: 0, shift: true });
|
||||
let inventory = last_container(t.take(1), "inventory");
|
||||
assertEquals(inventory[0], null);
|
||||
assertEquals(inventory[9], { id: "bworld:coal", count: 10 });
|
||||
|
||||
// back down it goes to the first free hotbar slot, the sticks are in the second
|
||||
t.send(1, { type: "click", container: "inventory", index: 9, button: 0, shift: true });
|
||||
t.send(1, { type: "click", menu: 0, slot: 9, button: 0, shift: true });
|
||||
inventory = last_container(t.take(1), "inventory");
|
||||
assertEquals(inventory[0], { id: "bworld:coal", count: 10 });
|
||||
assertEquals(inventory[1], { id: "bworld:stick", count: 5 });
|
||||
@@ -40,9 +40,9 @@ Deno.test("without a container open, shift clicking moves between the hotbar and
|
||||
Deno.test("shift clicking tops up stacks of the same item before using empty slots", async () => {
|
||||
const t = await setup([["bworld:coal", 20]]);
|
||||
// half of it to the main inventory by hand, then the other half shift clicked onto it
|
||||
t.send(1, { type: "click", container: "inventory", index: 0, button: 2 });
|
||||
t.send(1, { type: "click", container: "inventory", index: 9, button: 0 });
|
||||
t.send(1, { type: "click", container: "inventory", index: 0, button: 0, shift: true });
|
||||
t.send(1, { type: "click", menu: 0, slot: 0, button: 2 });
|
||||
t.send(1, { type: "click", menu: 0, slot: 9, button: 0 });
|
||||
t.send(1, { type: "click", menu: 0, slot: 0, button: 0, shift: true });
|
||||
const inventory = last_container(t.take(1), "inventory");
|
||||
assertEquals(inventory[0], null);
|
||||
assertEquals(inventory[9], { id: "bworld:coal", count: 20 });
|
||||
@@ -53,16 +53,18 @@ Deno.test("with a chest open, shift clicking moves between it and the inventory"
|
||||
const t = await setup([["bworld:coal", 10]]);
|
||||
t.game.set_block(1, 100, 0, "bworld:chest");
|
||||
t.send(1, { type: "use_block", x: 1, y: 100, z: 0, face: "top" });
|
||||
const { id } = opened_menu(t.take(1));
|
||||
|
||||
t.send(1, { type: "click", container: "inventory", index: 0, button: 0, shift: true });
|
||||
// the chest's 27 slots, then the inventory's
|
||||
t.send(1, { type: "click", menu: id, slot: 27, button: 0, shift: true });
|
||||
let messages = t.take(1);
|
||||
assertEquals(last_container(messages, "inventory")[0], null);
|
||||
assertEquals(last_container(messages, "screen")[0], { id: "bworld:coal", count: 10 });
|
||||
assertEquals(menu_items(messages)[0], { id: "bworld:coal", count: 10 });
|
||||
|
||||
// like minecraft, out of a container it fills the hotbar from the right
|
||||
t.send(1, { type: "click", container: "screen", index: 0, button: 0, shift: true });
|
||||
t.send(1, { type: "click", menu: id, slot: 0, button: 0, shift: true });
|
||||
messages = t.take(1);
|
||||
assertEquals(last_container(messages, "screen")[0], null);
|
||||
assertEquals(menu_items(messages)[0], null);
|
||||
assertEquals(last_container(messages, "inventory")[8], { id: "bworld:coal", count: 10 });
|
||||
});
|
||||
|
||||
@@ -70,11 +72,13 @@ Deno.test("shift clicking into a furnace goes by its slot filters, and takes the
|
||||
const t = await setup([["bworld:iron_ore", 1], ["bworld:coal", 1], ["bworld:stick", 1]]);
|
||||
t.game.set_block(1, 100, 0, "bworld:furnace");
|
||||
t.send(1, { type: "use_block", x: 1, y: 100, z: 0, face: "top" });
|
||||
const { id } = opened_menu(t.take(1));
|
||||
|
||||
// the ore goes in the input, the coal in the fuel slot, and sticks fit neither so they stay
|
||||
for (const index of [0, 1, 2]) t.send(1, { type: "click", container: "inventory", index, button: 0, shift: true });
|
||||
// the ore goes in the input, the coal in the fuel slot, and sticks fit neither so they stay. the furnace's 3 slots
|
||||
// come before the inventory's
|
||||
for (const index of [0, 1, 2]) t.send(1, { type: "click", menu: id, slot: 3 + index, button: 0, shift: true });
|
||||
let messages = t.take(1);
|
||||
assertEquals(last_container(messages, "screen"), [
|
||||
assertEquals(menu_items(messages).slice(0, 3), [
|
||||
{ id: "bworld:iron_ore", count: 1 },
|
||||
{ id: "bworld:coal", count: 1 },
|
||||
null,
|
||||
@@ -82,18 +86,18 @@ Deno.test("shift clicking into a furnace goes by its slot filters, and takes the
|
||||
assertEquals(last_container(messages, "inventory")[2], { id: "bworld:stick", count: 1 });
|
||||
|
||||
for (let i = 0; i < 210; i++) t.game.tick();
|
||||
t.send(1, { type: "click", container: "screen", index: 2, button: 0, shift: true });
|
||||
t.send(1, { type: "click", menu: id, slot: 2, button: 0, shift: true });
|
||||
messages = t.take(1);
|
||||
assertEquals(last_container(messages, "screen")[2], null);
|
||||
assertEquals(menu_items(messages)[2], null);
|
||||
assertEquals(last_container(messages, "inventory")[8], { id: "bworld:iron_ingot", count: 1 });
|
||||
});
|
||||
|
||||
Deno.test("shift clicking the crafting result crafts as many as fit", async () => {
|
||||
const t = await setup([["bworld:log", 3]]);
|
||||
// the logs into the grid, then the result shift clicked: 3 crafts of 2 planks
|
||||
t.send(1, { type: "click", container: "inventory", index: 0, button: 0 });
|
||||
t.send(1, { type: "click", container: "crafting", index: 0, button: 0 });
|
||||
t.send(1, { type: "click", container: "crafting", index: CRAFTING_RESULT_SLOT, button: 0, shift: true });
|
||||
t.send(1, { type: "click", menu: 0, slot: 0, button: 0 });
|
||||
t.send(1, { type: "click", menu: 0, slot: PLAYER_MENU_CRAFTING, button: 0 });
|
||||
t.send(1, { type: "click", menu: 0, slot: PLAYER_MENU_CRAFTING + CRAFTING_RESULT_SLOT, button: 0, shift: true });
|
||||
const messages = t.take(1);
|
||||
assertEquals(last_container(messages, "crafting").every((item: Msg) => item === null), true);
|
||||
assertEquals(last_container(messages, "inventory")[8], { id: "bworld:planks", count: 6 });
|
||||
@@ -101,9 +105,9 @@ Deno.test("shift clicking the crafting result crafts as many as fit", async () =
|
||||
|
||||
Deno.test("shift clicking the crafting grid puts its items back in the inventory", async () => {
|
||||
const t = await setup([["bworld:log", 3]]);
|
||||
t.send(1, { type: "click", container: "inventory", index: 0, button: 0 });
|
||||
t.send(1, { type: "click", container: "crafting", index: 4, button: 0 });
|
||||
t.send(1, { type: "click", container: "crafting", index: 4, button: 0, shift: true });
|
||||
t.send(1, { type: "click", menu: 0, slot: 0, button: 0 });
|
||||
t.send(1, { type: "click", menu: 0, slot: PLAYER_MENU_CRAFTING + 4, button: 0 });
|
||||
t.send(1, { type: "click", menu: 0, slot: PLAYER_MENU_CRAFTING + 4, button: 0, shift: true });
|
||||
const messages = t.take(1);
|
||||
assertEquals(last_container(messages, "crafting").every((item: Msg) => item === null), true);
|
||||
assertEquals(last_container(messages, "inventory")[9], { id: "bworld:log", count: 3 });
|
||||
|
||||
Reference in New Issue
Block a user