Skip to content

Commit

Permalink
mirrored placements obey 'Place things anywhere' checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
rainlizard committed Nov 9, 2023
1 parent b37951a commit 559cd9f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
11 changes: 10 additions & 1 deletion Scenes/Instances.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ onready var oMirrorFlipCheckBox = Nodelist.list["oMirrorFlipCheckBox"]
onready var oSlabPlacement = Nodelist.list["oSlabPlacement"]
onready var oMirrorPlacementCheckBox = Nodelist.list["oMirrorPlacementCheckBox"]
onready var oSelector = Nodelist.list["oSelector"]
onready var oPlaceThingsAnywhere = Nodelist.list["oPlaceThingsAnywhere"]


var thingScn = preload("res://Scenes/ThingInstance.tscn")
var actionPointScn = preload("res://Scenes/ActionPointInstance.tscn")
Expand Down Expand Up @@ -137,6 +139,12 @@ func mirror_deletion_of_instance(instanceBeingDeleted):
if getNodeAtMirroredPosition.thingType == instanceBeingDeleted.thingType:
getNodeAtMirroredPosition.queue_free()

func placement_is_obstructed(thingType, placeSubtile):
var detectTerrainHeight = oDataClm.height[oDataClmPos.get_cell(placeSubtile.x,placeSubtile.y)]
if oPlaceThingsAnywhere.pressed == false and detectTerrainHeight >= 5 and thingType != Things.TYPE.EXTRA: # Lights and Action Points can always be placed anywhere
return true
return false

func mirror_instance_placement(newThingType, newSubtype, fromPos, newOwner, mirrorType):
var actions = []
match oMirrorOptions.splitType:
Expand All @@ -156,7 +164,8 @@ func mirror_instance_placement(newThingType, newSubtype, fromPos, newOwner, mirr
var toPos = oMirrorOptions.mirror_calculation(performAction, flip, fromPos, fieldX, fieldY)

toPos = Vector3(toPos.x, toPos.y, fromPosZ)

if placement_is_obstructed(newThingType, Vector2(toPos.x,toPos.y)) == true:
continue
# Prevent overlapping placements along the center line
if oMirrorOptions.splitType == 0: # Don't use 'match', 'continue' doesn't work correctly there.
if toPos == fromPos:
Expand Down
10 changes: 3 additions & 7 deletions Scenes/Selection.gd
Original file line number Diff line number Diff line change
Expand Up @@ -234,20 +234,16 @@ func some_manual_placements_dont_update_nearby():
func place_subtile(placeSubtile):
if placeSubtile.x < 0 or placeSubtile.y < 0 or placeSubtile.x >= (M.xSize*3) or placeSubtile.y >= (M.ySize*3):
return

var detectTerrainHeight = oDataClm.height[oDataClmPos.get_cell(placeSubtile.x,placeSubtile.y)]

if oPlaceThingsAnywhere.pressed == false:
if detectTerrainHeight >= 5:
if paintThingType != Things.TYPE.EXTRA: # Lights and Action Points can always be placed anywhere
return
if oInstances.placement_is_obstructed(paintThingType, placeSubtile) == true:
return

if oSelector.position_meeting(get_global_mouse_position(), "Instance") == true:
if Input.is_action_pressed("place_overlapping") == false: # While holding control, allow overlapping placements
return
oEditor.mapHasBeenEdited = true

if paintThingType != null:
var detectTerrainHeight = oDataClm.height[oDataClmPos.get_cell(placeSubtile.x,placeSubtile.y)]
var newPos:Vector3 = Vector3(placeSubtile.x + 0.5, placeSubtile.y + 0.5, detectTerrainHeight)

match paintThingType:
Expand Down

0 comments on commit 559cd9f

Please sign in to comment.