From dd4515a748d960f27dac540c24a168624c9fbb4e Mon Sep 17 00:00:00 2001 From: justin Date: Wed, 8 Jun 2022 19:48:01 +0100 Subject: [PATCH] Fix module combing --- src/Dodge/Combine.hs | 25 ++++++++++++++++--------- src/Dodge/Render/HUD.hs | 12 +++++++++++- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/Dodge/Combine.hs b/src/Dodge/Combine.hs index e11a55bc0..2c5913ed7 100644 --- a/src/Dodge/Combine.hs +++ b/src/Dodge/Combine.hs @@ -48,14 +48,16 @@ splitIcAmounts = concatMap f lookupItems' :: IM.IntMap Item -> [([(IcAmount,Int)],Item)] lookupItems' = flip multiLookupTrieI combinationsTrie . sortOn fst . splitIcAmounts . invertInventory -combineItemListYou :: World -> [([Int],Item)] -combineItemListYou = map (first f) . lookupItems' . yourInv +combineItemListYouX :: World -> [([Int],Item)] +combineItemListYouX = map (first f) . lookupItems' . yourInv where f = concatMap g g (amount,i) = replicate (_toInt amount) i combineItemListYou' :: World -> [([Int],(Item,[String]))] -combineItemListYou' w = map (cmm (yourInv w)) $ combineItemListYou w +combineItemListYou' w = map (cmm (yourInv w)) $ combineItemListYouX w + +combineItemListYou = map (second fst) . combineItemListYou' cmm :: IM.IntMap Item -> ([Int],Item) -> ([Int],(Item,[String])) cmm inv (is,itm) = (is,(itm & itType . iyModules .~ mods, s)) @@ -65,23 +67,28 @@ cmm inv (is,itm) = (is,(itm & itType . iyModules .~ mods, s)) combineModuleMaps :: M.Map ModuleSlot ItemModuleType -> [M.Map ModuleSlot ItemModuleType] -> ([String],M.Map ModuleSlot ItemModuleType) -combineModuleMaps = foldrM cMod +combineModuleMaps = foldM cMod cMod :: M.Map ModuleSlot ItemModuleType -> (M.Map ModuleSlot ItemModuleType) -> ([String],M.Map ModuleSlot ItemModuleType) cMod = mergeA + preserveMissing (filterAMissing f) - (filterAMissing f') (zipWithAMatched g) where f k EMPTYMODULE = ([],False) - f k md = ([],False) + f k md = ([rm "REMOVES" md],False) f' k EMPTYMODULE = ([],True) - f' k md = ([rm md++"SECOND"++show k],True) + f' k md = ([rm "KEEPS" md],True) g k EMPTYMODULE md = ([],md) - g k md1 md2 = ([rm md1++"BOTH"],md2) - rm md = "REMOVES "++fromJust (moduleName md) + g k md EMPTYMODULE = ([],md) + g k md1 md2 = ([rm "REPLACES" md1 ++ rm " WITH " md2],md2) + rm str md = str ++ " "++fullModuleName md + sm k = show k ++ ":" + + +fullModuleName = fromMaybe "EMPTYMODULE" . moduleName -- this can probably be improved by going through accessing the combinations diff --git a/src/Dodge/Render/HUD.hs b/src/Dodge/Render/HUD.hs index cb2c41cc0..3bcaec1a6 100644 --- a/src/Dodge/Render/HUD.hs +++ b/src/Dodge/Render/HUD.hs @@ -21,6 +21,7 @@ import qualified Data.Vector as V --import Data.Foldable import Data.Maybe import qualified Data.IntMap.Strict as IM +import qualified Data.Map.Strict as M import qualified Data.Set as S --import qualified Data.IntSet as IS import Control.Lens @@ -109,7 +110,11 @@ subInventoryDisplay subinv cfig w = case subinv of <> foldMap (topCursorTypeWidth listCursorNESW (topInvW +2) cfig w) lnks <> combineCounts cfig w lnks ] - InspectInventory -> invHead cfig "INSPECT" + InspectInventory -> mconcat + [ selcursor' listCursorNESW + , invHead cfig "INSPECT" + , listTextPicturesAt subInvX 60 cfig $ map text (itmInfo it) + ] where closeobjectcursor = case selectedCloseObject w of Nothing -> mempty @@ -133,6 +138,11 @@ subInventoryDisplay subinv cfig w = case subinv of then drawRBOptions cfig w (_rbOptions w) else mempty +itmInfo :: Maybe Item -> [String] +itmInfo mit = fromMaybe [] $ do + itm <- mit + return (map show . M.assocs . _iyModules $ _itType itm) + displayTerminal :: Int -> Configuration -> World -> Picture displayTerminal tid cfig w = fromMaybe mempty $ do tm <- w ^? terminals . ix tid