Allow for some and/or in regexes
This commit is contained in:
@@ -6,6 +6,7 @@ module Dodge.DisplayInventory (
|
|||||||
updatePositionHUD,
|
updatePositionHUD,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
import ListHelp
|
||||||
import Dodge.Data.Combine
|
import Dodge.Data.Combine
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
import qualified Data.IntMap.Strict as IM
|
import qualified Data.IntMap.Strict as IM
|
||||||
@@ -53,7 +54,8 @@ updateCombineInventory w cfig sss =
|
|||||||
str <- mstr
|
str <- mstr
|
||||||
invitms <- w ^? hud . hudElement . diSections . sssSections . ix 0 . ssItems
|
invitms <- w ^? hud . hudElement . diSections . sssSections . ix 0 . ssItems
|
||||||
--return $ IM.filter (regexList str . _siPictures) allcombs
|
--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
|
showncombs
|
||||||
| null filtcombs = IM.singleton 0 $ SelectionInfo ["No possible combinations"] 1 False white 0
|
| null filtcombs = IM.singleton 0 $ SelectionInfo ["No possible combinations"] 1 False white 0
|
||||||
| otherwise = filtcombs
|
| otherwise = filtcombs
|
||||||
@@ -78,6 +80,23 @@ regexCombs inv str = case str of
|
|||||||
si' <- inv ^? ix i
|
si' <- inv ^? ix i
|
||||||
return $ regexList str' $ _siPictures si'
|
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 :: World -> Configuration -> SelectionSections () -> SelectionSections ()
|
||||||
updateDisplayInventory w cfig sss =
|
updateDisplayInventory w cfig sss =
|
||||||
sss & sssSections
|
sss & sssSections
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ module ListHelp
|
|||||||
, takeWhileArb
|
, takeWhileArb
|
||||||
, takeWhileArb'
|
, takeWhileArb'
|
||||||
, foldrWhileArb
|
, foldrWhileArb
|
||||||
|
|
||||||
|
, wordsBy
|
||||||
) where
|
) where
|
||||||
import Data.List
|
import Data.List
|
||||||
import Data.Ord
|
import Data.Ord
|
||||||
@@ -108,3 +110,10 @@ foldrWhileArb _ z _ _ _ [] = z
|
|||||||
foldrWhileArb h z t f y (x:xs) = case f y x of
|
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
|
y' | t y' -> h x $ foldrWhileArb h z t f y' xs
|
||||||
| otherwise -> h x z
|
| 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'
|
||||||
|
|||||||
Reference in New Issue
Block a user