Remove Either construct over invAdj

This commit is contained in:
2024-10-26 15:03:45 +01:00
parent 6402ab11da
commit 53557965d0
4 changed files with 8 additions and 15 deletions
+1 -1
View File
@@ -1 +1 @@
All good (594 modules, at 14:50:27) All good (594 modules, at 15:02:57)
+1 -3
View File
@@ -27,9 +27,7 @@ tryGetRootAttachedFromInvID invid im = do
-- location ids -- location ids
tryGetRootItemInvID :: Int -> Creature -> Maybe Int tryGetRootItemInvID :: Int -> Creature -> Maybe Int
tryGetRootItemInvID i cr = do tryGetRootItemInvID i cr = do
let adj = case invAdj (_crInv cr) of let adj = invAdj (_crInv cr)
Left str -> error $ "tryToGetRootItemInvID: " ++ str
Right x -> x
theroot <- adj ^? ix i theroot <- adj ^? ix i
theroot ^? _1 . _Just . _1 <|> Just i theroot ^? _1 . _Just . _1 <|> Just i
+5 -8
View File
@@ -179,16 +179,13 @@ invRootMap = foldMap (dtToIntMapWithRoot (^?! itLocation . ilInvID) . fmap (^. _
-- location ids -- location ids
-- consider explicitly reseting the inventory ids (but this probably really -- consider explicitly reseting the inventory ids (but this probably really
-- should be done upstream anyway in the actually creature inventory) -- 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.IntMap Item -> IM.IntMap (Maybe (Int, Int), [Int], [Int])
invAdj im = do invAdj im = IM.unions . map g $ invLDT im
l <- mapM g $ invLDT im
return $ IM.unions l
where where
g = dtToLRAdjEither getid . ldtToDT g = dtToLRAdj getid . ldtToDT
getid (itm, _, _) = getid (itm, _, _) =
maybe fromMaybe
(Left ("invAdj item " ++ show (_itID itm) ++ " location: " ++ show (itm ^? itLocation))) (error ("invAdj item " ++ show (_itID itm) ++ " location: " ++ show (itm ^? itLocation)))
Right
$ itm ^? itLocation . ilInvID $ itm ^? itLocation . ilInvID
-- returns an intmap with trees for all items -- returns an intmap with trees for all items
+1 -3
View File
@@ -72,9 +72,7 @@ drawInventory sss w cfig =
curs = invCursorParams w curs = invCursorParams w
iextra = fromMaybe mempty $ do iextra = fromMaybe mempty $ do
inv <- w ^? cWorld . lWorld . creatures . ix 0 . crInv inv <- w ^? cWorld . lWorld . creatures . ix 0 . crInv
let x = case invAdj inv of let x = invAdj inv
Left str -> error $ "drawInventory: " ++ str
Right y -> y
return $ inventoryExtra sss cfig w x return $ inventoryExtra sss cfig w x
drawDIMouseOver :: World -> Picture drawDIMouseOver :: World -> Picture