This commit is contained in:
2022-04-07 09:29:11 +01:00
parent 4e80e73f13
commit 6c1bf92082
+23
View File
@@ -0,0 +1,23 @@
module Dodge.Item.Location where
import Dodge.Data
import qualified IntMapHelp as IM
import Control.Lens
import Data.Maybe
setHeldItemPos :: Creature -> World -> World
setHeldItemPos cr = fst . getHeldItemPos cr
getHeldItemPos :: Creature -> World -> (World,Int)
getHeldItemPos cr w = case maybeitid of
Nothing ->
( w & creatures . ix cid . crInv . ix j . itID ?~ newitid
& itemPositions %~ IM.insert newitid (InInv cid j)
, itid)
_ -> (w, itid)
where
cid = _crID cr
j = _crInvSel cr
newitid = IM.newKey $ _itemPositions w
maybeitid = cr ^? crInv . ix j . itID . _Just
itid = fromMaybe newitid maybeitid