Implemented Entity tagged union for highlighted entity (similar to abstract class in some ways)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
const std = @import("std");
|
||||
const Vector2 = @import("raylib").Vector2;
|
||||
|
||||
const c = @import("../constants.zig");
|
||||
const c = @import("../common/constants.zig");
|
||||
const e = @import("../errors.zig");
|
||||
const Node = @import("node.zig").Node;
|
||||
const Road = @import("road.zig").Road;
|
||||
@@ -53,7 +53,7 @@ pub const NodeManager = struct {
|
||||
/// otherwise creates a new node and returns its pointer
|
||||
pub fn getSelectedNode(self: *NodeManager, allocator: std.mem.Allocator, pos: Vector2) !*Node {
|
||||
for (self.nodes.items) |node| {
|
||||
if (node.posWithinRadius(pos)) return node;
|
||||
if (node.withinSnapRadius(pos)) return node;
|
||||
}
|
||||
|
||||
// No node is within that position, so we must create a new one
|
||||
@@ -98,6 +98,14 @@ pub const NodeManager = struct {
|
||||
|
||||
return e.Entity.NotFound;
|
||||
}
|
||||
|
||||
pub fn getHighlightedNode(self: *const NodeManager, pos: Vector2) ?*Node {
|
||||
for (self.nodes.items) |node| {
|
||||
if (node.withinRadius(pos)) return node;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
const expect = std.testing.expect;
|
||||
|
||||
Reference in New Issue
Block a user