Simplify the main loop, events only perform functional update
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
module Dodge.Update.Input
|
||||
( updateKeyInGame
|
||||
, updateKeysInTerminal
|
||||
, doInputScreenInput
|
||||
) where
|
||||
|
||||
import Dodge.Terminal.LeftButton
|
||||
import Dodge.Save
|
||||
import Dodge.Debug.Terminal
|
||||
import Dodge.WorldPos
|
||||
import Dodge.Button.Event
|
||||
@@ -41,9 +44,30 @@ doBackspace t = case T.unsnoc t of
|
||||
Nothing -> t
|
||||
Just (t', _) -> t'
|
||||
|
||||
updateKeysInTerminal :: Int -> Universe -> Universe
|
||||
updateKeysInTerminal tmid u= u & tmpoint %~ (`T.append` T.toUpper thetext)
|
||||
& checkBackspace
|
||||
& checkEndStatus
|
||||
where
|
||||
tmpoint = uvWorld . cWorld . lWorld . terminals . ix tmid . tmInput . tiText
|
||||
thetext = u ^. uvWorld . input . textInput
|
||||
checkBackspace = case u ^. uvWorld . input . pressedKeys . at ScancodeBackspace of
|
||||
Just InitialPress -> f
|
||||
Just LongPress -> f
|
||||
_ -> id
|
||||
f = tmpoint %~ doBackspace
|
||||
pkeys = u ^. uvWorld . input . pressedKeys
|
||||
checkEndStatus
|
||||
| pkeys ^. at ScancodeReturn == Just InitialPress
|
||||
= over uvWorld (\w -> terminalReturnEffect (w ^?! cWorld . lWorld . terminals . ix tmid) w)
|
||||
-- | pkeys ^. at ScancodeEscape == Just InitialPress
|
||||
-- = uvWorld . cWorld . lWorld . terminals . ix tmid . tmInput . tiFocus %~ const False
|
||||
| otherwise = id
|
||||
|
||||
updateKeyInGame :: Universe -> Scancode -> PressType -> Universe
|
||||
updateKeyInGame uv sc InitialPress = case sc of
|
||||
ScancodeF5 -> doQuicksave uv
|
||||
ScancodeF9 -> loadSaveSlot QuicksaveSlot uv
|
||||
ScancodeEscape -> pauseGame uv
|
||||
ScancodeSpace -> over uvWorld spaceAction uv
|
||||
ScancodeP -> pauseGame uv
|
||||
|
||||
Reference in New Issue
Block a user