Cleanup, move towards unifying zones

This commit is contained in:
2021-09-11 15:52:43 +01:00
parent 27e4f16dd9
commit aa7413a29f
57 changed files with 157 additions and 331 deletions
+8 -15
View File
@@ -5,11 +5,12 @@ import Dodge.LevelGen
import Dodge.LevelGen.StaticWalls
--import Dodge.LevelGen.Data
import Dodge.Base
import Dodge.Base.Zone
import Dodge.Zone
import Dodge.Zone.Data
import Dodge.GameRoom
import Dodge.Bounds
--import Dodge.RandomHelp
import Dodge.Graph
--import Dodge.Graph
import Dodge.Layout.Tree.Polymorphic (applyToRoot)
import Dodge.Room.Data
import Dodge.Room.AddTile
@@ -31,13 +32,14 @@ import System.Random
--import Data.Maybe
import Data.Tree
import Data.Graph.Inductive.Graph (labNodes)
import qualified Data.Map as M
--import qualified Data.Map as M
import Data.Foldable
import qualified Control.Foldl as L
import Data.Maybe
generateLevelFromRoomList :: State StdGen [Room] -> World -> World
generateLevelFromRoomList gr w = updateWallZoning
generateLevelFromRoomList gr w
= updateWallZoning
. setupWorldBounds
-- . initializeStaticWalls
. setupForegroundEdgeVerxs
@@ -87,7 +89,6 @@ generateFromTree t w = updateWallZoning $ placeSpots plmnts
,_pathGraph = path
,_pathGraph' = pairGraph
,_pathPoints = foldl' (flip insertPoint) IM.empty (labNodes path)
,_pathInc = pinc
}
where
tr = evalState t $ _randGen w
@@ -95,15 +96,7 @@ generateFromTree t w = updateWallZoning $ placeSpots plmnts
path = pairsToGraph dist pairGraph
pairGraph = makePath tr
insertPoint pp@(_,V2 x y) = insertInZoneWith (floorHun x) (floorHun y) (++) [pp]
pinc = M.fromList $ pairsToIncidence pairGraph
initializeStaticWalls :: World -> World
initializeStaticWalls w = w & staticWalls %~ (\wls' -> foldl' (flip wallToWall) wls' wls)
& walls %~ IM.filter (not . wlIsWall)
where
wls = [wl | wl@Wall{} <- IM.elems $ _walls w]
wlIsWall Wall{} = True
wlIsWall _ = False
--pinc = M.fromList $ pairsToIncidence pairGraph
wallToWall :: Wall -> IM.IntMap (IM.IntMap [Wall']) -> IM.IntMap (IM.IntMap [Wall'])
wallToWall wl wls = foldl' (flip f) wls is
@@ -113,7 +106,7 @@ wallToWall wl wls = foldl' (flip f) wls is
f (x,y) = insertInZoneWith x y (++) [wl']
updateWallZoning :: World -> World
updateWallZoning w = set wallsZone (foldl' (flip wallInZone) IM.empty (_walls w)) w
updateWallZoning w = set (wallsZone . znObjects) (foldl' (flip wallInZone) IM.empty (_walls w)) w
where
wallInZone wl
| uncurry dist (_wlLine wl) <= 2*zoneSize = insertIMInZone x y wlid wl