Refactor, try to limit dependencies
This commit is contained in:
@@ -1,19 +1,20 @@
|
||||
module Dodge.Item.Location where
|
||||
import Dodge.Data
|
||||
import qualified IntMapHelp as IM
|
||||
|
||||
import Control.Lens
|
||||
import Data.Maybe
|
||||
import Dodge.Data.World
|
||||
import qualified IntMapHelp as IM
|
||||
|
||||
setHeldItemLoc :: Creature -> World -> World
|
||||
setHeldItemLoc cr = fst . getHeldItemLoc cr
|
||||
|
||||
getHeldItemLoc :: Creature -> World -> (World,Int)
|
||||
getHeldItemLoc :: Creature -> World -> (World, Int)
|
||||
getHeldItemLoc cr w = case maybeitid of
|
||||
Nothing ->
|
||||
Nothing ->
|
||||
( w & cWorld . creatures . ix cid . crInv . ix j . itID ?~ newitid
|
||||
& cWorld . itemLocations %~ IM.insert newitid (InInv cid j)
|
||||
, itid)
|
||||
, itid
|
||||
)
|
||||
_ -> (w, itid)
|
||||
where
|
||||
cid = _crID cr
|
||||
@@ -30,12 +31,20 @@ getItem itid w = do
|
||||
InInv cid invid -> w ^? cWorld . creatures . ix cid . crInv . ix invid
|
||||
VoidItm -> Nothing
|
||||
|
||||
pointerToItemLocation :: Applicative f =>
|
||||
ItemLocation -> (Item -> f Item) -> World -> f World
|
||||
pointerToItemLocation ::
|
||||
Applicative f =>
|
||||
ItemLocation ->
|
||||
(Item -> f Item) ->
|
||||
World ->
|
||||
f World
|
||||
pointerToItemLocation (InInv cid invid) = cWorld . creatures . ix cid . crInv . ix invid
|
||||
pointerToItemLocation (OnFloor flid) = cWorld . floorItems . ix flid . flIt
|
||||
pointerToItemLocation _ = const pure
|
||||
|
||||
pointerToItem :: Applicative f =>
|
||||
Item -> (Item -> f Item) -> World -> f World
|
||||
pointerToItem ::
|
||||
Applicative f =>
|
||||
Item ->
|
||||
(Item -> f Item) ->
|
||||
World ->
|
||||
f World
|
||||
pointerToItem = pointerToItemLocation . _itLocation
|
||||
|
||||
Reference in New Issue
Block a user