Files
bworld/mods/farmersdelight/scripts/client.ts
T
2026-10-01 16:22:02 -03:00

53 lines
1.4 KiB
TypeScript

// the cooking pot's screen, like the java mod's CookingPotScreen. its slots are in scripts/server.ts, in gui pixels
import type { ClientContext, Graphics } from "bworld/client";
const WIDTH = 176;
const HEIGHT = 166;
export function setup(ctx: ClientContext) {
ctx.ui.register_menu_screen("farmersdelight:cooking_pot", (menu) => ({
width: WIDTH,
height: HEIGHT,
on_render_background(g) {
g.panel(0, 0, WIDTH, HEIGHT);
// lit under the ingredients while something heats the pot, the arrow fills as the meal cooks
bar(g, 47, 53, "up", menu.data.heated, 1, "bworld:fire_empty", "bworld:fire_full");
bar(
g,
95,
25,
"right",
menu.data.progress,
menu.data.progress_max,
"bworld:arrow_empty",
"bworld:arrow_full",
);
},
on_render_labels(g) {
g.text(menu.title, 8, 6);
g.text("Inventory", 8, 73);
},
}));
}
// an 18 pixel square progress bar, value / max of full drawn over empty
function bar(
g: Graphics,
x: number,
y: number,
direction: "up" | "right",
value = 0,
max = 0,
empty: string,
full: string,
) {
const size = 18;
const done = max > 0 ? Math.max(0, Math.min(1, value / max)) : 0;
g.texture(empty, x, y, size, size);
if (direction === "right") {
g.texture(full, x, y, size * done, size, [0, 0, done, 1]);
} else {
g.texture(full, x, y + size * (1 - done), size, size * done, [0, 1 - done, 1, done]);
}
}