Move to using RoomLink datatype

This commit is contained in:
2021-11-23 20:45:39 +00:00
parent a66ea1d922
commit 1f2d767d5e
18 changed files with 160 additions and 122 deletions
+6 -1
View File
@@ -1,12 +1,14 @@
module Dodge.Room.Path
( gridPoints
, linksAndPath
, linksAndPath'
, makeGrid
, createPathGrid
)
where
import Dodge.LevelGen.Data
import Dodge.LevelGen.StaticWalls
import Dodge.RoomLink
import Geometry
import Data.Function (on)
@@ -18,7 +20,7 @@ import qualified Control.Foldl as L
createPathGrid :: Room -> Room
createPathGrid rm = rm
{ _rmPath = linksAndPath (_rmOutLinks rm ++ _rmInLinks rm) filterGrid }
{ _rmPath = linksAndPath (map lnkPosDir $ _rmOutLinks rm ++ _rmInLinks rm) filterGrid }
where
filterGrid = filter (\p -> pairInPolys (_rmPolys rm) p && testCrossWalls outerWalls p) grid
grid = fromMaybe [] $ shiftedGrid <$> minx <*> maxx <*> miny <*> maxy
@@ -37,6 +39,9 @@ linksAndPath lnks subpth = subpth ++ concatMap linkClosest lnks
where
linkClosest (p,_) = doublePair (p, minimumBy (compare `on` dist p) $ map fst subpth)
linksAndPath' :: [RoomLink] -> [(Point2,Point2)] -> [(Point2,Point2)]
linksAndPath' = linksAndPath . map lnkPosDir
testCrossWalls
:: [(Point2,Point2)]
-> (Point2,Point2)