Improve item location code
This commit is contained in:
@@ -15,7 +15,8 @@ getItem itid w = do
|
||||
itpos <- w ^? cWorld . lWorld . itemLocations . ix itid
|
||||
case itpos of
|
||||
OnFloor flitid -> w ^? cWorld . lWorld . floorItems . ix flitid . flIt
|
||||
InInv cid invid -> w ^? cWorld . lWorld . creatures . ix cid . crInv . ix invid
|
||||
InInv {_ilCrID = cid, _ilInvID = invid}
|
||||
-> w ^? cWorld . lWorld . creatures . ix cid . crInv . ix invid
|
||||
OnTurret mcid -> w ^? cWorld . lWorld . machines . ix mcid . mcType . _McTurret . tuWeapon
|
||||
InVoid -> Nothing
|
||||
|
||||
@@ -25,19 +26,20 @@ pointerToItemLocation ::
|
||||
(Item -> f Item) ->
|
||||
World ->
|
||||
f World
|
||||
pointerToItemLocation (InInv cid invid) = cWorld . lWorld . creatures . ix cid . crInv . ix invid
|
||||
pointerToItemLocation InInv {_ilCrID = cid, _ilInvID = invid}
|
||||
= cWorld . lWorld . creatures . ix cid . crInv . ix invid
|
||||
pointerToItemLocation (OnFloor flid) = cWorld . lWorld . floorItems . ix 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 . inInventory . imSelectedItem
|
||||
Just $ pointerToItemLocation (InInv 0 itinvid) f w
|
||||
Just $ pointerToItemLocation (InInv 0 itinvid True True) 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
|
||||
Just $ pointerToItemLocation (InInv 0 itinvid True True) f w
|
||||
|
||||
pointerToItem ::
|
||||
Applicative f =>
|
||||
|
||||
Reference in New Issue
Block a user