Change curios to always show on inventory

This commit is contained in:
2026-10-01 16:35:41 -03:00
parent deba36260e
commit 3dc7d2adee
24 changed files with 244 additions and 159 deletions
+15 -25
View File
@@ -1,9 +1,12 @@
// curios: accessory slots, shown with the player's inventory from the curios button. each player's curios are a
// curios: accessory slots, in 2 columns left of the player's inventory. each player's curios are a
// container of their own, and fall out when they die like the rest of what they carry. items with the
// curios:attribute_modifiers component change the wearer's attributes, like curios' attribute modifiers
import type { AttributeModifier, Container, Player, ServerContext } from "bworld/server";
import { active_slots, fits, SLOTS } from "./slots.ts";
// where the left column of slots goes, from the inventory screen's left edge. the panel around them ends just left of it
const COLUMNS_X = -45;
// curios:attribute_modifiers' params, a list of these
interface WornModifier {
attribute: string;
@@ -24,7 +27,7 @@ export function setup(ctx: ServerContext) {
const applied = new Map<string, { attribute: string; id: string }[]>();
const stop_watching = new Map<string, () => void>();
// by player name, like the players themselves are saved. undefined until they first open curios
// by player name, like the players themselves are saved. undefined until they first join with curios
function saved_curios(player: Player): Container | undefined {
const id = ctx.storage.get<Record<string, string>>("containers")?.[player.name];
return id ? ctx.containers.get(id) : undefined;
@@ -72,28 +75,8 @@ export function setup(ctx: ServerContext) {
applied.delete(player.id);
});
// like curios' CuriosContainer: the slot types in rows of 9, each row centered, over the inventory. the screen is
// in scripts/client.ts
const rows = Math.ceil(active.length / 9);
const menu_type = ctx.menus.register("curios:curios", (menu, _args, player) => {
const curios = curios_of(player);
menu.title = "Curios";
menu.open_data = { rows };
for (const [i, slot] of active.entries()) {
const row = Math.floor(i / 9);
const in_row = Math.min(9, active.length - row * 9);
menu.add_slot(curios, SLOTS.indexOf(slot), {
x: 7 + ((9 - in_row) / 2 + (i % 9)) * 18,
y: 17 + row * 18,
filter: (item) => fits(ctx.tags, slot, item.id),
icon: `curios:empty_${slot}_slot`,
});
}
menu.add_player_inventory(7, 31 + rows * 18);
});
// the curios button, curios' client asks for its menu like the java mod's packet does
ctx.net.on("curios:open", (player) => {
// the slot types in 2 columns left of the inventory, always there while it's open. the engine draws their panel
ctx.menus.extend_player_menu((menu, player) => {
if (active.length === 0) return;
const curios = curios_of(player);
// what's in slot types no item goes in anymore, since the mod that added them was removed, goes back to them
@@ -104,7 +87,14 @@ export function setup(ctx: ServerContext) {
curios.set(index, undefined);
}
}
menu_type.open(player, undefined);
for (const [i, slot] of active.entries()) {
menu.add_slot(curios, SLOTS.indexOf(slot), {
x: COLUMNS_X + (i % 2) * 18,
y: 7 + Math.floor(i / 2) * 18,
filter: (item) => fits(ctx.tags, slot, item.id),
icon: `curios:empty_${slot}_slot`,
});
}
});
ctx.events.after.player_death.subscribe(({ player }) => {