Skip to content

Commit

Permalink
Remove grid overlay truncation behavior (#1995)
Browse files Browse the repository at this point in the history
In the implementation of #1826, I decided to preserve the old truncating behavior as the default.  But after some consideration, there's no real use case for the old behavior, so let's take it out to simplify the code.
  • Loading branch information
kostmo authored Jun 27, 2024
1 parent 1735416 commit d9382ad
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@ world:
xx
placements:
- src: vertical rectangle
truncate: false
offset: [-7, 7]
- src: horizontal rectangle
truncate: false
offset: [7, -7]
placements:
- src: disjoint rectangles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ world:
x
placements:
- src: single tree
truncate: false
offset: [-2, -4]
map: |
i.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ world:
map: ""
placements:
- src: vertical rectangle
truncate: false
- src: horizontal rectangle
truncate: false
- name: combined rectangles single cell base
structure:
palette:
Expand All @@ -56,9 +54,7 @@ world:
x
placements:
- src: vertical rectangle
truncate: false
- src: horizontal rectangle
truncate: false
- name: multi overlap
structure:
palette:
Expand All @@ -68,27 +64,21 @@ world:
placements:
- src: vertical rectangle
offset: [1, 0]
truncate: false
- src: horizontal rectangle
truncate: false
offset: [0, -2]
- src: vertical rectangle
offset: [3, -2]
truncate: false
- src: horizontal rectangle
truncate: false
offset: [3, -4]
- src: vertical rectangle
offset: [5, -4]
truncate: false
placements:
- src: vertical rectangle
offset: [1, -1]
- src: horizontal rectangle
offset: [1, -1]
- src: multi overlap
offset: [1, -6]
truncate: false
- src: combined rectangles blank base
offset: [6, -1]
- src: combined rectangles empty base
Expand Down
10 changes: 0 additions & 10 deletions data/test/standalone-topography/checkerboard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ structures:
placements:
- src: checker pair
offset: [0, 0]
truncate: false
- src: checker pair
offset: [0, -4]
truncate: false
orient:
up: south
- name: checker octo
Expand All @@ -27,27 +25,19 @@ structures:
placements:
- src: checker quad
offset: [0, 0]
truncate: false
- src: checker quad
offset: [8, 0]
truncate: false
- src: checker quad
offset: [0, -8]
truncate: false
- src: checker quad
offset: [8, -8]
truncate: false
placements:
- src: checker octo
offset: [0, 0]
truncate: false
- src: checker octo
offset: [16, 0]
truncate: false
- src: checker octo
offset: [0, -16]
truncate: false
- src: checker octo
offset: [16, -16]
truncate: false
map: ""
7 changes: 0 additions & 7 deletions data/test/standalone-topography/circle-and-crosses.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ structures:
placements:
- src: beam
offset: [0, 3]
truncate: false
- src: beam
offset: [-3, -3]
truncate: false
orient:
up: east
map: ""
Expand All @@ -44,23 +42,18 @@ structures:
placements:
- src: cross
offset: [0, -15]
truncate: false
- src: cross
offset: [0, 0]
truncate: false
orient:
up: east
- src: cross
offset: [15, 0]
truncate: false
orient:
up: south
- src: cross
offset: [15, -15]
truncate: false
orient:
up: west
- src: disc
offset: [8, -8]
truncate: false
map: ""
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,13 @@ data Pose = Pose

data Placement = Placement
{ src :: StructureName
, truncateOverlay :: Bool
, structurePose :: Pose
}
deriving (Eq, Show)

instance FromJSON Placement where
parseJSON = withObject "structure placement" $ \v -> do
src <- v .: "src"
truncateOverlay <- v .:? "truncate" .!= True
offset <- v .:? "offset" .!= origin
orient <- v .:? "orient" .!= defaultOrientation
let structurePose = Pose offset orient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module Swarm.Game.Scenario.Topography.Structure.Assembly (
)
where

import Control.Applicative ((<|>))
import Control.Arrow (left, (&&&))
import Control.Monad (when)
import Data.Coerce
Expand Down Expand Up @@ -40,22 +39,17 @@ overlaySingleStructure ::
Either Text (MergedStructure (Maybe a))
overlaySingleStructure
inheritedStrucDefs
(Placed p@(Placement _ shouldTruncate pose@(Pose loc orientation)) ns)
(Placed p@(Placement _ pose@(Pose loc orientation)) ns)
(MergedStructure inputArea inputPlacements inputWaypoints) = do
MergedStructure overlayArea overlayPlacements overlayWaypoints <-
mergeStructures inheritedStrucDefs (WithParent p) $ structure ns

let mergedWaypoints = inputWaypoints <> map (fmap $ placeOnArea overlayArea) overlayWaypoints
mergedPlacements = inputPlacements <> map (placeOnArea overlayArea) overlayPlacements
mergedArea = mergeFunc (gridContent inputArea) pose overlayArea
mergedArea = overlayGridExpanded (gridContent inputArea) pose overlayArea

return $ MergedStructure mergedArea mergedPlacements mergedWaypoints
where
mergeFunc =
if shouldTruncate
then overlayGridTruncated
else overlayGridExpanded

placeOnArea (PositionedGrid _ overArea) =
offsetLoc (coerce loc)
. modifyLoc (reorientLandmark orientation $ getGridDimensions overArea)
Expand Down Expand Up @@ -113,39 +107,6 @@ overlayGridExpanded
reorientedOverlayCells = Grid $ applyOrientationTransform orientation overlayArea
positionedOverlay = PositionedGrid loc reorientedOverlayCells

-- | NOTE: This ignores the 'loc' parameter of 'PositionedGrid'.
overlayGridTruncated ::
Grid (Maybe a) ->
Pose ->
PositionedGrid (Maybe a) ->
PositionedGrid (Maybe a)
overlayGridTruncated
(Grid inputArea)
(Pose (Location colOffset rowOffset) orientation)
(PositionedGrid _ (Grid overlayArea)) =
PositionedGrid origin
. Grid
. zipWithPad mergeSingleRow inputArea
$ paddedOverlayRows overlayArea
where
zipWithPad f a b = zipWith f a $ b <> repeat Nothing

mergeSingleRow inputRow maybeOverlayRow =
zipWithPad (flip (<|>)) inputRow paddedSingleOverlayRow
where
paddedSingleOverlayRow = maybe [] (applyOffset colOffset) maybeOverlayRow

affineTransformedOverlay = applyOrientationTransform orientation

paddedOverlayRows = applyOffset (negate rowOffset) . map Just . affineTransformedOverlay
applyOffset offsetNum = modifyFront
where
integralOffset = fromIntegral offsetNum
modifyFront =
if integralOffset >= 0
then (replicate integralOffset Nothing <>)
else drop $ abs integralOffset

-- * Validation

elaboratePlacement :: Parentage Placement -> Text
Expand All @@ -158,7 +119,7 @@ elaboratePlacement p =
where
pTxt = case p of
Root -> "root placement"
WithParent (Placement (StructureName sn) _shouldTruncate (Pose loc _)) ->
WithParent (Placement (StructureName sn) (Pose loc _)) ->
T.unwords
[ "placement of"
, quote sn
Expand All @@ -172,7 +133,7 @@ validatePlacement ::
Either Text (Placed (Maybe a))
validatePlacement
structureMap
placement@(Placement sName@(StructureName n) _shouldTruncate (Pose _ orientation)) = do
placement@(Placement sName@(StructureName n) (Pose _ orientation)) = do
t@(_, ns) <-
maybeToEither
(T.unwords ["Could not look up structure", quote n])
Expand Down

0 comments on commit d9382ad

Please sign in to comment.