diff --git a/src/common/constants.odin b/src/common/constants.odin index dd26ede..a93723a 100644 --- a/src/common/constants.odin +++ b/src/common/constants.odin @@ -3,20 +3,20 @@ package common import rl "vendor:raylib" // Screen Width -WIDTH :: 1920 +WIDTH :: 1920 // Screen Height -HEIGHT :: 1080 +HEIGHT :: 1080 // Default Monitor -MONITOR :: 0 +MONITOR :: 0 // Thickness of the road being drawn -ROAD_SIZE :: 20 +ROAD_SIZE :: 20 // Radius of the node -NODE_RADIUS :: 20 +NODE_RADIUS :: 20 // Size of designated radius that determines when position is within node's 'sphere' -NODE_SNAP_RADIUS :: 3 +NODE_SNAP_RADIUS :: 3 // Default text size -TEXT_SIZE :: 50 +TEXT_SIZE :: 50 // Default road colour ROAD_COLOUR :: rl.BLACK @@ -31,7 +31,4 @@ NODE_CURSOR_COLOUR :: rl.BLUE // The colour of the overlay displaying the snap radius NODE_SNAP_COLOUR :: rl.PINK // The default colour of the text displayed -TEXT_COLOUR :: rl.BLACK - -// Background Colour -BACKGROUND_COLOUR :: rl.LIGHTGRAY \ No newline at end of file +TEXT_COLOUR :: rl.BLACK \ No newline at end of file diff --git a/src/common/structures.odin b/src/common/structures.odin index d383d57..977c072 100644 --- a/src/common/structures.odin +++ b/src/common/structures.odin @@ -10,6 +10,7 @@ Intersection_Data :: struct { point: rl.Vector2, } +// Tracks the entity type Entity :: enum { Node, Road, diff --git a/src/draw.odin b/src/draw.odin index be75c92..add8018 100644 --- a/src/draw.odin +++ b/src/draw.odin @@ -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)) diff --git a/src/infrastructure/node.odin b/src/infrastructure/node.odin index 6d99190..15b3f97 100644 --- a/src/infrastructure/node.odin +++ b/src/infrastructure/node.odin @@ -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.. 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 diff --git a/src/simulator.odin b/src/simulator.odin index 240a3e8..0403361 100644 --- a/src/simulator.odin +++ b/src/simulator.odin @@ -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