Files
loop/src/Dodge/Update/Input/Text.hs
T
justin 81f88c32e9 Unify key press and mouse button press timings
Both now use Ints for presses.
Still no release timer for keyboard events.
2025-07-28 23:16:05 +01:00

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