Shuffle regexes

This commit is contained in:
2023-02-20 12:16:46 +00:00
parent 5ac379959a
commit a38c77335c
9 changed files with 82 additions and 67 deletions
+55 -53
View File
@@ -48,7 +48,7 @@ updateUseInputOnScreen sl = case sl of
updateUseInputInGame :: HUDElement -> Universe -> Universe
updateUseInputInGame h u = case h of
DisplayCarte -> over uvWorld updatePressedButtonsCarte u
DisplayInventory si _ -> case si of
DisplayInventory si _ _ _ -> case si of
DisplayTerminal tmid
| lbinitialpress && inTermFocus w ->
over uvWorld (doTerminalEffectLB (w ^?! cWorld . lWorld . terminals . ix tmid)) u
@@ -121,31 +121,39 @@ doSubInvRegexInput u
&& ScancodeBackspace `M.lookup` pkeys == Just InitialPress
pkeys = u ^. uvWorld . input . pressedKeys
doRegexInput ::
Int ->
( (Maybe String -> Identity (Maybe String)) ->
Manipulation ->
Identity Manipulation
) ->
( ( Maybe String ->
Const (First String) (Maybe String)
) ->
Manipulation ->
Const (First String) Manipulation
) ->
Universe ->
Universe
--doRegexInput ::
-- Int ->
-- ( (Maybe String -> Identity (Maybe String)) ->
-- Manipulation ->
-- Identity Manipulation
-- ) ->
-- ( ( Maybe String ->
-- Const (First String) (Maybe String)
-- ) ->
-- Manipulation ->
-- Const (First String) Manipulation
-- ) ->
-- Universe ->
-- Universe
doRegexInput :: Int
-> ((Maybe String -> Identity (Maybe String))
-> HUDElement -> Identity HUDElement)
-> ((Maybe String
-> Const (Data.Monoid.First String) (Maybe String))
-> HUDElement -> Const (Data.Monoid.First String) HUDElement)
-> Universe
-> Universe
doRegexInput i crregex crregex' u
| backspacetonothing || escapekey = closeregex i 0
| endkeys || endmouse = closeregex (i + 1) (j -1)
| otherwise =
u
& doTextInputOver
(uvWorld . cWorld . lWorld . creatures . ix 0 . crManipulation . crregex . _Just)
(uvWorld . hud . hudElement . crregex . _Just)
where
closeregex a b =
u
& uvWorld . cWorld . lWorld . creatures . ix 0 . crManipulation . crregex .~ Nothing
& uvWorld . hud . hudElement . crregex .~ Nothing
& uvWorld . hud . hudElement . diSections
%~ ( ssSetCursor (ssLookupDown a b)
. overSection (ssItems . at i .~ Nothing)
@@ -161,7 +169,7 @@ doRegexInput i crregex crregex' u
[ScancodeReturn, ScancodeSlash]
endmouse = Just True == (u ^? uvWorld . input . mouseButtons . ix ButtonLeft)
backspacetonothing =
u ^? uvWorld . cWorld . lWorld . creatures . ix 0 . crManipulation . crregex' . _Just == Just ""
u ^? uvWorld . hud . hudElement . crregex' . _Just == Just ""
&& ScancodeBackspace `M.lookup` pkeys == Just InitialPress
pkeys = u ^. uvWorld . input . pressedKeys
@@ -220,57 +228,49 @@ updateLongPressInGame uv sc = case sc of
ScancodeSpace -> over uvWorld spaceAction uv
_ -> uv
-- doesn't seem to set cursor positioning
updateBackspaceRegex :: World -> World
updateBackspaceRegex w = case di ^? subInventory of
Just NoSubInventory | secfocus (-1) 0 -> w & cWorld . lWorld . creatures . ix 0 . crManipulation %~ trybackspace
Just NoSubInventory | secfocus 2 3 -> w & cWorld . lWorld . creatures . ix 0 . crManipulation %~ trybackspaceclose
-- Just CombineInventory{} ->
-- w & hud . hudElement . subInventory . subInvMap
-- %~ ( (smRegex %~ enternonzeroregex)
-- . (smSelPos ?~ 0)
-- . setShownIntMap
-- )
Just NoSubInventory | secfocus (-1) 0 -> w & trybackspace
Just NoSubInventory | secfocus 2 3 -> w & trybackspaceclose
Just CombineInventory{} -> w & hud . hudElement . subInventory %~ trybackspacecomb
_ -> w
where
secfocus a b = fromMaybe False $ do
i <- di ^? diSections . sssSelPos . _Just . _1
return $ i == a || i == b
trybackspace cm = case cm ^? invRegex . _Just of
trybackspacecomb ci = case ci ^? ciRegex . _Just of
Just (_ : _) ->
cm & invRegex . _Just %~ init
& manObject .~ InInventory SortInventory
Just [] -> cm & invRegex .~ Nothing
Nothing -> cm
trybackspaceclose cm = case cm ^? closeRegex . _Just of
ci & ciRegex . _Just %~ init
Just [] -> ci & ciRegex .~ Nothing
Nothing -> ci
trybackspace w' = case w' ^? hud . hudElement . invRegex . _Just of
Just (_ : _) ->
cm & closeRegex . _Just %~ init
& manObject .~ InNearby SortNearby
Just [] -> cm & closeRegex .~ Nothing
Nothing -> cm
w' & hud . hudElement . invRegex . _Just %~ init
& cWorld . lWorld . creatures . ix 0 . crManipulation . manObject .~ InInventory SortInventory
Just [] -> w' & hud . hudElement . invRegex .~ Nothing
Nothing -> w'
trybackspaceclose w' = case w' ^? hud . hudElement . closeRegex . _Just of
Just (_ : _) ->
w' & hud . hudElement . closeRegex . _Just %~ init
& cWorld . lWorld . creatures . ix 0 . crManipulation . manObject .~ InNearby SortNearby
Just [] -> w' & hud . hudElement . closeRegex .~ Nothing
Nothing -> w'
di = w ^. hud . hudElement
enternonzeroregex (Just (x : xs)) = Just (init (x : xs))
enternonzeroregex smr = smr
updateEnterRegex :: World -> World
updateEnterRegex w = case w ^? hud . hudElement . subInventory of
Just NoSubInventory
| secfocus (-1) 0 ->
w & cWorld . lWorld . creatures . ix 0 . crManipulation
%~ ( (invRegex %~ enterregex)
. (manObject .~ InInventory SortInventory)
)
w & cWorld . lWorld . creatures . ix 0 . crManipulation . manObject
.~ InInventory SortInventory
& hud . hudElement . invRegex %~ enterregex
Just NoSubInventory
| secfocus 2 3 ->
w & cWorld . lWorld . creatures . ix 0 . crManipulation
%~ ( (closeRegex %~ enterregex)
. (manObject .~ InNearby SortNearby)
)
Just CombineInventory{} -> w
-- w & hud . hudElement . subInventory . subInvMap
-- %~ ( setShownIntMap
-- . (smSelPos ?~ 0)
-- . (smRegex %~ enterregex)
-- )
w & cWorld . lWorld . creatures . ix 0 . crManipulation . manObject .~ InNearby SortNearby
& hud . hudElement . closeRegex %~ enterregex
Just CombineInventory{} -> w & hud . hudElement . subInventory
%~ ( ciRegex %~ enterregex )
_ -> w
where
di = w ^. hud . hudElement
@@ -306,7 +306,8 @@ spaceAction w = case w ^?! hud . hudElement of
toggleMap :: Universe -> Universe
toggleMap u = case u ^?! uvWorld . hud . hudElement of
DisplayCarte -> u & uvWorld . hud . hudElement
.~ DisplayInventory{_subInventory = NoSubInventory, _diSections = defaultInvSections}
.~ DisplayInventory{_subInventory = NoSubInventory, _diSections = defaultInvSections
, _invRegex = Nothing, _closeRegex = Nothing}
_ -> u & uvWorld . hud . hudElement .~ DisplayCarte
toggleTweakInv :: World -> World
@@ -400,6 +401,7 @@ setSelectionListRestriction cfig screen = fromMaybe screen $ do
ldps <- screen ^? scListDisplayParams
return $ screen & scAvailableLines %~ const (getAvailableListLines ldps cfig)
updatePressedButtonsCarte :: World -> World
updatePressedButtonsCarte w = updatePressedButtonsCarte' (_mouseButtons (_input w)) w
updatePressedButtonsCarte' :: M.Map MouseButton Bool -> World -> World