From 53557965d008d54be9e0f8fd9e03286c0773636d Mon Sep 17 00:00:00 2001 From: justin Date: Sat, 26 Oct 2024 15:03:45 +0100 Subject: [PATCH] Remove Either construct over invAdj --- ghcidOutput | 2 +- src/Dodge/Inventory/Location.hs | 4 +--- src/Dodge/Item/Grammar.hs | 13 +++++-------- src/Dodge/Render/HUD.hs | 4 +--- 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/ghcidOutput b/ghcidOutput index b9e92aec0..3daa4bdb4 100644 --- a/ghcidOutput +++ b/ghcidOutput @@ -1 +1 @@ -All good (594 modules, at 14:50:27) +All good (594 modules, at 15:02:57) diff --git a/src/Dodge/Inventory/Location.hs b/src/Dodge/Inventory/Location.hs index 82afbece1..986ea08c7 100644 --- a/src/Dodge/Inventory/Location.hs +++ b/src/Dodge/Inventory/Location.hs @@ -27,9 +27,7 @@ tryGetRootAttachedFromInvID invid im = do -- location ids tryGetRootItemInvID :: Int -> Creature -> Maybe Int tryGetRootItemInvID i cr = do - let adj = case invAdj (_crInv cr) of - Left str -> error $ "tryToGetRootItemInvID: " ++ str - Right x -> x + let adj = invAdj (_crInv cr) theroot <- adj ^? ix i theroot ^? _1 . _Just . _1 <|> Just i diff --git a/src/Dodge/Item/Grammar.hs b/src/Dodge/Item/Grammar.hs index 7ed730225..fc7ddb7cc 100644 --- a/src/Dodge/Item/Grammar.hs +++ b/src/Dodge/Item/Grammar.hs @@ -179,16 +179,13 @@ invRootMap = foldMap (dtToIntMapWithRoot (^?! itLocation . ilInvID) . fmap (^. _ -- location ids -- consider explicitly reseting the inventory ids (but this probably really -- should be done upstream anyway in the actually creature inventory) -invAdj :: IM.IntMap Item -> Either String (IM.IntMap (Maybe (Int, Int), [Int], [Int])) -invAdj im = do - l <- mapM g $ invLDT im - return $ IM.unions l +invAdj :: IM.IntMap Item -> IM.IntMap (Maybe (Int, Int), [Int], [Int]) +invAdj im = IM.unions . map g $ invLDT im where - g = dtToLRAdjEither getid . ldtToDT + g = dtToLRAdj getid . ldtToDT getid (itm, _, _) = - maybe - (Left ("invAdj item " ++ show (_itID itm) ++ " location: " ++ show (itm ^? itLocation))) - Right + fromMaybe + (error ("invAdj item " ++ show (_itID itm) ++ " location: " ++ show (itm ^? itLocation))) $ itm ^? itLocation . ilInvID -- returns an intmap with trees for all items diff --git a/src/Dodge/Render/HUD.hs b/src/Dodge/Render/HUD.hs index bd982bd33..06b2d0728 100644 --- a/src/Dodge/Render/HUD.hs +++ b/src/Dodge/Render/HUD.hs @@ -72,9 +72,7 @@ drawInventory sss w cfig = curs = invCursorParams w iextra = fromMaybe mempty $ do inv <- w ^? cWorld . lWorld . creatures . ix 0 . crInv - let x = case invAdj inv of - Left str -> error $ "drawInventory: " ++ str - Right y -> y + let x = invAdj inv return $ inventoryExtra sss cfig w x drawDIMouseOver :: World -> Picture