Implemented Entity tagged union for highlighted entity (similar to abstract class in some ways)
This commit is contained in:
@@ -7,13 +7,11 @@ const Node = @import("node.zig").Node;
|
||||
pub const RoadManager = struct {
|
||||
next_id: usize,
|
||||
roads: std.ArrayList(*Road),
|
||||
highlighted_road: ?*Road,
|
||||
|
||||
pub fn init() RoadManager {
|
||||
return .{
|
||||
.next_id = 0,
|
||||
.roads = .empty,
|
||||
.highlighted_road = null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -26,9 +24,9 @@ pub const RoadManager = struct {
|
||||
}
|
||||
|
||||
/// Draws all the roads in the list, sends the information ahead whether the road drawn should be highlighted
|
||||
pub fn draw(self: *const RoadManager, delete_mode: bool) void {
|
||||
pub fn draw(self: *const RoadManager, highlighted_road: ?*Road) void {
|
||||
for (self.roads.items) |road| {
|
||||
const is_highlighted = delete_mode and self.highlighted_road != null and self.highlighted_road.? == road;
|
||||
const is_highlighted = if (highlighted_road) |h_road| road == h_road else false;
|
||||
road.draw(is_highlighted);
|
||||
}
|
||||
}
|
||||
@@ -85,16 +83,13 @@ pub const RoadManager = struct {
|
||||
return e.Entity.NotFound;
|
||||
}
|
||||
|
||||
/// Sets the pointer to the road that is intersection with pos coordinate
|
||||
pub fn update_highlighted_road(self: *RoadManager, pos: Vector2) void {
|
||||
/// Returns if pos is pointing at a road, or null if it isn't at any
|
||||
pub fn getHighlightedRoad(self: *const RoadManager, pos: Vector2) ?*Road {
|
||||
for (self.roads.items) |road| {
|
||||
if (!road.isHighlighted(pos)) continue;
|
||||
|
||||
self.highlighted_road = road;
|
||||
return;
|
||||
if (road.isHighlighted(pos)) return road;
|
||||
}
|
||||
|
||||
self.highlighted_road = null;
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user