Curios slots rendering !

This commit is contained in:
2026-10-01 17:57:22 -03:00
parent ea9f3f61bb
commit f2c3cb8135
39 changed files with 1032 additions and 226 deletions
+8 -4
View File
@@ -1,7 +1,7 @@
// curios, from C4's Curios mod: 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
// bworld:curio_modifiers component change the wearer's attributes, like curios' attribute modifiers
import type { AttributeModifier, Container, Player, ServerContext, TagApi } from "bworld/server";
import type { AttributeModifier, Container, ItemStack, Player, ServerContext, TagApi } from "bworld/server";
// 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;
@@ -43,16 +43,19 @@ export function register_curios(ctx: ServerContext) {
// keeps what their curios give them up to date
function watch(player: Player, curios: Container) {
stop_watching.get(player.id)?.();
stop_watching.set(player.id, curios.on_change(() => update_modifiers(player, curios)));
update_modifiers(player, curios);
stop_watching.set(player.id, curios.on_change(() => apply_worn(player, curios)));
apply_worn(player, curios);
}
function update_modifiers(player: Player, curios: Container) {
// what they wear: its attribute modifiers, and its worn model on them for everyone to see
function apply_worn(player: Player, curios: Container) {
for (const { attribute, id } of applied.get(player.id) ?? []) player.remove_modifier(attribute, id);
const now: { attribute: string; id: string }[] = [];
const worn: ItemStack[] = [];
for (const [index, slot] of SLOTS.entries()) {
const item = curios.get(index);
if (!item || !active.includes(slot)) continue;
worn.push(item);
for (const [i, { attribute, amount, operation }] of modifiers_of(item.id).entries()) {
const id = `bworld:curio/${slot}/${i}`;
player.add_modifier(attribute, { id, amount, operation });
@@ -60,6 +63,7 @@ export function register_curios(ctx: ServerContext) {
}
}
applied.set(player.id, now);
player.set_worn("bworld:curios", worn);
}
ctx.events.after.player_leave.subscribe(({ player }) => {