Refactor text input

This commit is contained in:
2022-10-30 11:57:53 +00:00
parent 9779b6fa39
commit 6123795c7a
7 changed files with 49 additions and 74 deletions
+19
View File
@@ -1,5 +1,6 @@
module Dodge.Update.Input
( updateKeyInGame
, doInputScreenInput
) where
import Dodge.WorldPos
@@ -14,6 +15,24 @@ import Dodge.Menu
import Dodge.Data.Universe
import SDL
import LensHelp
import qualified Data.Text as T
doInputScreenInput :: Universe -> Universe
doInputScreenInput u = u & uvScreenLayers . _head . scInput %~ (`T.append` thetext)
& checkBackspace
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
doBackspace :: T.Text -> T.Text
doBackspace t = case T.unsnoc t of
Nothing -> t
Just (t', _) -> t'
updateKeyInGame :: Universe -> Scancode -> PressType -> Universe
updateKeyInGame uv sc InitialPress = case sc of