Refactor, try to limit dependencies

This commit is contained in:
2022-07-28 00:59:56 +01:00
parent 8aa5c17ab9
commit 160560af5f
418 changed files with 15104 additions and 13342 deletions
+18 -9
View File
@@ -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