Files
loop/src/Dodge/Update/Input/Text.hs
T
2023-05-03 11:19:47 +01:00

35 lines
895 B
Haskell

module Dodge.Update.Input.Text (
doTextInputOver,
doTextInputOver',
) where
import Data.Either
--import Data.Char
import Dodge.Data.Universe
import LensHelp
import SDL
doTextInputOver :: ASetter' Universe String -> Universe -> Universe
doTextInputOver p u = doTextInputOver' u p u
doTextInputOver' :: Universe -> ASetter' a String -> a -> a
doTextInputOver' u p x =
--x & p %~ (++ map toUpper (rights str))
x & p %~ (++ rights str)
& checkBackspace
where
str = u ^. uvWorld . input . textInput
checkBackspace
| backspaceInputted u = p %~ doBackspace
| otherwise = id
backspaceInputted :: Universe -> Bool
backspaceInputted u = case u ^. uvWorld . input . pressedKeys . at ScancodeBackspace of
Just InitialPress -> True
Just LongPress -> True
_ -> False
doBackspace :: String -> String
doBackspace [] = []
doBackspace s = init s