From 6577b62432ebb76a3c939a30507bf4cc91c3018d Mon Sep 17 00:00:00 2001 From: rainlizard <15337628+rainlizard@users.noreply.github.com> Date: Mon, 22 Apr 2024 00:20:04 +1000 Subject: [PATCH] Fixed Fill on fortified walls --- Scenes/Selection.gd | 47 +++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/Scenes/Selection.gd b/Scenes/Selection.gd index 22cd104a..01c83647 100644 --- a/Scenes/Selection.gd +++ b/Scenes/Selection.gd @@ -172,39 +172,47 @@ func construct_shape_for_placement(constructType): CONSTRUCT_FILL: var beginTile = oSelector.world2tile(get_global_mouse_position()) - # Prevent clicking outside - if beginTile.x < oEditor.fieldBoundary.position.x: return - if beginTile.x > oEditor.fieldBoundary.end.x-1: return - if beginTile.y < oEditor.fieldBoundary.position.y: return - if beginTile.y > oEditor.fieldBoundary.end.y-1: return + if not oEditor.fieldBoundary.has_point(beginTile): + return - var coordsToCheck = [beginTile] var fillTargetID = oSelector.get_slabID_at_pos(oSelector.cursorTile) - var checkedCoords = {} # Use a dictionary to mimic set behavior for checked coordinates + var checkedCoords = {} + var coordsToCheck = [beginTile] + + var targetIsFortifiedWall = Slabs.auto_wall_updates_these.has(fillTargetID) var preventFillingBorder = false if fillTargetID == Slabs.ROCK: preventFillingBorder = true - while coordsToCheck.size() > 0: + var neighborOffsets = [Vector2(0, 1), Vector2(0, -1), Vector2(1, 0), Vector2(-1, 0)] + + while coordsToCheck: var coord = coordsToCheck.pop_back() - - if coord in checkedCoords: # Skip if already checked + if checkedCoords.has(coord): continue + checkedCoords[coord] = true - if preventFillingBorder: - if coord.x < oEditor.fieldBoundary.position.x: continue - if coord.x > oEditor.fieldBoundary.end.x-1: continue - if coord.y < oEditor.fieldBoundary.position.y: continue - if coord.y > oEditor.fieldBoundary.end.y-1: continue + if preventFillingBorder and not oEditor.fieldBoundary.has_point(coord): + continue + + var currentSlabID = oSelector.get_slabID_at_pos(coord) - if oSelector.get_slabID_at_pos(coord) == fillTargetID: + var shouldAppend = false + if targetIsFortifiedWall: + if Slabs.auto_wall_updates_these.has(currentSlabID): + shouldAppend = true + else: + if currentSlabID == fillTargetID: + shouldAppend = true + + if shouldAppend: shapePositionArray.append(coord) - var neighbors = [coord + Vector2(0,1), coord + Vector2(0,-1), coord + Vector2(1,0), coord + Vector2(-1,0)] - for neighbor in neighbors: - if not checkedCoords.has(neighbor): + for offset in neighborOffsets: + var neighbor = coord + offset + if not checkedCoords.has(neighbor) and oEditor.fieldBoundary.has_point(neighbor): coordsToCheck.append(neighbor) if oSlabStyle.visible == true: @@ -233,6 +241,7 @@ func construct_shape_for_placement(constructType): var updateNearby = some_manual_placements_dont_update_nearby() oSlabPlacement.generate_slabs_based_on_id(shapePositionArray, updateNearby) + func some_manual_placements_dont_update_nearby(): # Fake Slabs don't update the surroundings (! HAD TO COMMENT THIS OUT BECAUSE IT BREAKS CUSTOM SLABSET SLABS) # if oCustomSlabsTab.visible == true and oPickSlabWindow.oSelectedRect.visible == true: