Allow for some and/or in regexes

This commit is contained in:
2023-02-21 12:22:50 +00:00
parent e137e95b54
commit 495c38b9c7
2 changed files with 29 additions and 1 deletions
+20 -1
View File
@@ -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