Remove duplicate code
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// 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";
|
||||
import type { ClientContext } from "bworld/client";
|
||||
|
||||
const WIDTH = 176;
|
||||
const HEIGHT = 166;
|
||||
@@ -14,17 +14,9 @@ export function setup(ctx: ClientContext) {
|
||||
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",
|
||||
);
|
||||
g.progress("bworld:fire_empty", "bworld:fire_full", 47, 53, 18, 18, menu.data.heated, "up");
|
||||
const { progress, progress_max } = menu.data;
|
||||
g.progress("bworld:arrow_empty", "bworld:arrow_full", 95, 25, 18, 18, progress / progress_max);
|
||||
},
|
||||
on_render_labels(g) {
|
||||
g.text(menu.title, 8, 6);
|
||||
@@ -32,24 +24,3 @@ export function setup(ctx: ClientContext) {
|
||||
},
|
||||
}));
|
||||
}
|
||||
|
||||
// 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]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user