Distinguish between selected item and root-selected item

This commit is contained in:
2024-09-21 21:59:53 +01:00
parent 2154abfb1d
commit 31b5db6e9e
33 changed files with 313 additions and 281 deletions
+10 -4
View File
@@ -2,7 +2,8 @@ module Dodge.Item.Location (
pointerToItemLocation,
getItem,
pointerToItem,
pointerYourItem,
pointerYourSelectedItem,
pointerYourRootItem,
) where
import Control.Lens
@@ -28,9 +29,14 @@ pointerToItemLocation (InInv cid invid) = cWorld . lWorld . creatures . ix cid .
pointerToItemLocation (OnFloor flid) = cWorld . lWorld . floorItems . ix flid . flIt
pointerToItemLocation _ = const pure
pointerYourItem :: Applicative a => (Item -> a Item) -> World -> a World
pointerYourItem f w = fromMaybe (pure w) $ do
itinvid <- w ^? cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . inInventory . ispItem
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 . inInventory . imSelectedItem
Just $ pointerToItemLocation (InInv 0 itinvid) f w
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 . inInventory . imRootItem
Just $ pointerToItemLocation (InInv 0 itinvid) f w
pointerToItem ::