Files
loop/src/Dodge/Item/Location.hs
T

44 lines
1.7 KiB
Haskell

module Dodge.Item.Location (
pointerToItemID,
--pointerToItemLocation,
pointerToItem,
pointerYourSelectedItem,
pointerYourRootItem,
) where
import NewInt
import Control.Lens
import Data.Maybe
import Dodge.Data.World
--pointerToItemLocation ::
-- Applicative f =>
-- ItemLocation ->
-- (Item -> f Item) ->
-- World ->
-- f World
--pointerToItemLocation InInv {_ilCrID = cid, _ilInvID = invid}
-- = cWorld . lWorld . creatures . ix cid . crInv . ix invid
--pointerToItemLocation (OnFloor) = \f w ->
---- cWorld . lWorld . floorItems . ix (_unNInt flid) . flIt
--pointerToItemLocation _ = const pure
pointerYourSelectedItem :: Applicative a => (Item -> a Item) -> World -> a World
pointerYourSelectedItem f w = fromMaybe (pure w) $ do
itinvid <- w ^? cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . imSelectedItem
itid <- w ^? cWorld . lWorld . creatures . ix 0 . crInv . ix itinvid
Just $ (cWorld . lWorld . items . ix itid) f w
-- note the ilIsRoot/Selected/Attached booleans are irrelevant
pointerYourRootItem :: Applicative a => (Item -> a Item) -> World -> a World
pointerYourRootItem f w = fromMaybe (pure w) $ do
itinvid <- w ^? cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . imRootSelectedItem
itid <- w ^? cWorld . lWorld . creatures . ix 0 . crInv . ix itinvid
Just $ (cWorld . lWorld . items . ix itid) f w
pointerToItem :: Applicative f => Item -> (Item -> f Item) -> World -> f World
pointerToItem x = cWorld . lWorld . items . ix (x ^. itID . unNInt)
pointerToItemID :: Applicative f => NewInt ItmInt -> (Item -> f Item) -> World -> f World
pointerToItemID itid = cWorld . lWorld . items . ix (itid ^. unNInt)