diff --git a/src/Dodge/DisplayInventory.hs b/src/Dodge/DisplayInventory.hs index 2edf612f6..5e0fb6446 100644 --- a/src/Dodge/DisplayInventory.hs +++ b/src/Dodge/DisplayInventory.hs @@ -6,6 +6,7 @@ module Dodge.DisplayInventory ( updatePositionHUD, ) where +import ListHelp import Dodge.Data.Combine import Control.Monad import qualified Data.IntMap.Strict as IM @@ -53,7 +54,8 @@ updateCombineInventory w cfig sss = str <- mstr invitms <- w ^? hud . hudElement . diSections . sssSections . ix 0 . ssItems --return $ IM.filter (regexList str . _siPictures) allcombs - return $ regexCombs invitms str allcombs + return $ IM.filter (flip (andOrRegex $ regexCombs' invitms) str) allcombs + --return $ regexCombs invitms str allcombs showncombs | null filtcombs = IM.singleton 0 $ SelectionInfo ["No possible combinations"] 1 False white 0 | otherwise = filtcombs @@ -78,6 +80,23 @@ regexCombs inv str = case str of si' <- inv ^? ix i return $ regexList str' $ _siPictures si' +regexCombs' :: IM.IntMap (SelectionItem ()) -> SelectionItem CombinableItem -> String -> Bool +regexCombs' inv ci str = case str of + '<':str' -> f str' ci + _ -> (regexList str . _siPictures) ci + where + f str' si = any (g str') (_ciInvIDs $ _siPayload si) + g str' i = fromMaybe False $ do + si' <- inv ^? ix i + return $ regexList str' $ _siPictures si' + +andOrRegex :: (a -> String -> Bool) -> a -> String -> Bool +andOrRegex f x str = all (orRegex f x) (wordsBy '&' str) + +orRegex :: (a -> String -> Bool) -> a -> String -> Bool +orRegex f x str = any (f x) (words str) + + updateDisplayInventory :: World -> Configuration -> SelectionSections () -> SelectionSections () updateDisplayInventory w cfig sss = sss & sssSections diff --git a/src/ListHelp.hs b/src/ListHelp.hs index 2ceed735f..3408b02e3 100644 --- a/src/ListHelp.hs +++ b/src/ListHelp.hs @@ -18,6 +18,8 @@ module ListHelp , takeWhileArb , takeWhileArb' , foldrWhileArb + + , wordsBy ) where import Data.List import Data.Ord @@ -108,3 +110,10 @@ foldrWhileArb _ z _ _ _ [] = z foldrWhileArb h z t f y (x:xs) = case f y x of y' | t y' -> h x $ foldrWhileArb h z t f y' xs | otherwise -> h x z + +wordsBy :: Eq a => a -> [a] -> [[a]] +wordsBy x xs = case dropWhile (==x) xs of + [] -> [] + xs' -> w : wordsBy x xs'' + where + (w,xs'') = break (==x) xs'