Reorganise update-input-gamestate structure

This commit is contained in:
2023-02-23 11:47:05 +00:00
parent fc0fd5fa37
commit d513914886
3 changed files with 397 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
module Dodge.Update.Input.Text (
doTextInputOver,
doTextInputOver',
) where
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 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