diff --git a/data/scenarios/Testing/1780-structure-merge-expansion/sequential-placement.yaml b/data/scenarios/Testing/1780-structure-merge-expansion/sequential-placement.yaml index c82fbb2c8..fc6660bad 100644 --- a/data/scenarios/Testing/1780-structure-merge-expansion/sequential-placement.yaml +++ b/data/scenarios/Testing/1780-structure-merge-expansion/sequential-placement.yaml @@ -28,11 +28,18 @@ world: - src: house orient: flip: true - offset: [-8, 0] + offset: [-6, 0] - src: house + + # - src: house + # orient: + # flip: true + # - src: house + # offset: [6, 0] map: "xx" palette: 'Ω': [grass, erase, base] + mask: '.' placements: - src: block offset: [0, -1] diff --git a/src/swarm-topography/Swarm/Game/Scenario/Topography/Structure/Assembly.hs b/src/swarm-topography/Swarm/Game/Scenario/Topography/Structure/Assembly.hs index 7635e5669..769359e20 100644 --- a/src/swarm-topography/Swarm/Game/Scenario/Topography/Structure/Assembly.hs +++ b/src/swarm-topography/Swarm/Game/Scenario/Topography/Structure/Assembly.hs @@ -23,7 +23,6 @@ import Data.Text qualified as T import Linear.Affine import Swarm.Game.Location import Swarm.Game.Scenario.Topography.Area -import Swarm.Game.Scenario.Topography.Grid import Swarm.Game.Scenario.Topography.Navigation.Waypoint import Swarm.Game.Scenario.Topography.Placement import Swarm.Game.Scenario.Topography.Structure @@ -50,8 +49,7 @@ overlaySingleStructure let mergedWaypoints = inputWaypoints <> map (fmap $ placeOnArea overlayArea) overlayWaypoints mergedPlacements = inputPlacements <> map (placeOnArea overlayArea) overlayPlacements - inputGridContent = gridContent inputArea - mergedArea2 = overlayGridExpanded (show sName) inputGridContent pose overlayArea + mergedArea2 = overlayGridExpanded (show sName) inputArea pose overlayArea mergedArea = trace (unwords [ "For placement of" , show sName @@ -110,20 +108,35 @@ mergeStructures inheritedStrucDefs parentPlacement (Structure origArea subStruct overlayGridExpanded :: String -> - Grid (Maybe a) -> + PositionedGrid (Maybe a) -> Pose -> PositionedGrid (Maybe a) -> PositionedGrid (Maybe a) overlayGridExpanded note - inputGrid - (Pose loc orientation) - (PositionedGrid c overlayArea) = - trace (unwords ["In overlayGridExpanded for", note, "where c = ", show c, "and loc = ", show loc]) output + baseGrid + (Pose yamlPlacementOffset orientation) + -- NOTE: The 'childAdjustedOrigin' is the sum of origin adjustments + -- to completely assemble some substructure. However, we discard + -- this when we place a substructure into a new base grid. + (PositionedGrid childAdjustedOrigin overlayArea) = + trace (unwords [ + "In overlayGridExpanded for" + , note + , "where childAdjustedOrigin =" + , show childAdjustedOrigin + , "and placementOffset =" + , show yamlPlacementOffset + , "and placementAdjustedByOrigin =" + , show placementAdjustedByOrigin + , ". New origin will be:" + , show $ gridPosition output + ]) output where - output = PositionedGrid origin inputGrid <> positionedOverlay + output = baseGrid <> positionedOverlay reorientedOverlayCells = applyOrientationTransform orientation overlayArea - positionedOverlay = PositionedGrid loc reorientedOverlayCells + placementAdjustedByOrigin = gridPosition baseGrid .+^ (yamlPlacementOffset .-. origin) + positionedOverlay = PositionedGrid placementAdjustedByOrigin reorientedOverlayCells -- * Validation diff --git a/src/swarm-topography/Swarm/Game/Scenario/Topography/Structure/Overlay.hs b/src/swarm-topography/Swarm/Game/Scenario/Topography/Structure/Overlay.hs index 86444ed5a..0bff92854 100644 --- a/src/swarm-topography/Swarm/Game/Scenario/Topography/Structure/Overlay.hs +++ b/src/swarm-topography/Swarm/Game/Scenario/Topography/Structure/Overlay.hs @@ -9,10 +9,11 @@ module Swarm.Game.Scenario.Topography.Structure.Overlay ( ) where import Control.Applicative +import Debug.Trace import Data.Function (on) import Data.Int (Int32) import Data.Tuple (swap) -import Linear +import Linear hiding (trace) import Swarm.Game.Location import Swarm.Game.Scenario.Topography.Area import Swarm.Game.Scenario.Topography.Grid @@ -113,10 +114,19 @@ instance (Alternative f) => Semigroup (PositionedGrid (f a)) where -- We don't have to adjust the origin if the base layer lies -- to the northwest of the overlay layer. clampedDelta = V2 (min 0 deltaX) (max 0 deltaY) - newOrigin = baseLoc .-^ clampedDelta + newOrigin2 = baseLoc .-^ clampedDelta + + newOrigin = trace (unwords [ + "COMBINING baseLoc" + , show baseLoc + , "with overlayLoc" + , show overlayLoc + , "to get" + , show newOrigin2 + ]) newOrigin2 paddedOverlayPair = - padSouthwest originDelta $ + padSouthwest (overlayLoc .-. origin) $ OverlayPair baseGrid overlayGrid -- | NOTE: We only make explicit grid adjustments for