Cleanup menu code, fix reloading crash for nonweapons

This commit is contained in:
2022-03-20 20:09:29 +00:00
parent 988a0de578
commit 2a5b6d3597
3 changed files with 39 additions and 37 deletions
+9 -6
View File
@@ -1,8 +1,7 @@
module Dodge.Event.Menu
( handlePressedKeyInMenu
, handleTextInMenu
)
where
) where
import Dodge.Data
import Dodge.Debug.Terminal
--import Dodge.Menu
@@ -25,7 +24,7 @@ handleTextInMenu mState text = return . Just . case mState of
handlePressedKeyInMenu :: ScreenLayer -> Scancode -> Universe -> IO (Maybe Universe)
handlePressedKeyInMenu mState scode = case mState of
OptionScreen { _scOptions = mos, _scDefaultEff = defeff}
-> optionListToEffects mos defeff scode
-> optionListToEffects defeff scode mos
DisplayScreen {} -> popScreen
ColumnsScreen {} -> popScreen
WaitScreen {} -> return . Just
@@ -41,11 +40,15 @@ handlePressedKeyInMenu mState scode = case mState of
doBackspace (x:xs) = init (x:xs)
doBackspace _ = ['>']
optionListToEffects :: [MenuOption] -> (Universe -> IO (Maybe Universe)) -> Scancode
optionListToEffects
:: (Universe -> IO (Maybe Universe))
-> Scancode
-> [MenuOption]
-> Universe -> IO (Maybe Universe)
optionListToEffects mos defaulteff sc = fromMaybe defaulteff
optionListToEffects defaulteff sc
= fromMaybe defaulteff
. lookup sc
$ concatMap menuOptionToEffects mos
. concatMap menuOptionToEffects
menuOptionToEffects :: MenuOption -> [(Scancode,Universe -> IO (Maybe Universe))]
menuOptionToEffects Toggle {_moKey = k, _moEff = eff} = [(k,eff)]