Simplify the main loop, events only perform functional update
This commit is contained in:
+16
-4
@@ -6,6 +6,7 @@ Description : Simulation update
|
||||
-}
|
||||
module Dodge.Update (updateUniverse) where
|
||||
|
||||
import Dodge.InputFocus
|
||||
import Dodge.Event.Menu
|
||||
import Color
|
||||
import Control.Applicative
|
||||
@@ -62,10 +63,12 @@ import LensHelp
|
||||
import SDL
|
||||
import Sound.Data
|
||||
import StrictHelp
|
||||
import qualified Data.Text as T
|
||||
|
||||
updateUniverse :: Universe -> Universe
|
||||
updateUniverse u =
|
||||
updateUniverseLast
|
||||
. maybeOpenTerminal
|
||||
. over (uvWorld . input . textInput) (const mempty)
|
||||
. updateUniverseMid
|
||||
. updateUseInput
|
||||
@@ -75,16 +78,25 @@ updateUniverse u =
|
||||
where
|
||||
cfig = u ^. uvConfig
|
||||
|
||||
maybeOpenTerminal :: Universe -> Universe
|
||||
maybeOpenTerminal u = case u ^. uvWorld . input . pressedKeys . at ScancodeSemicolon of
|
||||
Just InitialPress -> gotoTerminal u
|
||||
_ -> u
|
||||
|
||||
gotoTerminal :: Universe -> Universe
|
||||
gotoTerminal w = case _uvScreenLayers w of
|
||||
(InputScreen{} : _) -> w
|
||||
_ -> w & uvScreenLayers .:~ InputScreen T.empty "Enter command"
|
||||
|
||||
updateUseInput :: Universe -> Universe
|
||||
updateUseInput u = case u ^? uvScreenLayers . _head of
|
||||
Just (InputScreen thetext _) -> doInputScreenInput thetext u
|
||||
-- Just OptionScreen{} -> --{_scOptions = mos, _scDefaultEff = defeff} -> u
|
||||
-- u
|
||||
--
|
||||
Just OptionScreen{_scOptions = mos, _scDefaultEff = defeff} ->
|
||||
foldl' (\u' scode -> optionListToEffects defeff scode mos u') u (M.keys $ M.filter (== InitialPress) pkeys)
|
||||
Just ColumnsScreen{} -> u & uvScreenLayers %~ tail
|
||||
_ -> M.foldlWithKey' updateKeyInGame u pkeys
|
||||
_ -> case u ^? uvWorld . cWorld . lWorld . hud . hudElement . subInventory of
|
||||
Just (DisplayTerminal tmid) | inTermFocus (_uvWorld u) -> updateKeysInTerminal tmid u-- M.foldlWithKey' (updateKeyInTerminal tmid) u pkeys
|
||||
_ -> M.foldlWithKey' updateKeyInGame u pkeys
|
||||
where
|
||||
pkeys = u ^. uvWorld . input . pressedKeys
|
||||
|
||||
|
||||
Reference in New Issue
Block a user