Fix module combing

This commit is contained in:
2022-06-08 19:48:01 +01:00
parent 95ec30837a
commit dd4515a748
2 changed files with 27 additions and 10 deletions
+16 -9
View File
@@ -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