81f88c32e9
Both now use Ints for presses. Still no release timer for keyboard events.
34 lines
852 B
Haskell
34 lines
852 B
Haskell
module Dodge.Update.Input.Text (
|
|
doTextInputOverUniverse,
|
|
doTextInputOver,
|
|
) where
|
|
|
|
import Data.Either
|
|
import Data.Char
|
|
import Dodge.Data.Universe
|
|
import LensHelp
|
|
import SDL
|
|
|
|
doTextInputOverUniverse :: ASetter' Universe String -> Universe -> Universe
|
|
doTextInputOverUniverse p u = doTextInputOver (u ^. uvWorld . input) p u
|
|
|
|
doTextInputOver :: Input -> ASetter' a String -> a -> a
|
|
doTextInputOver u p x =
|
|
x & p %~ (++ map toUpper (rights str))
|
|
& checkBackspace
|
|
where
|
|
str = u ^. textInput
|
|
checkBackspace
|
|
| backspaceInputted u = p %~ doBackspace
|
|
| otherwise = id
|
|
|
|
backspaceInputted :: Input -> Bool
|
|
backspaceInputted u = case u ^. pressedKeys . at ScancodeBackspace of
|
|
Just 0 -> True
|
|
Just x | x >= 30 -> True
|
|
_ -> False
|
|
|
|
doBackspace :: String -> String
|
|
doBackspace [] = []
|
|
doBackspace s = init s
|