diff --git a/src/Dodge/Update/Input.hs b/src/Dodge/Update/Input.hs index 4d46bff1d..3c1252e6e 100644 --- a/src/Dodge/Update/Input.hs +++ b/src/Dodge/Update/Input.hs @@ -1,38 +1,37 @@ -module Dodge.Update.Input - ( updateKeyInGame - , updateKeysInTerminal - , doInputScreenInput - ) where +module Dodge.Update.Input ( + updateKeyInGame, + updateKeysInTerminal, + doInputScreenInput, +) where -import Dodge.Terminal.LeftButton -import Dodge.Save -import Dodge.Debug.Terminal -import Dodge.WorldPos -import Dodge.Button.Event -import Dodge.Inventory -import Dodge.Combine -import Dodge.Event.Test -import Dodge.Base.You -import Dodge.Reloading -import Dodge.Creature.Action -import Dodge.Menu -import Dodge.Data.Universe -import SDL -import LensHelp -import qualified Data.Text as T import qualified Data.Map.Strict as M +import qualified Data.Text as T +import Dodge.Base.You +import Dodge.Button.Event +import Dodge.Combine +import Dodge.Creature.Action +import Dodge.Data.Universe +import Dodge.Debug.Terminal +import Dodge.Event.Test +import Dodge.Inventory +import Dodge.Menu +import Dodge.Reloading +import Dodge.Save +import Dodge.Terminal.LeftButton +import Dodge.WorldPos +import LensHelp +import SDL doInputScreenInput :: T.Text -> Universe -> Universe -doInputScreenInput s u = u & uvScreenLayers . _head . scInput %~ (`T.append` T.toUpper thetext) - & checkBackspace - & checkEndStatus +doInputScreenInput s u = + u & uvScreenLayers . _head . scInput %~ (`T.append` T.toUpper thetext) + & checkBackspace + & checkEndStatus where thetext = u ^. uvWorld . input . textInput - checkBackspace = case u ^. uvWorld . input . pressedKeys . at ScancodeBackspace of - Just InitialPress -> f - Just LongPress -> f - _ -> id - f = uvScreenLayers . _head . scInput %~ doBackspace + checkBackspace + | backspaceInputted u = uvScreenLayers . _head . scInput %~ doBackspace + | otherwise = id pkeys = u ^. uvWorld . input . pressedKeys checkEndStatus | ScancodeReturn `M.member` pkeys = (uvScreenLayers %~ tail) . applyTerminalString (words $ T.unpack s) @@ -44,28 +43,31 @@ doBackspace t = case T.unsnoc t of Nothing -> t Just (t', _) -> t' +backspaceInputted :: Universe -> Bool +backspaceInputted u = case u ^. uvWorld . input . pressedKeys . at ScancodeBackspace of + Just InitialPress -> True + Just LongPress -> True + _ -> False + updateKeysInTerminal :: Int -> Universe -> Universe -updateKeysInTerminal tmid u= u & tmpoint %~ (`T.append` T.toUpper thetext) - & checkBackspace - & checkEndStatus +updateKeysInTerminal tmid u = + u & tmpoint %~ (`T.append` T.toUpper thetext) + & checkBackspace + & checkEndStatus where tmpoint = uvWorld . cWorld . lWorld . terminals . ix tmid . tmInput . tiText thetext = u ^. uvWorld . input . textInput - checkBackspace = case u ^. uvWorld . input . pressedKeys . at ScancodeBackspace of - Just InitialPress -> f - Just LongPress -> f - _ -> id - f = tmpoint %~ doBackspace + checkBackspace + | backspaceInputted u = tmpoint %~ doBackspace + | otherwise = id pkeys = u ^. uvWorld . input . pressedKeys checkEndStatus - | pkeys ^. at ScancodeReturn == Just InitialPress - = over uvWorld (\w -> terminalReturnEffect (w ^?! cWorld . lWorld . terminals . ix tmid) w) --- | pkeys ^. at ScancodeEscape == Just InitialPress --- = uvWorld . cWorld . lWorld . terminals . ix tmid . tmInput . tiFocus %~ const False + | pkeys ^. at ScancodeReturn == Just InitialPress = + over uvWorld (\w -> terminalReturnEffect (w ^?! cWorld . lWorld . terminals . ix tmid) w) | otherwise = id updateKeyInGame :: Universe -> Scancode -> PressType -> Universe -updateKeyInGame uv sc InitialPress = case sc of +updateKeyInGame uv sc InitialPress = case sc of ScancodeF5 -> doQuicksave uv ScancodeF9 -> loadSaveSlot QuicksaveSlot uv ScancodeEscape -> pauseGame uv @@ -80,7 +82,7 @@ updateKeyInGame uv sc InitialPress = case sc of _ -> uv where w = _uvWorld uv -updateKeyInGame uv _ _ = uv +updateKeyInGame uv _ _ = uv pauseGame :: Universe -> Universe pauseGame u = u & uvScreenLayers .~ [pauseMenu u]