Basic drawing
This commit is contained in:
@@ -30,14 +30,39 @@ pub const Simulator = struct {
|
||||
}
|
||||
|
||||
pub fn handleInput(self: *Simulator, pos: rl.Vector2) void {
|
||||
self.handleKeyboardInput();
|
||||
self.handleMouseInput(pos);
|
||||
}
|
||||
|
||||
fn handleKeyboardInput(self: *Simulator) void {
|
||||
if (rl.isKeyReleased(.c)) self.clear();
|
||||
}
|
||||
|
||||
fn handleMouseInput(self: *Simulator, pos: rl.Vector2) void {
|
||||
if (rl.isMouseButtonReleased(.left)) self.leftClickEvent(pos);
|
||||
}
|
||||
|
||||
fn leftClickEvent(self: *Simulator, pos: rl.Vector2) void {
|
||||
// TODO
|
||||
const cur_node = self.node_man.getSelectedNode(self.allocator, pos) catch |err| {
|
||||
std.debug.panic("Failed to append the newly created node at pos ({d}, {d}) to node list: {}\n", .{
|
||||
pos.x, pos.y, err
|
||||
});
|
||||
};
|
||||
|
||||
if (self.node_man.temp_node) |temp| {
|
||||
self.road_man.addRoad(self.allocator, temp, cur_node) catch |err| {
|
||||
std.debug.panic("Failed to add a new road or assigning its nodes: {}\n", .{err});
|
||||
};
|
||||
|
||||
self.node_man.temp_node = null;
|
||||
return;
|
||||
}
|
||||
|
||||
self.node_man.temp_node = cur_node;
|
||||
}
|
||||
|
||||
fn clear(self: *Simulator) void {
|
||||
self.road_man.clear();
|
||||
self.node_man.clear(self.allocator);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user