Various refactoring
This commit is contained in:
+19
-30
@@ -1,10 +1,17 @@
|
||||
module Dodge.Inventory
|
||||
( checkInvSlotsYou
|
||||
, rmSelectedInvItem
|
||||
, addItem
|
||||
, updateCloseObjects
|
||||
, closeObjScrollDir
|
||||
)
|
||||
where
|
||||
import Dodge.Data
|
||||
import Dodge.Base
|
||||
import Dodge.Base.Collide
|
||||
import Geometry
|
||||
import FoldableHelp
|
||||
import Padding
|
||||
|
||||
--import Data.Maybe
|
||||
import Data.List
|
||||
@@ -12,28 +19,31 @@ import qualified Data.IntMap.Strict as IM
|
||||
--import System.Random
|
||||
import Control.Lens
|
||||
|
||||
-- | Finds first available slot where a new item may be placed in your inventory
|
||||
checkInvSlotsYou :: Item -> World -> Maybe Int
|
||||
checkInvSlotsYou it w = fst <$> find cond invListSelFirst
|
||||
checkInvSlotsYou it w = checkInvSlotsH it invListSelFirst
|
||||
where
|
||||
cond (_,NoItem) = True
|
||||
cond (_,it' ) = itNotFull it' && _itName it == _itName it'
|
||||
youCr = you w
|
||||
youSel = _crInvSel youCr
|
||||
invList = _crInv youCr
|
||||
invListSelFirst = (youSel , invList IM.! youSel) : IM.toList invList
|
||||
|
||||
checkInvSlots :: Item -> IM.IntMap Item -> Maybe Int
|
||||
checkInvSlots it its = fmap fst $ find cond $ IM.toList its
|
||||
checkInvSlotsH :: Item -> [(Int,Item)] -> Maybe Int
|
||||
checkInvSlotsH it = fmap fst . find cond
|
||||
where
|
||||
cond (_,NoItem) = True
|
||||
cond (_,it' ) = itNotFull it' && _itName it == _itName it'
|
||||
|
||||
---- | Finds first available slot where a new item may be placed in the inventory
|
||||
--checkInvSlots :: Item -> IM.IntMap Item -> Maybe Int
|
||||
--checkInvSlots it = checkInvSlotsH it . IM.toList
|
||||
|
||||
addItem :: Item -> Item -> Item
|
||||
addItem it NoItem = it
|
||||
addItem _ it' = it' & itAmount +~ 1
|
||||
|
||||
numInventorySlots :: Int
|
||||
numInventorySlots = 9
|
||||
--numInventorySlots :: Int
|
||||
--numInventorySlots = 9
|
||||
|
||||
itNotFull :: Item -> Bool
|
||||
itNotFull it = _itMaxStack it > _itAmount it
|
||||
@@ -52,19 +62,6 @@ rmSelectedInvItem
|
||||
-> World
|
||||
-> World
|
||||
rmSelectedInvItem cid w = rmInvItem cid (_crInvSel (_creatures w IM.! cid)) w
|
||||
-- for now, left are floor items, right are buttons
|
||||
closestActiveObject :: World -> Maybe (Either FloorItem Button)
|
||||
closestActiveObject w = safeMinimumOn (dist ypos . pos) actObjs
|
||||
where
|
||||
ypos = _crPos $ you w
|
||||
actObjs = filter (\obj -> dist ypos (pos obj) < 40 && hasLOS ypos (pos obj) w)
|
||||
$ map Left (IM.elems $ _floorItems w) ++ activeButtons -- map Right (IM.elems $ _buttons w)
|
||||
pos (Right x) = _btPos x
|
||||
pos (Left x) = _flItPos x
|
||||
activeButtons = map Right
|
||||
. filter ( (/=) BtNoLabel . _btState)
|
||||
. IM.elems
|
||||
$ _buttons w
|
||||
|
||||
updateCloseObjects :: World -> World
|
||||
updateCloseObjects w = w & closeActiveObjects .~ unionBy eTest oldCloseFiltered currentClose
|
||||
@@ -87,15 +84,7 @@ updateCloseObjects w = w & closeActiveObjects .~ unionBy eTest oldCloseFiltered
|
||||
|
||||
closeObjScrollDir :: Float -> World -> World
|
||||
closeObjScrollDir x
|
||||
| x > 0 = closeObjScrollUp
|
||||
| x < 0 = closeObjScrollDown
|
||||
| x > 0 = over closeActiveObjects rotU
|
||||
| x < 0 = over closeActiveObjects rotD
|
||||
| otherwise = id
|
||||
|
||||
closeObjScrollUp :: World -> World
|
||||
closeObjScrollUp = over closeActiveObjects rotU
|
||||
where rotU [] = []
|
||||
rotU (x:xs) = xs ++ [x]
|
||||
closeObjScrollDown :: World -> World
|
||||
closeObjScrollDown = over closeActiveObjects rotD
|
||||
where rotD [] = []
|
||||
rotD xs = last xs : init xs
|
||||
|
||||
Reference in New Issue
Block a user