Refactor floor items, removing ids (not fully checked)
This commit is contained in:
+26
-27
@@ -1,6 +1,6 @@
|
||||
module Dodge.Item.Location (
|
||||
pointerToItemID,
|
||||
pointerToItemLocation,
|
||||
--pointerToItemLocation,
|
||||
pointerToItem,
|
||||
pointerYourSelectedItem,
|
||||
pointerYourRootItem,
|
||||
@@ -11,42 +11,41 @@ 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 flid) = cWorld . lWorld . floorItems . unNIntMap . ix (_unNInt flid) . flIt
|
||||
pointerToItemLocation _ = const pure
|
||||
--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
|
||||
Just $ pointerToItemLocation (InInv 0 itinvid True True True Nothing) f w
|
||||
Just $ (cWorld . lWorld . creatures . ix 0 . crInv . ix itinvid) 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
|
||||
Just $ pointerToItemLocation (InInv 0 itinvid True True True Nothing) f w
|
||||
Just $ (cWorld . lWorld . creatures . ix 0 . crInv . ix itinvid) f w
|
||||
|
||||
pointerToItem ::
|
||||
Applicative f =>
|
||||
Item ->
|
||||
(Item -> f Item) ->
|
||||
World ->
|
||||
f World
|
||||
pointerToItem = pointerToItemLocation . _itLocation
|
||||
pointerToItem :: Applicative f => Item -> (Item -> f Item) -> World -> f World
|
||||
pointerToItem x = case x ^. itLocation of
|
||||
OnFloor -> cWorld . lWorld . floorItems . ix (x ^. itID . unNInt) . flIt
|
||||
OnTurret tid -> cWorld . lWorld . machines . ix tid . mcType . mctTurret . tuWeapon
|
||||
InInv cid invid _ _ _ _ -> cWorld . lWorld . creatures . ix cid . crInv . ix invid
|
||||
InVoid -> const pure
|
||||
|
||||
pointerToItemID ::
|
||||
Applicative f =>
|
||||
NewInt ItmInt ->
|
||||
(Item -> f Item) ->
|
||||
World ->
|
||||
f World
|
||||
pointerToItemID :: Applicative f => NewInt ItmInt -> (Item -> f Item) -> World -> f World
|
||||
pointerToItemID itid f w = fromMaybe (pure w) $ do
|
||||
itloc <- w ^? cWorld . lWorld . itemLocations . ix (_unNInt itid)
|
||||
return $ pointerToItemLocation itloc f w
|
||||
return $ (\x -> x f w) $ case itloc of
|
||||
OnFloor -> cWorld . lWorld . floorItems . ix (_unNInt itid) . flIt
|
||||
OnTurret tid -> cWorld . lWorld . machines . ix tid . mcType . mctTurret . tuWeapon
|
||||
InInv cid invid _ _ _ _ -> cWorld . lWorld . creatures . ix cid . crInv . ix invid
|
||||
InVoid -> const pure
|
||||
|
||||
Reference in New Issue
Block a user