From 64463e82b26d5346c879694b0b63b4114160aa27 Mon Sep 17 00:00:00 2001 From: Marto Date: Wed, 8 Apr 2026 01:32:58 +0200 Subject: [PATCH] Some more fixes and some more errors --- src/infrastructure/node.zig | 8 +++++++- src/simulator.zig | 8 ++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/infrastructure/node.zig b/src/infrastructure/node.zig index f649956..42662a6 100644 --- a/src/infrastructure/node.zig +++ b/src/infrastructure/node.zig @@ -33,7 +33,10 @@ pub const Node = struct { /// /// Returns error if the road is not within the node pub fn unreferenceRoad(self: *Node, road: *const Road) !void { - if (self.roadInList(road)) |i| _ = self.roads.swapRemove(i); + if (self.roadInList(road)) |i| { + _ = self.roads.swapRemove(i); + return; + } return error.InvalidNode; } @@ -43,7 +46,10 @@ pub const Node = struct { 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; diff --git a/src/simulator.zig b/src/simulator.zig index 635bcfe..cbc4d79 100644 --- a/src/simulator.zig +++ b/src/simulator.zig @@ -77,15 +77,19 @@ pub const Simulator = struct { } else if (self.mode == .BUILD and rl.isMouseButtonReleased(.right)) { if (self.node_man.temp_node) |node| { - // todo + // todo proper error handling self.node_man.removeNode(node) catch {}; } } else if (self.mode == .DELETE and rl.isMouseButtonReleased(.left) and self.road_man.highlighted_road != null) { - // todo + const nodes = self.road_man.highlighted_road.?.nodes; self.road_man.remove(self.road_man.highlighted_road.?) catch |err| { std.debug.panic("Failed to remove the road: {}\n", .{err}); }; + + // todo proper error handling + self.node_man.removeNode(nodes[0]) catch {}; + self.node_man.removeNode(nodes[1]) catch {}; } }