Refactor, try to limit dependencies

This commit is contained in:
2022-07-28 00:59:56 +01:00
parent 8aa5c17ab9
commit 160560af5f
418 changed files with 15104 additions and 13342 deletions
+40 -32
View File
@@ -1,50 +1,58 @@
module Dodge.FloorItem
( copyItemToFloor
, copyItemToFloorID
) where
import Dodge.Data
import Dodge.Base
import Geometry
import qualified IntMapHelp as IM
module Dodge.FloorItem (
copyItemToFloor,
copyItemToFloorID,
) where
import Control.Lens
import System.Random
import Data.Maybe
import Dodge.Base
import Dodge.Data.World
import Geometry
import qualified IntMapHelp as IM
import System.Random
{- | Copy an item to the floor. -}
-- | Copy an item to the floor.
copyItemToFloor :: Point2 -> Item -> World -> World
copyItemToFloor pos it = snd . copyItemToFloorID pos it
{- | Copy an item to the floor, returns the floor item's id. -}
-- | Copy an item to the floor, returns the floor item's id.
copyItemToFloorID :: Point2 -> Item -> World -> (Int, World)
copyItemToFloorID pos it w = (,) flid $ w'
& cWorld . floorItems %~ IM.insert flid theflit
& updateLocation
copyItemToFloorID pos it w =
(,) flid $
w'
& cWorld . floorItems %~ IM.insert flid theflit
& updateLocation
where
(p',w') = findWallFreeDropPoint (_dimRad $ _itDimension it) pos w
rot = fst . randomR (-pi,pi) $ _randGen w
(p', w') = findWallFreeDropPoint (_dimRad $ _itDimension it) pos w
rot = fst . randomR (- pi, pi) $ _randGen w
updateLocation = case it ^? itID of
Just (Just i') -> cWorld . itemLocations . ix i' .~ OnFloor flid
Just (Just i') -> cWorld . itemLocations . ix i' .~ OnFloor flid
_ -> id
flid = IM.newKey $ _floorItems (_cWorld w)
theflit = FlIt
{_flIt = it & itUse . useAmount %~ const 1
,_flItPos = p'
,_flItRot = rot
,_flItID = flid
}
theflit =
FlIt
{ _flIt = it & itUse . useAmount %~ const 1
, _flItPos = p'
, _flItRot = rot
, _flItID = flid
}
cardinalVectors :: [Point2]
cardinalVectors =
[ V2 1 0
, V2 0 1
, V2 (-1) 0
, V2 0 (-1)
[ V2 1 0
, V2 0 1
, V2 (-1) 0
, V2 0 (-1)
]
findWallFreeDropPoint :: Float -> Point2 -> World -> (Point2,World)
findWallFreeDropPoint r p w = (head $ mapMaybe f cardinalVectors ++ [p]
, w {_randGen = g})
findWallFreeDropPoint :: Float -> Point2 -> World -> (Point2, World)
findWallFreeDropPoint r p w =
( head $ mapMaybe f cardinalVectors ++ [p]
, w{_randGen = g}
)
where
f q = testOnWall r $ p +.+ rotateV rot (10 *.* q)
testOnWall r' q | circOnSomeWall q r' w = Nothing
testOnWall r' q
| circOnSomeWall q r' w = Nothing
| otherwise = Just q
(rot, g) = randomR (0,2*pi) $ _randGen w
(rot, g) = randomR (0, 2 * pi) $ _randGen w