Implemented a few debugging/inspecting tools
This commit is contained in:
@@ -43,13 +43,7 @@ pub const Node = struct {
|
||||
/// Returns bool whether the road passed is part of the roads list
|
||||
fn roadInList(self: *const Node, road_to_check: *const Road) ?usize {
|
||||
for (self.roads.items, 0..) |road, i| {
|
||||
std.debug.print("Road id = {d}\n", .{road.id});
|
||||
std.debug.print("Road to check id = {d}\n", .{road_to_check.id});
|
||||
// TODO fix why doesn't 0 == 0 return i
|
||||
std.debug.print("{}\n", .{road.id == road_to_check.id});
|
||||
const res = road.id == road_to_check.id;
|
||||
if (road.id == road_to_check.id) return i;
|
||||
if (res) return i;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -7,11 +7,13 @@ const Node = @import("node.zig").Node;
|
||||
pub const NodeManager = struct {
|
||||
temp_node: ?*Node,
|
||||
nodes: std.ArrayList(Node),
|
||||
highlighted_node: ?*Node,
|
||||
|
||||
pub fn init(allocator: std.mem.Allocator) !NodeManager {
|
||||
return .{
|
||||
.temp_node = null,
|
||||
.nodes = try .initCapacity(allocator, c.ALLOC_SIZE),
|
||||
.highlighted_node = null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -91,7 +93,7 @@ pub const NodeManager = struct {
|
||||
}
|
||||
|
||||
/// Removes the node from the list with all appropriate checks
|
||||
pub fn removeNode(self: *NodeManager, node_to_remove: *Node) !void {
|
||||
pub fn remove(self: *NodeManager, node_to_remove: *Node) !void {
|
||||
// In case the node has references to the existing roads we can not remove it
|
||||
// This also means we don't have to deinit it, since it has no elements
|
||||
if (node_to_remove.roads.items.len > 0) return;
|
||||
@@ -105,4 +107,6 @@ pub const NodeManager = struct {
|
||||
|
||||
return error.NodeNotExist;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
@@ -21,9 +21,7 @@ pub const RoadManager = struct {
|
||||
self.roads.deinit(allocator);
|
||||
}
|
||||
|
||||
pub fn draw(self: *RoadManager, display_highlighted_road: bool) void {
|
||||
self.highlighted_road = self.getSelectedRoad(rl.getMousePosition());
|
||||
|
||||
pub fn draw(self: *const RoadManager, display_highlighted_road: bool) void {
|
||||
for (self.roads.items) |road| {
|
||||
var colour: rl.Color = .black;
|
||||
if (self.highlighted_road) |hr| {
|
||||
|
||||
Reference in New Issue
Block a user