Add basic prompt

This commit is contained in:
jgk
2021-05-23 16:24:11 +02:00
parent afafc245ef
commit b337fbdab9
12 changed files with 82 additions and 27 deletions
+15
View File
@@ -11,14 +11,21 @@ import Dodge.Config.Data
import Dodge.Config.Update
import Dodge.Layout
import Preload.Update
import Dodge.Debug.Terminal
import Data.Maybe
--import qualified Data.Set as S
import Control.Lens
import SDL
import SDL.Internal.Numbered
handlePressedKeyInMenu :: MenuLayer -> Scancode -> World -> Maybe World
handlePressedKeyInMenu mState scode w = case mState of
Terminal s -> case scode of
ScancodeEscape -> popMenu w
ScancodeReturn -> popMenu $ applyTerminalString s w
ScancodeBackspace -> popMenu w >>= pushMenu (Terminal $ dropLast s)
_ -> popMenu w >>= pushMenu (Terminal $ s ++ [scodeToChar scode])
LevelMenu _ -> case scode of
ScancodeEscape -> Nothing
ScancodeO -> pushMenu OptionMenu w
@@ -72,6 +79,12 @@ handlePressedKeyInMenu mState scode w = case mState of
aNewGame = updateFramebufferSize $ generateLevelFromRoomList levx $ initialWorld
& randGen .~ _randGen w
& config .~ _config w
dropLast (x:xs) = init (x:xs)
dropLast _ = []
-- | hacky
scodeToChar :: Scancode -> Char
scodeToChar = toEnum . (+ 61) . fromIntegral . toNumber
updateFramebufferSize :: World -> World
updateFramebufferSize w = w & sideEffects
@@ -91,3 +104,5 @@ storeLevel :: World -> World
storeLevel w = case _storedLevel w of
Nothing -> w & storedLevel ?~ w
_ -> w