Remove duplicate code
This commit is contained in:
@@ -44,8 +44,9 @@ function chest_screen(menu: ClientMenu): MenuScreen {
|
||||
function furnace_screen(menu: ClientMenu): MenuScreen {
|
||||
return container_screen(menu, HEIGHT, (g) => {
|
||||
// the fuel left burns down, the progress fills to the right
|
||||
bar(g, 55, 34, "up", menu.data.fuel, menu.data.fuel_max, "bworld:fire_empty", "bworld:fire_full");
|
||||
bar(g, 85, 34, "right", menu.data.progress, menu.data.progress_max, "bworld:arrow_empty", "bworld:arrow_full");
|
||||
const { fuel, fuel_max, progress, progress_max } = menu.data;
|
||||
g.progress("bworld:fire_empty", "bworld:fire_full", 55, 34, 18, 18, fuel / fuel_max, "up");
|
||||
g.progress("bworld:arrow_empty", "bworld:arrow_full", 85, 34, 18, 18, progress / progress_max);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -125,27 +126,6 @@ function stonecutter_screen(ctx: ClientContext, menu: ClientMenu): MenuScreen {
|
||||
});
|
||||
}
|
||||
|
||||
// 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]);
|
||||
}
|
||||
}
|
||||
|
||||
// a fishing minigame's screen, by the minigame's name, see minigames/mod.ts
|
||||
function fishing_minigame_screen(menu: ClientMenu): MenuScreen {
|
||||
const { minigame, fish } = menu.open_data as { minigame: string; fish: ItemStack };
|
||||
|
||||
@@ -105,20 +105,10 @@ function grow_tree(kind: TreeKind, x: number, y: number, z: number, rng: Random,
|
||||
|
||||
let top: number;
|
||||
switch (kind) {
|
||||
case "oak": {
|
||||
const height = random(4, 6);
|
||||
top = y + height + 1;
|
||||
if (top >= CHUNK_HEIGHT - 1) return false;
|
||||
trunk(height);
|
||||
layer(y + height - 2, 2, true);
|
||||
layer(y + height - 1, 2, true);
|
||||
layer(y + height, 1, true);
|
||||
layer(y + height + 1, 1, false);
|
||||
break;
|
||||
}
|
||||
case "oak":
|
||||
case "birch": {
|
||||
// oak's canopy on a taller, straight trunk
|
||||
const height = random(5, 7);
|
||||
// birch is oak's canopy on a taller, straight trunk
|
||||
const height = kind === "birch" ? random(5, 7) : random(4, 6);
|
||||
top = y + height + 1;
|
||||
if (top >= CHUNK_HEIGHT - 1) return false;
|
||||
trunk(height);
|
||||
|
||||
@@ -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