Remove GenWorld datatype

This commit is contained in:
2022-06-02 19:06:00 +01:00
parent 35cd213bcf
commit 7c4a853d70
9 changed files with 95 additions and 107 deletions
+8 -10
View File
@@ -54,11 +54,10 @@ addBlock (p:ps) wl hp hps bm w
ips = map zoneOfPoint $ uncurry (divideLine (2*zoneSize)) (_wlLine wl)
addBlock _ _ _ _ _ _ = error "Trying to add a block with incomplete polygon"
placeBlock :: [Point2] -> Int -> Wall -> [Int] -> BlockMaterial -> GenWorld -> (Int,GenWorld)
placeBlock poly i wl is bm gw
= (0, gw & gWorld .~ foldr (uncurry removePathsCrossing) wWithBlock pairs)
placeBlock :: [Point2] -> Int -> Wall -> [Int] -> BlockMaterial -> World -> (Int,World)
placeBlock poly i wl is bm w
= (0, foldr (uncurry removePathsCrossing) wWithBlock pairs)
where
w = _gWorld gw
pairs = loopPairs poly
wWithBlock = addBlock poly wl i is bm w
@@ -70,13 +69,12 @@ placeLineBlock
-> Float -- ^ Block depth
-> Point2 -- ^ Start point (symmetric)
-> Point2 -- ^ End point (symmetric)
-> GenWorld
-> (Int, GenWorld)
-> World
-> (Int, World)
placeLineBlock basePane bm blockWidth depth a b gw = ( 0
, gw & gWorld .~ removePathsCrossing a b (foldr insertWall (insertBlocks w) listWalls)
, removePathsCrossing a b (foldr insertWall (insertBlocks gw) listWalls)
)
where
w = _gWorld gw
psOnLine = divideLineOddNumPoints blockWidth a b
halfBlockWidth = dist a b / fromIntegral (length psOnLine - 1)
blockCenPs = snd $ evenOddSplit psOnLine
@@ -85,8 +83,8 @@ placeLineBlock basePane bm blockWidth depth a b gw = ( 0
cornerPoints = reverse $ rectWH halfBlockWidth depth -- goes clockwise around the block
cornersAt p = fmap ( (p +.+) . rotateV (argV (b -.- a)) ) cornerPoints
linesAt p = loopPairs $ cornersAt p
wlid = IM.newKey $ _walls w
blid = IM.newKey $ _blocks w
wlid = IM.newKey $ _walls gw
blid = IM.newKey $ _blocks gw
insertBlock i = over blocks $ IM.insert (i+blid) Block
{ _blID = i + blid, _blWallIDs = IS.fromList $ ksAtI i
, _blHPs = [5,5], _blShadows = shadowsAt i, _blMaterial = bm}
+10 -12
View File
@@ -21,12 +21,11 @@ plDoor :: Color
-> (World -> Bool) -- ^ Opening condition
-> [(Point2,Point2)] -- ^ Door positions, closed to open.
-- Bumped out up and down by 9, not widened
-> GenWorld
-> (Int,GenWorld)
plDoor col cond pss gw = (drid, gw & gWorld .~ (addWalls w & doors %~ addDoor))
-> World
-> (Int,World)
plDoor col cond pss gw = (drid, (addWalls gw & doors %~ addDoor))
where
w = _gWorld gw
drid = IM.newKey $ _doors w
drid = IM.newKey $ _doors gw
addDoor = IM.insert drid $ Door
{ _drID = drid
, _drWallIDs = IS.fromList wlids
@@ -38,7 +37,7 @@ plDoor col cond pss gw = (drid, gw & gWorld .~ (addWalls w & doors %~ addDoor))
, _drClosePos = last pss
}
nsteps = length pss - 1
wlids = take 4 [IM.newKey $ _walls w ..]
wlids = take 4 [IM.newKey $ _walls gw ..]
wlps' = uncurry (rectanglePairs 9) $ head pss
addWalls w' = foldl' (addDoorWall col False) w' $ zip wlids wlps'
@@ -106,13 +105,12 @@ plSlideDoor
-> Point2
-> Point2
-> Float
-> GenWorld
-> (Int, GenWorld)
-> World
-> (Int, World)
plSlideDoor isPathable col cond shiftOffset a b speed gw
= (drid, gw & gWorld .~ (addWalls w & doors %~ addDoor))
= (drid, (addWalls gw & doors %~ addDoor))
where
w = _gWorld gw
drid = IM.newKey $ _doors w
drid = IM.newKey $ _doors gw
addDoor = IM.insert drid $ Door
{ _drID = drid
, _drWallIDs = IS.fromList wlids
@@ -127,7 +125,7 @@ plSlideDoor isPathable col cond shiftOffset a b speed gw
pairs = rectanglePairs 9 a b
shiftedPairs = map (bimap shiftLeft shiftLeft) pairs
shiftLeft = (+.+ (a -.- b +.+ shiftOffset *.* normalizeV (b -.- a)))
wlids = take 4 [IM.newKey $ _walls w ..]
wlids = take 4 [IM.newKey $ _walls gw ..]
-- old code that may help with pathing
--import Dodge.LevelGen.Pathing
--import Data.Graph.Inductive hiding ((&))