Final improvements and refactorings
This commit is contained in:
@@ -32,6 +32,3 @@ NODE_CURSOR_COLOUR :: rl.BLUE
|
||||
NODE_SNAP_COLOUR :: rl.PINK
|
||||
// The default colour of the text displayed
|
||||
TEXT_COLOUR :: rl.BLACK
|
||||
|
||||
// Background Colour
|
||||
BACKGROUND_COLOUR :: rl.LIGHTGRAY
|
||||
@@ -10,6 +10,7 @@ Intersection_Data :: struct {
|
||||
point: rl.Vector2,
|
||||
}
|
||||
|
||||
// Tracks the entity type
|
||||
Entity :: enum {
|
||||
Node,
|
||||
Road,
|
||||
|
||||
@@ -7,7 +7,7 @@ import "common"
|
||||
|
||||
// Main drawing function
|
||||
draw :: proc(self: ^Simulator, pos: rl.Vector2) {
|
||||
rl.ClearBackground(common.BACKGROUND_COLOUR)
|
||||
rl.ClearBackground(rl.LIGHTGRAY)
|
||||
|
||||
// draw roads
|
||||
for &road, index in self.roads {
|
||||
@@ -33,12 +33,15 @@ draw :: proc(self: ^Simulator, pos: rl.Vector2) {
|
||||
// draw temp road if exists
|
||||
if val, ok := self.temp_node.?; ok {
|
||||
rl.DrawLineEx(self.nodes[val].pos, pos, common.ROAD_SIZE, common.ROAD_COLOUR)
|
||||
rl.DrawCircleV(pos, common.NODE_RADIUS, common.NODE_BUILD_COLOUR)
|
||||
|
||||
rl.DrawCircleV(self.nodes[val].pos, common.NODE_RADIUS, common.NODE_BUILD_COLOUR)
|
||||
rl.DrawCircleV(pos, common.NODE_RADIUS, common.NODE_CURSOR_COLOUR)
|
||||
}
|
||||
|
||||
draw_ui(self)
|
||||
}
|
||||
|
||||
// Drawing UI text, mostly for debugging purposes
|
||||
@(private="file")
|
||||
draw_ui :: proc(self: ^Simulator) {
|
||||
entity_count := fmt.ctprintf("Nodes: %d\nRoads: %d", len(self.nodes), len(self.roads))
|
||||
|
||||
@@ -36,8 +36,7 @@ node_within_snapping_radius :: proc(self: ^Node, pos: rl.Vector2) -> bool {
|
||||
)
|
||||
}
|
||||
|
||||
// Tries to remove the road reference from the node;
|
||||
// Returns false if failed
|
||||
// Tries to remove the road reference from the node; returns false if failed
|
||||
node_unreference_road :: proc(self: ^Node, road_to_unref: u32) -> bool {
|
||||
for i in 0..<len(self.roads) {
|
||||
if self.roads[i] != road_to_unref do continue
|
||||
@@ -49,6 +48,7 @@ node_unreference_road :: proc(self: ^Node, road_to_unref: u32) -> bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// Attempts to update the existing road references with new one; returns false if it can't find the old reference
|
||||
node_update_road_reference :: proc(self: ^Node, old_ref: u32, new_ref: u32) -> bool {
|
||||
for &road in self.roads {
|
||||
if road != old_ref do continue
|
||||
|
||||
@@ -41,6 +41,7 @@ update :: proc(self: ^Simulator, pos: rl.Vector2) {
|
||||
update_highlighted_road(self, pos)
|
||||
}
|
||||
|
||||
// Implementation of removing the road after a click has been registered
|
||||
@private
|
||||
demolish_road :: proc(self: ^Simulator) {
|
||||
if !self.delete_mode do return
|
||||
@@ -48,6 +49,7 @@ demolish_road :: proc(self: ^Simulator) {
|
||||
if road, ok := self.highlighted_road.?; ok do delete_road(self, road)
|
||||
}
|
||||
|
||||
// Implementation of road building after a click has been registered
|
||||
@private
|
||||
create_road :: proc(self: ^Simulator, pos: rl.Vector2) {
|
||||
// BUILD
|
||||
@@ -153,6 +155,7 @@ add_road :: proc(self: ^Simulator, start: u32, end: u32) {
|
||||
append(&self.nodes[end].roads, road_index)
|
||||
}
|
||||
|
||||
// Deletes the road which index was sent in, alongside deleting references of said road and removal of nodes if that road was their only connection
|
||||
@(private="file")
|
||||
delete_road :: proc(self: ^Simulator, road_to_delete: u32) {
|
||||
// First we need to unreference this road from surrounding nodes and then delete those nodes IF this was the last road connection
|
||||
|
||||
Reference in New Issue
Block a user