From 559cd9fc580123d1f3419a0359f03263076489bb Mon Sep 17 00:00:00 2001 From: rainlizard Date: Thu, 9 Nov 2023 21:49:31 +1100 Subject: [PATCH] mirrored placements obey 'Place things anywhere' checkbox --- Scenes/Instances.gd | 11 ++++++++++- Scenes/Selection.gd | 10 +++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Scenes/Instances.gd b/Scenes/Instances.gd index e25c9a78..ae9fdbfc 100644 --- a/Scenes/Instances.gd +++ b/Scenes/Instances.gd @@ -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") @@ -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: @@ -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: diff --git a/Scenes/Selection.gd b/Scenes/Selection.gd index a06a5f37..9acd3822 100644 --- a/Scenes/Selection.gd +++ b/Scenes/Selection.gd @@ -234,13 +234,8 @@ 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 @@ -248,6 +243,7 @@ func place_subtile(placeSubtile): 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: