I don’t know the cause, but I can point out a few issues:
(1)
func is_overlapping(position: Vector2, size: Vector2, occupied_cells) -> bool:
for x in range(size.x): # Use grid size, NOT pixels
for y in range(size.y):
if occupied_cells.has(position):
return true
return false
In this loop, you’re just checking whether occupied_cells has position over and over. I imagine you actually want to check something like has(position + Vector2(x, y)).
Also, you should not use a variable named “position”, because that variable already has a meaning for 2d nodes (there should be a compiler warning about “shadowing” the position variable)
(Same shadowing issue in the method “place_tile”)
(2) I don’t think set_cell is intended for use with differently sized cells. It seems to be doing something here, so I’m not sure if the behavior is intended or not.
(3) There are some variables that can be easily removed to make your code more readable (and bugs easier to find), for example
func generate_straight_street() -> void:
#print("Generating street...")
var start_y = 0
var x = 0
for i in range(STREET_LENGTH):
var y = start_y + i
streets_layer.set_cell(Vector2(x, y), street_source_id, straight_tile_coords)
#print("Street generation complete.")
can be rewritten as
func generate_straight_street() -> void:
for y in range(STREET_LENGTH):
streets_layer.set_cell(Vector2(0, y), street_source_id, straight_tile_coords)
Similar lines: “let y = i” in generate_side_structure, any commented print(…) statements
(4) I don’t have time right now to properly debug this, but I’ll recommend as a general exercise to add a breakpoint to some method that isn’t doing what you want and checking out what all the variables look like at each invocation. For example:
func is_overlapping(_position: Vector2, size: Vector2, occupied_cells) -> bool:
breakpoint
for x in range(size.x):
for y in range(size.y):
if occupied_cells.has(_position + Vector2(x, y)):
return true
return false
Code execution will pause every time you reach the breakpoint, and you will be able to look at each of the current stack variables, e.g. _position, size, and occupied_cells (as well as any vars in the surrounding context). This might help you figure out the issue.