UI and about page in game

This commit is contained in:
2026-02-24 16:57:51 -03:00
parent fe885a9e24
commit 86d527ae51
12 changed files with 268 additions and 6 deletions
+35
View File
@@ -0,0 +1,35 @@
import { System } from "$/common/ecs/mod.ts";
import { Position } from "$/common/components/position.ts";
import { point_inside_rec } from "$/common/utils.ts";
import { ClientWorld } from "$/client/client_world.ts";
import { UIButton } from "$/client/components/ui_components.ts";
import { InputManager } from "$/client/input_manager.ts";
export class UIInteractionSystem implements System {
update(world: ClientWorld, _delta: number) {
// TODO: dont like
if (InputManager.is_key_pressed("Escape")) {
world.paused = !world.paused;
}
if (!world.paused) {
return;
}
const mouse = InputManager.get_mouse_position();
for (const entity of world.get_entities()) {
const position = entity.get(Position);
const button = entity.get(UIButton);
if (position && button) {
const hovered = point_inside_rec(mouse.x, mouse.y, position.x, position.y, button.width, button.height);
button.hovered = hovered;
if (hovered && InputManager.is_mouse_pressed(0)) {
InputManager.consume_mouse(0);
button.on_click();
}
}
}
}
}