Implemented cancel building functionality
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
debug_build
|
||||||
@@ -13,7 +13,7 @@ Node :: struct {
|
|||||||
roads: [dynamic]u32,
|
roads: [dynamic]u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Node Initialisation
|
// Constructor
|
||||||
node_init :: proc(new_pos: rl.Vector2) -> Node {
|
node_init :: proc(new_pos: rl.Vector2) -> Node {
|
||||||
return {
|
return {
|
||||||
enabled = true,
|
enabled = true,
|
||||||
@@ -22,6 +22,11 @@ node_init :: proc(new_pos: rl.Vector2) -> Node {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
node_deinit :: proc(self: ^Node) {
|
||||||
|
delete(self.roads)
|
||||||
|
}
|
||||||
|
|
||||||
// Returns whether passed pos(ition) is within this node's snapping radius
|
// Returns whether passed pos(ition) is within this node's snapping radius
|
||||||
node_within_snapping_radius :: proc(self: ^Node, pos: rl.Vector2) -> bool {
|
node_within_snapping_radius :: proc(self: ^Node, pos: rl.Vector2) -> bool {
|
||||||
return rl.CheckCollisionPointCircle(
|
return rl.CheckCollisionPointCircle(
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import "core:fmt"
|
|||||||
import inf "infrastructure"
|
import inf "infrastructure"
|
||||||
|
|
||||||
// PLAN AREA
|
// PLAN AREA
|
||||||
// TODO implement right click 'cancel building functionali'
|
|
||||||
// TODO implement deleting of roads
|
// TODO implement deleting of roads
|
||||||
|
|
||||||
Simulator :: struct {
|
Simulator :: struct {
|
||||||
@@ -63,7 +62,11 @@ handle_keyboard_input :: proc(self: ^Simulator) {
|
|||||||
// Generally mouse event handler
|
// Generally mouse event handler
|
||||||
@(private="file")
|
@(private="file")
|
||||||
handle_mouse_input :: proc(self: ^Simulator, pos: rl.Vector2) {
|
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
|
// Handles left click functionality
|
||||||
@@ -82,6 +85,20 @@ left_click_event :: proc(self: ^Simulator, pos: rl.Vector2) {
|
|||||||
self.temp_node_index = cur_node_index
|
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
|
// Main drawing function
|
||||||
draw :: proc(self: ^Simulator, pos: rl.Vector2) {
|
draw :: proc(self: ^Simulator, pos: rl.Vector2) {
|
||||||
rl.ClearBackground(common.BACKGROUND_COLOUR)
|
rl.ClearBackground(common.BACKGROUND_COLOUR)
|
||||||
@@ -167,15 +184,13 @@ get_intersecting_roads :: proc(self: ^Simulator, start: u32, end: u32) -> []comm
|
|||||||
@(private="file")
|
@(private="file")
|
||||||
split_roads_by_points :: proc(self: ^Simulator, intersections: []common.Intersection_Data, start: u32, end: u32) {
|
split_roads_by_points :: proc(self: ^Simulator, intersections: []common.Intersection_Data, start: u32, end: u32) {
|
||||||
if len(intersections) == 0 {
|
if len(intersections) == 0 {
|
||||||
road := inf.road_init(start, end)
|
add_road(self, start, end)
|
||||||
append(&self.roads, road)
|
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
first_intersection_node := get_node_or_new(self, intersections[0].point)
|
first_intersection_node := get_node_or_new(self, intersections[0].point)
|
||||||
road := inf.road_init(start, first_intersection_node)
|
add_road(self, start, first_intersection_node)
|
||||||
append(&self.roads, road)
|
|
||||||
|
|
||||||
for i in 0..<len(intersections) {
|
for i in 0..<len(intersections) {
|
||||||
intersection := intersections[i]
|
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_road := intersections[len(intersections) - 1]
|
||||||
last_intersection_node := get_node_or_new(self, last_intersection_road.point)
|
last_intersection_node := get_node_or_new(self, last_intersection_road.point)
|
||||||
|
|
||||||
add_road(self, last_intersection_node, end)
|
add_road(self, last_intersection_node, end)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user