Reorganise/cleanup

This commit is contained in:
2023-02-21 01:24:22 +00:00
parent dee7472d31
commit 4904c57972
13 changed files with 119 additions and 140 deletions
+23 -43
View File
@@ -11,7 +11,7 @@ module Dodge.InputFocus (
) where
import Control.Monad
import Data.IntMap.Strict (IntMap)
--import Data.IntMap.Strict (IntMap)
import Data.Maybe
import Dodge.Data.SelectionList
import Dodge.Data.World
@@ -25,57 +25,39 @@ inTermFocus w = fromMaybe False $ do
return $ hasfocus && connectionstatus == TerminalReady
regexScope ::
(Applicative f1, Applicative f2, Num c) =>
(Applicative f) =>
World ->
Maybe
( ( IntMap (Maybe String) ->
f1 (IntMap (Maybe String))
) ->
HUDElement ->
f1 HUDElement
, (Maybe (Int, Int) -> f2 (Maybe (Int, Int))) ->
HUDElement ->
f2 HUDElement
, c
)
((SSSExtra -> f SSSExtra) -> HUDElement -> f HUDElement, Int)
regexScope w = case w ^? hud . hudElement . subInventory of
Just NoSubInventory -> case he ^? diSections . fssSections . sssSelPos . _Just of
Just NoSubInventory -> case he ^? diSections . sssExtra . sssSelPos . _Just of
Just (-1, _) -> di (-1)
Just (0, _) -> di (-1)
Just (2, _) -> di 2
Just (3, _) -> di 2
_ -> Nothing
Just CombineInventory{} ->
Just (subInventory . ciSections . fssFilters, subInventory . ciSections . fssSections . sssSelPos, (-1))
Just (subInventory . ciSections . sssExtra, (-1))
_ -> Nothing
where
di x = Just (diSections . fssFilters, diSections . fssSections . sssSelPos, x)
di x = Just (diSections . sssExtra, x)
he = w ^. hud . hudElement
regexFocus ::
(Applicative f1, Applicative f2, Num c) =>
(Applicative f) =>
World ->
Maybe
( ( IntMap (Maybe String) ->
f1 (IntMap (Maybe String))
) ->
HUDElement ->
f1 HUDElement
, (Maybe (Int, Int) -> f2 (Maybe (Int, Int))) ->
HUDElement ->
f2 HUDElement
, c
)
((SSSExtra -> f SSSExtra) -> HUDElement -> f HUDElement, Int)
regexFocus w = case w ^? hud . hudElement . subInventory of
Just NoSubInventory -> case he ^? diSections . fssSections . sssSelPos . _Just of
Just NoSubInventory -> case he ^? diSections . sssExtra . sssSelPos . _Just of
Just (-1, _) -> di (-1)
Just (2, _) -> di 2
_ -> Nothing
Just CombineInventory{} ->
Just (subInventory . ciSections . fssFilters, subInventory . ciSections . fssSections . sssSelPos, (-1))
Just (subInventory . ciSections . sssExtra, (-1))
_ -> Nothing
where
di x = Just (diSections . fssFilters, diSections . fssSections . sssSelPos, x)
di x = Just (diSections . sssExtra, x)
he = w ^. hud . hudElement
inInputFocus :: World -> Bool
@@ -89,12 +71,12 @@ inputFocus ::
World ->
Maybe ((String -> f String) -> World -> f World)
inputFocus w = case w ^? hud . hudElement . subInventory of
Just NoSubInventory -> case he ^? diSections . fssSections . sssSelPos . _Just of
Just NoSubInventory -> case he ^? diSections . sssExtra . sssSelPos . _Just of
Just (-1, _) -> di (-1)
Just (2, _) -> di 2
_ -> Nothing
Just CombineInventory{} -> case he ^? subInventory . ciSections . fssSections . sssSelPos . _Just of
Just (-1, _) -> Just $ hud . hudElement . subInventory . ciSections . fssFilters . ix (-1) . _Just
Just CombineInventory{} -> case he ^? subInventory . ciSections . sssExtra . sssSelPos . _Just of
Just (-1, _) -> Just $ hud . hudElement . subInventory . ciSections . sssExtra . sssFilters . ix (-1) . _Just
_ -> Nothing
Just DisplayTerminal{_termID = tmid} -> do
hasfocus <- w ^? cWorld . lWorld . terminals . ix tmid . tmInput . tiFocus
@@ -103,25 +85,23 @@ inputFocus w = case w ^? hud . hudElement . subInventory of
return $ cWorld . lWorld . terminals . ix tmid . tmInput . tiText
_ -> Nothing
where
di x = Just $ hud . hudElement . diSections . fssFilters . ix x . _Just
di x = Just $ hud . hudElement . diSections . sssExtra . sssFilters . ix x . _Just
he = w ^. hud . hudElement
inTopRegex :: Int -> World -> Bool
inTopRegex x w = fromMaybe False $ do
i <- w ^? hud . hudElement . diSections . sssExtra . sssSelPos . _Just . _1
return $ i == x
inInvRegex :: World -> Bool
inInvRegex w = fromMaybe False $ do
sss <- w ^? hud . hudElement . diSections . fssSections
i <- sss ^? sssSelPos . _Just . _1
return $ i == (-1)
inInvRegex = inTopRegex (-1)
inCloseRegex :: World -> Bool
inCloseRegex w = fromMaybe False $ do
sss <- w ^? hud . hudElement . diSections . fssSections
i <- sss ^? sssSelPos . _Just . _1
return $ i == 2
inCloseRegex = inTopRegex 2
inSubInvRegex :: World -> Bool
inSubInvRegex w = fromMaybe False $ do
sss <- w ^? hud . hudElement . subInventory . ciSections . fssSections
i <- sss ^? sssSelPos . _Just . _1
i <- w ^? hud . hudElement . subInventory . ciSections . sssExtra . sssSelPos . _Just . _1
return $ i == (-1)
--inputFocus :: World -> Bool