Implemented cancel building functionality
This commit is contained in:
@@ -7,7 +7,6 @@ import "core:fmt"
|
||||
import inf "infrastructure"
|
||||
|
||||
// PLAN AREA
|
||||
// TODO implement right click 'cancel building functionali'
|
||||
// TODO implement deleting of roads
|
||||
|
||||
Simulator :: struct {
|
||||
@@ -63,7 +62,11 @@ handle_keyboard_input :: proc(self: ^Simulator) {
|
||||
// Generally mouse event handler
|
||||
@(private="file")
|
||||
handle_mouse_input :: proc(self: ^Simulator, pos: rl.Vector2) {
|
||||
if (rl.IsMouseButtonReleased(.LEFT)) do left_click_event(self, pos)
|
||||
if (rl.IsMouseButtonReleased(.LEFT)) {
|
||||
left_click_event(self, pos)
|
||||
} else if (rl.IsMouseButtonReleased(.RIGHT)) {
|
||||
right_click_event(self)
|
||||
}
|
||||
}
|
||||
|
||||
// Handles left click functionality
|
||||
@@ -82,6 +85,20 @@ left_click_event :: proc(self: ^Simulator, pos: rl.Vector2) {
|
||||
self.temp_node_index = cur_node_index
|
||||
}
|
||||
|
||||
// Handles right click functionality
|
||||
@(private="file")
|
||||
right_click_event :: proc(self: ^Simulator) {
|
||||
if self.temp_node_index == nil do return
|
||||
index := self.temp_node_index.?
|
||||
|
||||
temp_node := &self.nodes[index]
|
||||
self.temp_node_index = nil
|
||||
if len(temp_node.roads) > 0 do return
|
||||
|
||||
inf.node_deinit(temp_node)
|
||||
unordered_remove(&self.nodes, index)
|
||||
}
|
||||
|
||||
// Main drawing function
|
||||
draw :: proc(self: ^Simulator, pos: rl.Vector2) {
|
||||
rl.ClearBackground(common.BACKGROUND_COLOUR)
|
||||
@@ -167,15 +184,13 @@ get_intersecting_roads :: proc(self: ^Simulator, start: u32, end: u32) -> []comm
|
||||
@(private="file")
|
||||
split_roads_by_points :: proc(self: ^Simulator, intersections: []common.Intersection_Data, start: u32, end: u32) {
|
||||
if len(intersections) == 0 {
|
||||
road := inf.road_init(start, end)
|
||||
append(&self.roads, road)
|
||||
add_road(self, start, end)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
first_intersection_node := get_node_or_new(self, intersections[0].point)
|
||||
road := inf.road_init(start, first_intersection_node)
|
||||
append(&self.roads, road)
|
||||
add_road(self, start, first_intersection_node)
|
||||
|
||||
for i in 0..<len(intersections) {
|
||||
intersection := intersections[i]
|
||||
@@ -206,7 +221,6 @@ split_roads_by_points :: proc(self: ^Simulator, intersections: []common.Intersec
|
||||
|
||||
last_intersection_road := intersections[len(intersections) - 1]
|
||||
last_intersection_node := get_node_or_new(self, last_intersection_road.point)
|
||||
|
||||
add_road(self, last_intersection_node, end)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user