Cleanup
This commit is contained in:
@@ -6,12 +6,12 @@
|
||||
-}
|
||||
module Dodge.Placement.PlaceSpot (placeSpot) where
|
||||
|
||||
import Data.Maybe
|
||||
import Color
|
||||
import Control.Monad.State
|
||||
import Data.Bifunctor
|
||||
import Data.Foldable
|
||||
import qualified Data.IntSet as IS
|
||||
import Data.Maybe
|
||||
import Dodge.Base.NewID
|
||||
import Dodge.Data.GenWorld
|
||||
import Dodge.Path
|
||||
@@ -23,6 +23,7 @@ import Geometry
|
||||
import qualified IntMapHelp as IM
|
||||
import LensHelp
|
||||
import NewInt
|
||||
|
||||
--import System.Random
|
||||
|
||||
-- when placing a placement, we update the world and the room and assign an id
|
||||
@@ -40,14 +41,17 @@ placeSpot rid w plmnt = case plmnt of
|
||||
|
||||
placePlainPSSpot :: GenWorld -> Int -> Placement -> DPoint2 -> GenWorld
|
||||
placePlainPSSpot w rid plmnt shift = case plmnt ^. plType of
|
||||
RandPS rgn ->
|
||||
RandPS rgn ->
|
||||
let (x, g) = runState rgn (w ^. gwWorld . randGen)
|
||||
in placePlainPSSpot (w & gwWorld . randGen .~ g) rid (plmnt & plType .~ x) shift
|
||||
in placePlainPSSpot (w & gwWorld . randGen .~ g) rid (plmnt & plType .~ x) shift
|
||||
_ ->
|
||||
let (i, w') = placeSpotID rid (shiftPSBy shift (_plSpot plmnt)) (_plType plmnt) w
|
||||
newplmnt = plmnt & plMID ?~ i
|
||||
gw = maybe (w' & genRooms . ix rid . rmPmnts .:~ newplmnt)
|
||||
(recrPlace newplmnt w') (_plIDCont plmnt w' newplmnt)
|
||||
gw =
|
||||
maybe
|
||||
(w' & genRooms . ix rid . rmPmnts .:~ newplmnt)
|
||||
(recrPlace newplmnt w')
|
||||
(_plIDCont plmnt w' newplmnt)
|
||||
in f newplmnt gw
|
||||
where
|
||||
f x gw = fromMaybe gw $ do
|
||||
@@ -65,7 +69,11 @@ placeSpotUsingLink ::
|
||||
Maybe Placement ->
|
||||
GenWorld
|
||||
placeSpotUsingLink w rid plmnt extract eff fallback = case searchedPoss (w ^?! genRooms . ix rid . rmPos) of
|
||||
Just (ps, rmposs) -> placeSpot rid (w & genRooms . ix rid %~ eff (head rmposs) . (rmPos .~ rmposs)) (plmnt & plSpot .~ ps)
|
||||
Just (ps, rmposs) ->
|
||||
placeSpot
|
||||
rid
|
||||
(w & genRooms . ix rid %~ eff (head rmposs) . (rmPos .~ rmposs))
|
||||
(plmnt & plSpot .~ ps)
|
||||
Nothing -> case fallback of
|
||||
Nothing -> w
|
||||
Just plmnt' -> placeSpot rid w plmnt'
|
||||
@@ -86,15 +94,18 @@ placeSpotRoomRand rid i f plmnt w =
|
||||
let (ps, g) = runState (_rmRandPSs (w ^?! genRooms . ix rid) !! i) $ w ^. gwWorld . randGen
|
||||
in placeSpot rid (w & gwWorld . randGen .~ g) (plmnt & plSpot .~ f ps)
|
||||
|
||||
|
||||
-- the Int here is some id that is assigned when the placement is placed
|
||||
placeSpotID :: Int -> PlacementSpot -> PSType -> GenWorld -> (Int, GenWorld)
|
||||
placeSpotID rid ps pt w = case pt of
|
||||
PutTrigger cnd -> plNewID (gwWorld . cWorld . lWorld . triggers) cnd w
|
||||
PutMod mdi -> plNewUpID (gwWorld . cWorld . lWorld . modifications) mdID mdi w
|
||||
PutProp prp -> plNewUpID (gwWorld . cWorld . lWorld . props) prID (mvProp p rot prp) w
|
||||
PutButton bt -> plNewUpID (gwWorld . cWorld . lWorld . buttons) btID
|
||||
(mvButton p rot bt) w
|
||||
PutButton bt ->
|
||||
plNewUpID
|
||||
(gwWorld . cWorld . lWorld . buttons)
|
||||
btID
|
||||
(mvButton p rot bt)
|
||||
w
|
||||
PutTerminal tm -> plNewUpID (gwWorld . cWorld . lWorld . terminals) tmID tm w
|
||||
PutFlIt itm ->
|
||||
let i = IM.newKey (w ^. gwWorld . cWorld . lWorld . items)
|
||||
@@ -107,8 +118,12 @@ placeSpotID rid ps pt w = case pt of
|
||||
)
|
||||
)
|
||||
PutCrit cr -> plNewUpID (gwWorld . cWorld . lWorld . creatures) crID (mvCr p rot cr) w
|
||||
PutForeground fs -> plNewUpID (gwWorld . cWorld . lWorld . foregroundShapes) fsID
|
||||
(mvFS p rot fs) w
|
||||
PutForeground fs ->
|
||||
plNewUpID
|
||||
(gwWorld . cWorld . lWorld . foregroundShapes)
|
||||
fsID
|
||||
(mvFS p rot fs)
|
||||
w
|
||||
PutMachine pps mc wl mitm -> plMachine (map doShift pps) mc wl mitm p rot w
|
||||
PutLS ls -> plNewUpID (gwWorld . cWorld . lWorld . lightSources) lsID (mvLS p' rot ls) w
|
||||
PutPPlate pp -> plNewUpID (gwWorld . cWorld . lWorld . pressPlates) ppID (mvPP p rot pp) w
|
||||
@@ -129,16 +144,16 @@ placeSpotID rid ps pt w = case pt of
|
||||
PutID i -> (i, w)
|
||||
PutWorldUpdate f -> (0, w & f rid ps)
|
||||
PutChasm ps' -> (0, w & gwWorld . cWorld . chasms .:~ map doShift ps')
|
||||
PutLabel {} -> (0, w)
|
||||
PutLabel{} -> (0, w)
|
||||
where
|
||||
p@(V2 px py) = _psPos ps
|
||||
p' = V3 px py 0
|
||||
rot = _psRot ps
|
||||
doShift = shiftPointBy (p, rot)
|
||||
|
||||
--evaluateRandPS
|
||||
--evaluateRandPS
|
||||
-- :: Int -> State StdGen PSType -> PlacementSpot -> GenWorld -> (Int, GenWorld)
|
||||
--evaluateRandPS rid rgen ps w = placeSpotID rid ps evaluatedType
|
||||
--evaluateRandPS rid rgen ps w = placeSpotID rid ps evaluatedType
|
||||
-- $ set (gwWorld . randGen) g w
|
||||
-- where
|
||||
-- (evaluatedType, g) = runState rgen (_randGen $ _gwWorld w)
|
||||
@@ -177,8 +192,15 @@ plMachine wallpoly mc wl = \case
|
||||
Nothing -> plMachine' wallpoly mc wl
|
||||
Just itm -> plTurret wallpoly mc wl itm
|
||||
|
||||
plTurret :: [Point2] -> Machine -> Wall -> Item -> Point2 -> Float -> GenWorld
|
||||
-> (Int, GenWorld)
|
||||
plTurret ::
|
||||
[Point2] ->
|
||||
Machine ->
|
||||
Wall ->
|
||||
Item ->
|
||||
Point2 ->
|
||||
Float ->
|
||||
GenWorld ->
|
||||
(Int, GenWorld)
|
||||
plTurret wallpoly mc wl itm p rot gw =
|
||||
( mcid
|
||||
, gw & gwWorld . cWorld . lWorld . machines %~ addMc
|
||||
@@ -215,8 +237,8 @@ plMachine' wallpoly mc wl p rot gw =
|
||||
addMc = IM.insert mcid (mc{_mcPos = p, _mcDir = rot, _mcID = mcid, _mcWallIDs = wlids})
|
||||
|
||||
-- TODO correctly remove/shift pathfinding lines (removePathsCrossing)
|
||||
placeMachineWalls
|
||||
:: Wall -> Color -> [Point2] -> Int -> Int -> IM.IntMap Wall -> IM.IntMap Wall
|
||||
placeMachineWalls ::
|
||||
Wall -> Color -> [Point2] -> Int -> Int -> IM.IntMap Wall -> IM.IntMap Wall
|
||||
placeMachineWalls wl col poly mcid wlid = flip (foldr f) $ zip [wlid ..] $ loopPairs poly
|
||||
where
|
||||
f (wid, l) = IM.insert wid baseWall{_wlID = wid, _wlLine = l}
|
||||
|
||||
Reference in New Issue
Block a user