Skip to content

Commit

Permalink
Fixed Fill on fortified walls
Browse files Browse the repository at this point in the history
  • Loading branch information
rainlizard committed Apr 21, 2024
1 parent 3aff5f0 commit 6577b62
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions Scenes/Selection.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 6577b62

Please sign in to comment.