Basic Entity ID display for debugging

This commit is contained in:
2026-05-01 15:44:00 +02:00
parent 2a3064b0fe
commit 643712f529
7 changed files with 64 additions and 31 deletions

View File

@@ -46,9 +46,25 @@ pub const Road = struct {
///
/// In the future as we improve and make roads more complex with multiple lanes and such
/// it will gradually become more complex
pub fn draw(self: *const Road, highlighted: bool) void {
pub fn draw(self: *const Road, highlighted: bool, display_info: bool) void {
const colour = if (highlighted) c.ROAD_HIGHLIGHTED_COLOUR else c.ROAD_COLOUR;
rl.drawLineEx(self.nodes[0].pos, self.nodes[1].pos, c.ROAD_SIZE, colour);
if (!display_info) return;
var buf: [100]u8 = undefined;
const entity = std.fmt.bufPrintZ(&buf, "{d}", .{self.id}) catch |err| {
std.debug.panic("Could not allocate ID into string???: {}\n", .{err});
};
const distance = ut.getVectorP1P2(self.nodes[0].pos, self.nodes[1].pos);
const entity_info_pos: rl.Vector2 = .{
.x = self.nodes[0].pos.x + distance.x / 2 - c.ROAD_SIZE / 2,
.y = self.nodes[0].pos.y + distance.y / 2 - c.ROAD_SIZE / 2,
};
rl.drawText(entity, @trunc(entity_info_pos.x), @trunc(entity_info_pos.y),
c.ENTITY_DATA_TEXT_SIZE, c.ENTITY_DATA_TEXT_COLOUR);
}
/// Important: after this function executes, this road is no longer reachable from its bounding nodes