Cleanup menu code, fix reloading crash for nonweapons
This commit is contained in:
@@ -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)]
|
||||
|
||||
Reference in New Issue
Block a user