This commit is contained in:
2026-09-24 18:34:16 -03:00
parent a758037f20
commit a37ffd9127
20 changed files with 799 additions and 20 deletions
+12 -2
View File
@@ -4,6 +4,8 @@ import { InputManager } from "../input_manager.ts";
import { ClientWorld } from "../client_world.ts";
import { PlayerComponent } from "../player.ts";
import { ItemStack } from "../inventory.ts";
import { MAX_CHAT_LENGTH } from "$/common/protocol.ts";
import { render_chat_log } from "../systems/rendering/network.ts";
export class GuiChat extends GuiScreen {
world: ClientWorld;
@@ -22,6 +24,7 @@ export class GuiChat extends GuiScreen {
draw_rect(0, 0, canvas.width, canvas.height, [0, 0, 0, 0.8]);
const y = canvas.height - 32;
render_chat_log(this.world, true, y - 8);
draw_rect(0, y, canvas.width, canvas.height, [0, 0, 0, 0.4]);
draw_text(this.text_typed, 0, y, 2, [1, 1, 1]);
@@ -85,6 +88,9 @@ export class GuiChat extends GuiScreen {
const typed = InputManager.get_typed_characters();
for (const char of typed) {
if (this.text_typed.length >= MAX_CHAT_LENGTH) {
break;
}
this.text_typed = this.text_typed.slice(0, this.caret) + char + this.text_typed.slice(this.caret);
this.caret += 1;
}
@@ -98,8 +104,12 @@ export class GuiChat extends GuiScreen {
submit() {
if (this.text_typed.startsWith("/")) {
this.command();
} else {
// we dont have multiplayer lol?
} else if (this.text_typed.trim().length > 0) {
if (this.world.connection) {
this.world.connection.send({ type: "chat", text: this.text_typed });
} else {
this.world.add_chat(this.text_typed);
}
}
this.text_typed = "";