Use placement as continutation

This commit is contained in:
2021-11-13 09:26:20 +00:00
parent b243479759
commit 17c1a2152d
8 changed files with 35 additions and 21 deletions
+12 -5
View File
@@ -28,13 +28,20 @@ import Control.Monad.State
import Control.Lens
import qualified Data.IntSet as IS
placeSpot :: (World,Room) -> Placement -> (World,Room)
-- when placing a placement, we update the world and the room and assign an id
-- to the placement
placeSpot :: (World,Room) -> Placement -> ( (World,Room), [Placement])
placeSpot (w,rm) plmnt = case plmnt of
Placement{_plSpot = PSRoomRand i} -> placeSpotRoomRand rm i plmnt w
Placement{_plSpot = PSLnk{}} -> placeSpotUsingLink w rm plmnt
Placement{} ->
let (i,w') = placeSpotID (shiftPSBy shift (_plSpot plmnt)) (_plType plmnt) w
in maybe (w',rm) (placeSpot (w',rm)) (_plIDCont plmnt i)
newplmnt = plmnt & plMID .~ Just i
in maybe ((w',rm),[newplmnt]) (recrPlace newplmnt w') (_plIDCont plmnt newplmnt)
where
recrPlace newplmnt w' pl = let (wr,newplmnts) = placeSpot (w',rm) pl
in (wr,newplmnt:newplmnts)
-- (placeSpot (w',rm)) (_plIDCont plmnt i)
PlacementUsingPos p subpl -> placeSpot (w,rm) (subpl (shiftPoint3By shift p))
RandomPlacement rplmnt -> placeSpot (w & randGen .~ g,rm) plmnt'
where
@@ -42,11 +49,11 @@ placeSpot (w,rm) plmnt = case plmnt of
where
shift = _rmShift rm
placeSpotUsingLink :: World -> Room -> Placement -> (World, Room)
placeSpotUsingLink :: World -> Room -> Placement -> ((World, Room), [Placement])
placeSpotUsingLink w rm plmnt = case lnks of
((lnki,lnk):_) -> placeSpot (w & randGen .~ g,uselnk lnki) (updatePS (f lnk) plmnt)
[] -> case fallback of
Nothing -> (w,rm)
Nothing -> ((w,rm),[plmnt])
Just plmnt' -> placeSpot (w,rm) plmnt'
where
uselnk lnki = rm & rmLinks %~ deletei lnki
@@ -61,7 +68,7 @@ placeSpotUsingLink w rm plmnt = case lnks of
invShiftLinkBy :: (Point2,Float) -> (Point2,Float) -> (Point2,Float)
invShiftLinkBy (pos,rot) (p,r) = (invShiftPointBy (pos,rot) p, r - rot)
placeSpotRoomRand :: Room -> Int -> Placement -> World -> (World,Room)
placeSpotRoomRand :: Room -> Int -> Placement -> World -> ((World,Room),[Placement])
placeSpotRoomRand rm i plmnt w =
let (ps,g) = runState (_rmRandPSs rm !! i) $_randGen w
in placeSpot (w & randGen .~ g,rm) (plmnt & plSpot .~ uncurry PS ps)