Restructuring, #9
This commit is contained in:
parent
2055ef234e
commit
dab6fadad4
41 changed files with 941 additions and 680 deletions
49
lib/RPGEngine/Input/LevelSelection.hs
Normal file
49
lib/RPGEngine/Input/LevelSelection.hs
Normal file
|
@ -0,0 +1,49 @@
|
|||
module RPGEngine.Input.LevelSelection
|
||||
( handleInputLevelSelection
|
||||
) where
|
||||
|
||||
import RPGEngine.Input.Core
|
||||
( composeInputHandlers, handleKey, InputHandler, ListSelector (..) )
|
||||
|
||||
import RPGEngine.Config ( levelFolder )
|
||||
import RPGEngine.Data ( Game (..), Direction (..), State (..), StateBase (..) )
|
||||
|
||||
import Graphics.Gloss.Interface.IO.Game
|
||||
( Key(SpecialKey), SpecialKey(KeySpace) )
|
||||
import Graphics.Gloss.Interface.IO.Interact (SpecialKey(..))
|
||||
import RPGEngine.Render.Playing (renderPlaying)
|
||||
import RPGEngine.Input.Playing (handleInputPlaying)
|
||||
import RPGEngine.Parse (parse)
|
||||
|
||||
------------------------------ Exported ------------------------------
|
||||
|
||||
handleInputLevelSelection :: InputHandler Game
|
||||
handleInputLevelSelection = composeInputHandlers [
|
||||
handleKey (SpecialKey KeySpace) selectLevel,
|
||||
|
||||
handleKey (SpecialKey KeyUp) $ moveSelector North,
|
||||
handleKey (SpecialKey KeyDown) $ moveSelector South
|
||||
]
|
||||
|
||||
----------------------------------------------------------------------
|
||||
|
||||
-- Select a level and load it in
|
||||
selectLevel :: Game -> Game
|
||||
selectLevel game@Game{ state = LevelSelection{ levelList = list, selector = selector }} = newGame
|
||||
where newGame = parse $ levelFolder ++ (list !! index)
|
||||
index = selection selector
|
||||
selectLevel g = g
|
||||
|
||||
-- Move the selector either up or down
|
||||
moveSelector :: Direction -> Game -> Game
|
||||
moveSelector dir game@Game{ state = state@LevelSelection{ levelList = list, selector = selector } } = newGame
|
||||
where newGame = game{ state = newState }
|
||||
newState = state{ selector = newSelector }
|
||||
newSelector | constraint = selector{ selection = newSelection }
|
||||
| otherwise = selector
|
||||
constraint = 0 <= newSelection && newSelection < length list
|
||||
newSelection = selection selector + diff
|
||||
diff | dir == North = -1
|
||||
| dir == South = 1
|
||||
| otherwise = 0
|
||||
moveSelector _ g = g
|
Reference in a new issue