Refactor, try to limit dependencies
This commit is contained in:
+28
-24
@@ -1,37 +1,40 @@
|
||||
module Dodge.Inventory.Add where
|
||||
import Dodge.Data
|
||||
import Dodge.Inventory.CheckSlots
|
||||
import Dodge.FloorItem
|
||||
import Dodge.Combine.Module
|
||||
import Dodge.Base.You
|
||||
|
||||
import Data.Maybe
|
||||
import Control.Lens
|
||||
import Data.Maybe
|
||||
import Dodge.Base.You
|
||||
import Dodge.Combine.Module
|
||||
import Dodge.Data.World
|
||||
import Dodge.FloorItem
|
||||
import Dodge.Inventory.CheckSlots
|
||||
import qualified IntMapHelp as IM
|
||||
|
||||
putItemInInvID :: Int -> Int -> World -> (Maybe Int,World)
|
||||
putItemInInvID cid flid w = fromMaybe (Nothing,w) $ do
|
||||
(i,w') <- tryPutItemInInv cid (_floorItems (_cWorld w) IM.! flid) w
|
||||
return (Just i,w')
|
||||
putItemInInvID :: Int -> Int -> World -> (Maybe Int, World)
|
||||
putItemInInvID cid flid w = fromMaybe (Nothing, w) $ do
|
||||
(i, w') <- tryPutItemInInv cid (_floorItems (_cWorld w) IM.! flid) w
|
||||
return (Just i, w')
|
||||
|
||||
putItemInInvSlot :: Int -> Item -> IM.IntMap Item -> IM.IntMap Item
|
||||
putItemInInvSlot = IM.insertWith (const $ itUse . useAmount +~ 1)
|
||||
|
||||
{- | Pick up a specific item. -}
|
||||
tryPutItemInInv :: Int -> FloorItem -> World -> Maybe (Int,World)
|
||||
-- | Pick up a specific item.
|
||||
tryPutItemInInv :: Int -> FloorItem -> World -> Maybe (Int, World)
|
||||
tryPutItemInInv cid flit w = case maybeInvSlot of
|
||||
Nothing -> Nothing
|
||||
Just i -> Just (i, w
|
||||
& updateItLocation i
|
||||
& cWorld . floorItems %~ IM.delete (_flItID flit)
|
||||
& cWorld . creatures . ix cid . crInv %~ putItemInInvSlot i it
|
||||
)
|
||||
where
|
||||
Just i ->
|
||||
Just
|
||||
( i
|
||||
, w
|
||||
& updateItLocation i
|
||||
& cWorld . floorItems %~ IM.delete (_flItID flit)
|
||||
& cWorld . creatures . ix cid . crInv %~ putItemInInvSlot i it
|
||||
)
|
||||
where
|
||||
it = _flIt flit
|
||||
maybeInvSlot = checkInvSlotsYou it w
|
||||
updateItLocation invid w' = case _itID it of
|
||||
updateItLocation invid w' = case _itID it of
|
||||
Nothing -> w'
|
||||
Just j -> w' & cWorld . itemLocations . ix j .~ InInv cid invid
|
||||
Just j -> w' & cWorld . itemLocations . ix j .~ InInv cid invid
|
||||
|
||||
--{- | Pick up a specific item. -}
|
||||
--putItemInInv :: Int -> FloorItem -> World -> World
|
||||
@@ -41,12 +44,13 @@ tryPutItemInInv cid flit w = case maybeInvSlot of
|
||||
-- & updateItLocation i
|
||||
-- & floorItems %~ IM.delete (_flItID flit)
|
||||
-- & creatures . ix cid . crInv %~ IM.insertWith (const $ itAmount +~ 1) i it
|
||||
-- where
|
||||
-- where
|
||||
-- it = _flIt flit
|
||||
-- maybeInvSlot = checkInvSlotsYou it w
|
||||
-- updateItLocation invid w' = case _itID it of
|
||||
-- updateItLocation invid w' = case _itID it of
|
||||
-- Nothing -> w'
|
||||
-- Just j -> w' & itemPositions . ix j .~ InInv cid invid
|
||||
createPutItem :: Item -> World -> (Maybe Int, World)
|
||||
createPutItem it w = uncurry (putItemInInvID (_yourID (_cWorld w)))
|
||||
$ copyItemToFloorID (_crPos $ you w) (applyModules it) w
|
||||
createPutItem it w =
|
||||
uncurry (putItemInInvID (_yourID (_cWorld w))) $
|
||||
copyItemToFloorID (_crPos $ you w) (applyModules it) w
|
||||
|
||||
@@ -3,7 +3,7 @@ module Dodge.Inventory.CheckSlots where
|
||||
import Control.Lens
|
||||
import Data.Maybe
|
||||
import Dodge.Base.You
|
||||
import Dodge.Data
|
||||
import Dodge.Data.World
|
||||
import Dodge.Inventory.ItemSpace
|
||||
import qualified IntMapHelp as IM
|
||||
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
module Dodge.Inventory.CloseObject where
|
||||
import Dodge.Data
|
||||
|
||||
import Dodge.Data.Button
|
||||
import Dodge.Data.FloorItem
|
||||
import Geometry
|
||||
|
||||
closeObjPos :: Either FloorItem Button -> Point2
|
||||
closeObjPos e = case e of
|
||||
Right x -> _btPos x
|
||||
Left x -> _flItPos x
|
||||
Left x -> _flItPos x
|
||||
|
||||
closeObjEq :: Either FloorItem Button -> Either FloorItem Button -> Bool
|
||||
closeObjEq (Right x) (Right y) = _btID x == _btID y
|
||||
closeObjEq (Left x) (Left y) = _flItID x == _flItID y
|
||||
closeObjEq (Right x) (Right y) = _btID x == _btID y
|
||||
closeObjEq (Left x) (Left y) = _flItID x == _flItID y
|
||||
closeObjEq _ _ = False
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
module Dodge.Inventory.ItemSpace
|
||||
( itSlotsTaken
|
||||
) where
|
||||
import Dodge.Data
|
||||
import Dodge.Module
|
||||
module Dodge.Inventory.ItemSpace (
|
||||
itSlotsTaken,
|
||||
) where
|
||||
|
||||
import Control.Lens
|
||||
--import Data.Maybe
|
||||
import Dodge.Data.Item
|
||||
import Dodge.Module
|
||||
|
||||
itSlotsTaken :: Item -> Int
|
||||
itSlotsTaken it = case it ^? itUse . useAmount of
|
||||
Nothing -> moduleSizes it + ceiling (_itInvSize it)
|
||||
Just i -> moduleSizes it + ceiling (_itInvSize it * fromIntegral i)
|
||||
Just i -> moduleSizes it + ceiling (_itInvSize it * fromIntegral i)
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
module Dodge.Inventory.Lock where
|
||||
import Dodge.Data
|
||||
|
||||
import Control.Lens
|
||||
import Dodge.Data.World
|
||||
|
||||
lockInv :: Int -> World -> World
|
||||
lockInv cid = cWorld . creatures . ix cid . crInvLock %~ (|| True)
|
||||
lockInv cid = cWorld . creatures . ix cid . crInvLock ||~ True
|
||||
|
||||
unlockInv :: Int -> World -> World
|
||||
unlockInv cid = cWorld . creatures . ix cid . crInvLock %~ (&& False)
|
||||
unlockInv cid = cWorld . creatures . ix cid . crInvLock &&~ False
|
||||
|
||||
Reference in New Issue
Block a user