Skip to content

Commit

Permalink
possibly fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
kostmo committed Sep 16, 2024
1 parent 6e7278d commit 2cfc312
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2cfc312

Please sign in to comment.