Compare commits
2
Commits
dd66d6caa7
...
a2ed562817
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a2ed562817 | ||
|
|
807b38b0af |
@@ -4,6 +4,8 @@ import type { ClientInventories } from "$/client/inventory.ts";
|
||||
import { draw_item } from "$/client/rendering/render_utils.ts";
|
||||
import { canvas, draw_rect, draw_text, measure_text } from "$/client/renderer/mod.ts";
|
||||
import { display_name } from "$/common/utils.ts";
|
||||
import { clock } from "$/common/time.ts";
|
||||
import { biome_season } from "$/common/worldgen/biomes.ts";
|
||||
import { TEXT_HEIGHT, TEXT_SCALE } from "./widgets.ts";
|
||||
import { draw_gui_sprite, GUI_SCALE } from "./gui_sprites.ts";
|
||||
|
||||
@@ -37,6 +39,11 @@ const ATTACK_BAR_HEIGHT = 2;
|
||||
const ATTACK_BAR_GAP = 2;
|
||||
const ATTACK_BAR_BACK: [number, number, number, number] = [0, 0, 0, 0.4];
|
||||
const ATTACK_BAR_FILL: [number, number, number, number] = [1, 1, 1, 0.9];
|
||||
// the day, time, biome and season in the top left, on a dark box so it reads over the sky
|
||||
const INFO_MARGIN = 4;
|
||||
const INFO_PADDING = 3;
|
||||
const INFO_LINE_GAP = 1;
|
||||
const INFO_BACK: [number, number, number, number] = [0, 0, 0, 0.4];
|
||||
|
||||
// what's drawn over the world while playing, like minecraft's Gui: hotbar, crosshair and chat
|
||||
export class Hud {
|
||||
@@ -50,6 +57,7 @@ export class Hud {
|
||||
const top = Math.min(icons_y() - heart_rows_height(client.player.max_health), air_y(client.player));
|
||||
this.#render_held_name(client.player.inventories, top);
|
||||
this.#render_crosshair(client);
|
||||
this.#render_info(client);
|
||||
client.chat.render(false, top - HELD_NAME_GAP);
|
||||
}
|
||||
|
||||
@@ -139,6 +147,31 @@ export class Hud {
|
||||
}
|
||||
}
|
||||
|
||||
#render_info(client: Client) {
|
||||
const { day, hour, minute } = clock(client.level.time);
|
||||
const { x, z } = client.player;
|
||||
const biome = client.level.biome_at(Math.floor(x), Math.floor(z));
|
||||
const lines = [
|
||||
`Day ${day}`,
|
||||
`${String(hour).padStart(2, "0")}:${String(minute).padStart(2, "0")}`,
|
||||
biome === undefined ? "Unknown" : display_name(biome),
|
||||
biome === undefined ? "Unknown" : capitalize(biome_season(biome)),
|
||||
];
|
||||
|
||||
const padding = INFO_PADDING * GUI_SCALE;
|
||||
const line_height = (TEXT_HEIGHT + INFO_LINE_GAP) * TEXT_SCALE;
|
||||
const width = Math.max(...lines.map((line) => measure_text(line, TEXT_SCALE))) + padding * 2;
|
||||
const height = lines.length * line_height - INFO_LINE_GAP * TEXT_SCALE + padding * 2;
|
||||
const left = INFO_MARGIN * GUI_SCALE;
|
||||
const top = INFO_MARGIN * GUI_SCALE;
|
||||
draw_rect(left, top, width, height, INFO_BACK);
|
||||
lines.forEach((line, i) => {
|
||||
const text_y = top + padding + i * line_height;
|
||||
draw_text(line, left + padding + TEXT_SCALE, text_y + TEXT_SCALE, TEXT_SCALE, [0.15, 0.15, 0.15, 1]);
|
||||
draw_text(line, left + padding, text_y, TEXT_SCALE, [1, 1, 1, 1]);
|
||||
});
|
||||
}
|
||||
|
||||
#render_crosshair(client: Client) {
|
||||
const size = CROSSHAIR_SIZE * GUI_SCALE;
|
||||
const x = Math.round((canvas.width - size) / 2);
|
||||
@@ -191,6 +224,10 @@ function heart_rows_height(max_health: number) {
|
||||
return Math.max(0, rows - 1) * heart_row_spacing(max_health) * GUI_SCALE;
|
||||
}
|
||||
|
||||
function capitalize(word: string) {
|
||||
return word[0].toUpperCase() + word.slice(1);
|
||||
}
|
||||
|
||||
// whether icon i of a value, 2 points an icon, is full, half or empty
|
||||
function icon_fill(value: number, i: number): "full" | "half" | undefined {
|
||||
if (value >= i * 2 + 2) return "full";
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
"grass": "#91bd59",
|
||||
"foliage": "#77ab2f",
|
||||
"water": "#3f76e4"
|
||||
}
|
||||
},
|
||||
"season": "summer"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
"wood": {
|
||||
"big_oak": "dark_oak"
|
||||
}
|
||||
}
|
||||
},
|
||||
"season": "autumn"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
"grass": "#80b497",
|
||||
"foliage": "#60a17b",
|
||||
"water": "#3938c9"
|
||||
}
|
||||
},
|
||||
"season": "winter"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
"grass": "#8eb971",
|
||||
"foliage": "#71a74d",
|
||||
"water": "#45adf2"
|
||||
}
|
||||
},
|
||||
"season": "summer"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
"grass": "#8eb971",
|
||||
"foliage": "#71a74d",
|
||||
"water": "#3f76e4"
|
||||
}
|
||||
},
|
||||
"season": "spring"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
"grass": "#bfb755",
|
||||
"foliage": "#aea42a",
|
||||
"water": "#3f76e4"
|
||||
}
|
||||
},
|
||||
"season": "summer"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
"big_oak",
|
||||
"birch"
|
||||
]
|
||||
}
|
||||
},
|
||||
"season": "spring"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
"grass": "#80b497",
|
||||
"foliage": "#60a17b",
|
||||
"water": "#3938c9"
|
||||
}
|
||||
},
|
||||
"season": "winter"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
"grass": "#80b497",
|
||||
"foliage": "#60a17b",
|
||||
"water": "#3f76e4"
|
||||
}
|
||||
},
|
||||
"season": "winter"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
"grass": "#80b497",
|
||||
"foliage": "#60a17b",
|
||||
"water": "#3938c9"
|
||||
}
|
||||
},
|
||||
"season": "winter"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
"grass": "#80b497",
|
||||
"foliage": "#60a17b",
|
||||
"water": "#3f76e4"
|
||||
}
|
||||
},
|
||||
"season": "autumn"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
"jungle",
|
||||
"big_oak"
|
||||
]
|
||||
}
|
||||
},
|
||||
"season": "summer"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
"cherry",
|
||||
"cherry"
|
||||
]
|
||||
}
|
||||
},
|
||||
"season": "autumn"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
"grass": "#8eb971",
|
||||
"foliage": "#71a74d",
|
||||
"water": "#3f76e4"
|
||||
}
|
||||
},
|
||||
"season": "spring"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
"kinds": [
|
||||
"oak"
|
||||
]
|
||||
}
|
||||
},
|
||||
"season": "spring"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
"kinds": [
|
||||
"oak"
|
||||
]
|
||||
}
|
||||
},
|
||||
"season": "spring"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
"acacia",
|
||||
"oak"
|
||||
]
|
||||
}
|
||||
},
|
||||
"season": "summer"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
"grass": "#83b593",
|
||||
"foliage": "#64a278",
|
||||
"water": "#3d57d6"
|
||||
}
|
||||
},
|
||||
"season": "winter"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
"kinds": [
|
||||
"spruce"
|
||||
]
|
||||
}
|
||||
},
|
||||
"season": "winter"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
"kinds": [
|
||||
"spruce"
|
||||
]
|
||||
}
|
||||
},
|
||||
"season": "winter"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
"kinds": [
|
||||
"spruce"
|
||||
]
|
||||
}
|
||||
},
|
||||
"season": "winter"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
"grass": "#9abe4b",
|
||||
"foliage": "#82ac1e",
|
||||
"water": "#3f76e4"
|
||||
}
|
||||
},
|
||||
"season": "autumn"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
"grass": "#8ab689",
|
||||
"foliage": "#6da36b",
|
||||
"water": "#3f76e4"
|
||||
}
|
||||
},
|
||||
"season": "autumn"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
"kinds": [
|
||||
"big_oak"
|
||||
]
|
||||
}
|
||||
},
|
||||
"season": "summer"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
"kinds": [
|
||||
"spruce"
|
||||
]
|
||||
}
|
||||
},
|
||||
"season": "winter"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
"grass": "#8eb971",
|
||||
"foliage": "#71a74d",
|
||||
"water": "#43d5ee"
|
||||
}
|
||||
},
|
||||
"season": "summer"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user