Implemented right click functionality
This commit is contained in:
@@ -87,8 +87,6 @@ pub const NodeManager = struct {
|
||||
|
||||
/// Deletes node, returns error if node still has road references
|
||||
pub fn deleteNode(self: *NodeManager, allocator: std.mem.Allocator, node_to_delete: *Node) !void {
|
||||
if (node_to_delete.roads.items.len != 0) return e.Entity.HasReferences;
|
||||
|
||||
for (0..self.nodes.items.len) |i| {
|
||||
if (self.nodes.items[i] != node_to_delete) continue;
|
||||
|
||||
@@ -108,6 +106,18 @@ pub const NodeManager = struct {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
pub fn deleteTempNode(self: *NodeManager, allocator: std.mem.Allocator) void {
|
||||
if (self.temp_node == null) return;
|
||||
|
||||
const node = self.temp_node.?;
|
||||
if (node.roads.items.len == 0)
|
||||
self.deleteNode(allocator, node) catch |err| {
|
||||
std.debug.panic("Failed to delete the temporary node: {}\n", .{err});
|
||||
};
|
||||
|
||||
self.temp_node = null;
|
||||
}
|
||||
};
|
||||
|
||||
const expect = std.testing.expect;
|
||||
|
||||
@@ -114,7 +114,12 @@ pub const Simulator = struct {
|
||||
|
||||
/// Sub input handling function for mouse input only
|
||||
fn handleMouseInput(self: *Simulator, pos: rl.Vector2) void {
|
||||
if (rl.isMouseButtonReleased(.left)) self.leftClickEvent(pos);
|
||||
if (rl.isMouseButtonReleased(.left)) {
|
||||
self.leftClickEvent(pos);
|
||||
return;
|
||||
}
|
||||
|
||||
if (rl.isMouseButtonReleased(.right)) self.node_man.deleteTempNode(self.allocator);
|
||||
}
|
||||
|
||||
/// Function that handles functionality that executes upon left click
|
||||
|
||||
Reference in New Issue
Block a user