Split Dodge.Base
This commit is contained in:
+8
-77
@@ -5,6 +5,7 @@ Basic helpers.
|
||||
Consider splitting. -}
|
||||
module Dodge.Base
|
||||
( module Dodge.Base
|
||||
, module Dodge.Base.Arithmetic
|
||||
, module Dodge.Base.You
|
||||
, module Dodge.Base.NewID
|
||||
, module Dodge.Base.WinScale
|
||||
@@ -15,6 +16,7 @@ module Dodge.Base
|
||||
) where
|
||||
import Dodge.Data
|
||||
import Dodge.Base.WinScale
|
||||
import Dodge.Base.Arithmetic
|
||||
import Dodge.Base.NewID
|
||||
import Dodge.Base.Coordinate
|
||||
import Dodge.Base.CardinalPoint
|
||||
@@ -37,77 +39,6 @@ import Data.Maybe
|
||||
--import qualified Data.Set as S
|
||||
|
||||
|
||||
{- | Implementation copied from
|
||||
- https://hackage.haskell.org/package/utility-ht-0.0.16/docs/src/Data.List.HT.Private.html#takeUntil
|
||||
-}
|
||||
takeUntil :: Foldable t => (a -> Bool) -> t a -> [a]
|
||||
takeUntil p = foldr (\x xs -> x : if p x then [] else xs) []
|
||||
|
||||
decreaseToZero :: Int -> Int
|
||||
decreaseToZero = max 0 . subtract 1
|
||||
|
||||
decreaseToNothing' :: (Num a, Ord a) => Maybe' a -> Maybe' a
|
||||
decreaseToNothing' ma = case ma of
|
||||
Just' x | x > 0 -> Just' (x - 1)
|
||||
_ -> Nothing'
|
||||
|
||||
safeHead :: [a] -> Maybe a
|
||||
safeHead (x:_) = Just x
|
||||
safeHead _ = Nothing
|
||||
|
||||
safeUncons :: [a] -> Maybe (a,[a])
|
||||
safeUncons (x:xs) = Just (x,xs)
|
||||
safeUncons _ = Nothing
|
||||
|
||||
errorHead :: String -> [a] -> a
|
||||
errorHead _ (x:_) = x
|
||||
errorHead s [] = error s
|
||||
|
||||
aCrPos :: Int -> World -> Point2
|
||||
aCrPos i w = _crPos $ _creatures w IM.! i
|
||||
|
||||
selectedObject :: World -> Maybe (Either FloorItem Button)
|
||||
selectedObject w = lookup (_crInvSel ycr) $ zip [n..] $ _closeObjects w
|
||||
where
|
||||
ycr = you w
|
||||
n = length $ _crInv ycr
|
||||
|
||||
crItem :: World -> Int -> Item
|
||||
crItem w cid = _crInv cr IM.! _crInvSel cr
|
||||
where
|
||||
cr = _creatures w IM.! cid
|
||||
|
||||
yourItemRef
|
||||
:: Applicative f
|
||||
=> World
|
||||
-> (Item -> f Item)
|
||||
-> World
|
||||
-> f World
|
||||
yourItemRef w = creatures . ix (_yourID w) . crInv . ix (_crInvSel (you w))
|
||||
|
||||
wallNormal :: Wall -> Point2
|
||||
wallNormal = normalizeV . vNormal . uncurry (-.-) . _wlLine
|
||||
|
||||
wallsOnLine :: Point2 -> Point2 -> IM.IntMap Wall -> IM.IntMap Wall
|
||||
wallsOnLine p1 p2 = IM.filter
|
||||
(isJust . uncurry (intersectSegSeg p1 p2) . _wlLine)
|
||||
|
||||
wallsOnLineHit :: Point2 -> Point2 -> IM.IntMap Wall -> IM.IntMap (Point2, Wall)
|
||||
wallsOnLineHit p1 p2 = IM.mapMaybe f
|
||||
where
|
||||
f wl = uncurry (intersectSegSeg p1 p2) (_wlLine wl) <&> (, wl)
|
||||
|
||||
wallsOnLine3D :: Point3 -> Point3 -> IM.IntMap Wall -> [Wall]
|
||||
wallsOnLine3D = undefined
|
||||
-- where
|
||||
-- hitPoint w = uncurry (intersectSegSeg p1 p2) (_wlLine w)
|
||||
-- hitWalls = filter (isJust . hitPoint) (IM.elems ws)
|
||||
|
||||
wallsOnCirc :: Point2 -> Float -> IM.IntMap Wall -> IM.IntMap Wall
|
||||
wallsOnCirc p r = IM.filter f
|
||||
where
|
||||
f wl = uncurry circOnSeg (_wlLine wl) p r
|
||||
|
||||
allWalls :: World -> IM.IntMap Wall
|
||||
allWalls = IM.unions . concatMap IM.elems . IM.elems . _znObjects . _wallsZone
|
||||
|
||||
@@ -200,12 +131,12 @@ adjustIMZone f x y n = IM.adjust f' x
|
||||
where
|
||||
f' = IM.adjust f'' y
|
||||
f'' = IM.adjust f n
|
||||
{- | Finds unused projectile key. -}
|
||||
newProjectileKey :: World -> Int
|
||||
newProjectileKey = IM.newKey . _props
|
||||
{- | Finds unused creature key. -}
|
||||
newCrKey :: World -> Int
|
||||
newCrKey = IM.newKey . _creatures
|
||||
--{- | Finds unused projectile key. -}
|
||||
--newProjectileKey :: World -> Int
|
||||
--newProjectileKey = IM.newKey . _props
|
||||
--{- | Finds unused creature key. -}
|
||||
--newCrKey :: World -> Int
|
||||
--newCrKey = IM.newKey . _creatures
|
||||
-- | Looks for overlap of a circle with walls.
|
||||
-- If found, gives wall
|
||||
overlapCircWallsReturnWall :: Point2 -> Float -> IM.IntMap Wall -> Maybe Wall
|
||||
|
||||
Reference in New Issue
Block a user