refactored game entry control flow
This commit is contained in:
parent
f1f7077c8c
commit
8795cb46a9
|
@ -43,7 +43,7 @@ dispatch :: ProgState -> Controller
|
||||||
dispatch s = case s^.progMode of
|
dispatch s = case s^.progMode of
|
||||||
MainMenu -> mainMenuC
|
MainMenu -> mainMenuC
|
||||||
NewSeason -> newSeasonC
|
NewSeason -> newSeasonC
|
||||||
NewGame _ -> newGameC s
|
NewGame gs -> newGameC gs
|
||||||
CreatePlayer cps
|
CreatePlayer cps
|
||||||
| null $ cps^.cpsNumber -> getPlayerNumC
|
| null $ cps^.cpsNumber -> getPlayerNumC
|
||||||
| null $ cps^.cpsName -> getPlayerNameC
|
| null $ cps^.cpsName -> getPlayerNameC
|
||||||
|
|
|
@ -39,95 +39,43 @@ import Mtlstats.Types
|
||||||
import Mtlstats.Util
|
import Mtlstats.Util
|
||||||
|
|
||||||
-- | Dispatcher for a new game
|
-- | Dispatcher for a new game
|
||||||
newGameC :: ProgState -> Controller
|
newGameC :: GameState -> Controller
|
||||||
newGameC s = let
|
newGameC gs
|
||||||
gs = s^.progMode.gameStateL
|
| null $ gs^.gameYear = gameYearC
|
||||||
in if null $ gs^.gameYear then gameYearC
|
| null $ gs^.gameMonth = gameMonthC
|
||||||
else if null $ gs^.gameMonth then gameMonthC
|
| null $ gs^.gameDay = gameDayC
|
||||||
else if null $ gs^.gameDay then gameDayC
|
| null $ gs^.gameType = gameTypeC
|
||||||
else if null $ gs^.gameType then gameTypeC
|
| null $ gs^.otherTeam = otherTeamC
|
||||||
else if null $ gs^.otherTeam then otherTeamC
|
| null $ gs^.homeScore = homeScoreC
|
||||||
else if null $ gs^.homeScore then homeScoreC
|
| null $ gs^.awayScore = awayScoreC
|
||||||
else if null $ gs^.awayScore then awayScoreC
|
| null $ gs^.overtimeFlag = overtimeFlagC
|
||||||
else if null $ gs^.overtimeFlag then overtimeFlagC
|
| not $ gs^.dataVerified = verifyDataC
|
||||||
else if not $ gs^.dataVerified then verifyDataC
|
| fromJust (unaccountedPoints gs) = goalInput gs
|
||||||
else if fromJust (unaccountedPoints gs) then goalInput gs
|
| isJust $ gs^.gameSelectedPlayer = getPMinsC
|
||||||
else if isJust $ gs^.gameSelectedPlayer then getPMinsC
|
| not $ gs^.gamePMinsRecorded = pMinPlayerC
|
||||||
else if not $ gs^.gamePMinsRecorded then pMinPlayerC
|
| not $ gs^.gameGoalieAssigned = goalieInputC gs
|
||||||
else if not $ gs^.gameGoalieAssigned then goalieInputC s
|
| otherwise = reportC
|
||||||
else reportC
|
|
||||||
|
|
||||||
gameYearC :: Controller
|
gameYearC :: Controller
|
||||||
gameYearC = Controller
|
gameYearC = promptControllerWith header gameYearPrompt
|
||||||
{ drawController = \s -> do
|
|
||||||
header s
|
|
||||||
drawPrompt gameYearPrompt s
|
|
||||||
, handleController = \e -> do
|
|
||||||
promptHandler gameYearPrompt e
|
|
||||||
return True
|
|
||||||
}
|
|
||||||
|
|
||||||
gameMonthC :: Controller
|
gameMonthC :: Controller
|
||||||
gameMonthC = Controller
|
gameMonthC = menuControllerWith header gameMonthMenu
|
||||||
{ drawController = \s -> do
|
|
||||||
header s
|
|
||||||
drawMenu gameMonthMenu
|
|
||||||
, handleController = \e -> do
|
|
||||||
menuHandler gameMonthMenu e
|
|
||||||
return True
|
|
||||||
}
|
|
||||||
|
|
||||||
gameDayC :: Controller
|
gameDayC :: Controller
|
||||||
gameDayC = Controller
|
gameDayC = promptControllerWith header gameDayPrompt
|
||||||
{ drawController = \s -> do
|
|
||||||
header s
|
|
||||||
drawPrompt gameDayPrompt s
|
|
||||||
, handleController = \e -> do
|
|
||||||
promptHandler gameDayPrompt e
|
|
||||||
modify validateGameDate
|
|
||||||
return True
|
|
||||||
}
|
|
||||||
|
|
||||||
gameTypeC :: Controller
|
gameTypeC :: Controller
|
||||||
gameTypeC = Controller
|
gameTypeC = menuControllerWith header gameTypeMenu
|
||||||
{ drawController = \s -> do
|
|
||||||
header s
|
|
||||||
drawMenu gameTypeMenu
|
|
||||||
, handleController = \e -> do
|
|
||||||
menuHandler gameTypeMenu e
|
|
||||||
return True
|
|
||||||
}
|
|
||||||
|
|
||||||
otherTeamC :: Controller
|
otherTeamC :: Controller
|
||||||
otherTeamC = Controller
|
otherTeamC = promptControllerWith header otherTeamPrompt
|
||||||
{ drawController = \s -> do
|
|
||||||
header s
|
|
||||||
drawPrompt otherTeamPrompt s
|
|
||||||
, handleController = \e -> do
|
|
||||||
promptHandler otherTeamPrompt e
|
|
||||||
return True
|
|
||||||
}
|
|
||||||
|
|
||||||
homeScoreC :: Controller
|
homeScoreC :: Controller
|
||||||
homeScoreC = Controller
|
homeScoreC = promptControllerWith header homeScorePrompt
|
||||||
{ drawController = \s -> do
|
|
||||||
header s
|
|
||||||
drawPrompt homeScorePrompt s
|
|
||||||
, handleController = \e -> do
|
|
||||||
promptHandler homeScorePrompt e
|
|
||||||
return True
|
|
||||||
}
|
|
||||||
|
|
||||||
awayScoreC :: Controller
|
awayScoreC :: Controller
|
||||||
awayScoreC = Controller
|
awayScoreC = promptControllerWith header awayScorePrompt
|
||||||
{ drawController = \s -> do
|
|
||||||
header s
|
|
||||||
drawPrompt awayScorePrompt s
|
|
||||||
, handleController = \e -> do
|
|
||||||
promptHandler awayScorePrompt e
|
|
||||||
modify overtimeCheck
|
|
||||||
return True
|
|
||||||
}
|
|
||||||
|
|
||||||
overtimeFlagC :: Controller
|
overtimeFlagC :: Controller
|
||||||
overtimeFlagC = Controller
|
overtimeFlagC = Controller
|
||||||
|
@ -146,13 +94,15 @@ verifyDataC = Controller
|
||||||
let gs = s^.progMode.gameStateL
|
let gs = s^.progMode.gameStateL
|
||||||
header s
|
header s
|
||||||
C.drawString "\n"
|
C.drawString "\n"
|
||||||
C.drawString $ " Date: " ++ gameDate gs ++ "\n"
|
C.drawString $ unlines $ labelTable
|
||||||
C.drawString $ " Game type: " ++ show (fromJust $ gs^.gameType) ++ "\n"
|
[ ( "Date", gameDate gs )
|
||||||
C.drawString $ "Other team: " ++ gs^.otherTeam ++ "\n"
|
, ( "Game type", show $ fromJust $ gs^.gameType )
|
||||||
C.drawString $ "Home score: " ++ show (fromJust $ gs^.homeScore) ++ "\n"
|
, ( "Other team", gs^.otherTeam )
|
||||||
C.drawString $ "Away score: " ++ show (fromJust $ gs^.awayScore) ++ "\n"
|
, ( "Home score", show $ fromJust $ gs^.homeScore )
|
||||||
C.drawString $ " Overtime: " ++ show (fromJust $ gs^.overtimeFlag) ++ "\n\n"
|
, ( "Away score", show $ fromJust $ gs^.awayScore )
|
||||||
C.drawString "Is the above information correct? (Y/N)"
|
, ( "Overtime", show $ fromJust $ gs^.overtimeFlag )
|
||||||
|
]
|
||||||
|
C.drawString "\nIs the above information correct? (Y/N)"
|
||||||
return C.CursorInvisible
|
return C.CursorInvisible
|
||||||
, handleController = \e -> do
|
, handleController = \e -> do
|
||||||
case ynHandler e of
|
case ynHandler e of
|
||||||
|
|
|
@ -33,16 +33,12 @@ import Mtlstats.Types
|
||||||
import Mtlstats.Util
|
import Mtlstats.Util
|
||||||
|
|
||||||
-- | The dispatcher for handling goalie input
|
-- | The dispatcher for handling goalie input
|
||||||
goalieInputC :: ProgState -> Controller
|
goalieInputC :: GameState -> Controller
|
||||||
goalieInputC s = let
|
goalieInputC gs
|
||||||
gs = s^.progMode.gameStateL
|
| gs^.gameGoaliesRecorded = selectGameGoalieC
|
||||||
in if gs^.gameGoaliesRecorded
|
| null $ gs^.gameSelectedGoalie = selectGoalieC
|
||||||
then selectGameGoalieC s
|
| null $ gs^.gameGoalieMinsPlayed = minsPlayedC
|
||||||
else if null $ gs^.gameSelectedGoalie
|
| otherwise = goalsAllowedC
|
||||||
then selectGoalieC
|
|
||||||
else if null $ gs^.gameGoalieMinsPlayed
|
|
||||||
then minsPlayedC
|
|
||||||
else goalsAllowedC
|
|
||||||
|
|
||||||
selectGoalieC :: Controller
|
selectGoalieC :: Controller
|
||||||
selectGoalieC = promptController selectGameGoaliePrompt
|
selectGoalieC = promptController selectGameGoaliePrompt
|
||||||
|
@ -53,8 +49,8 @@ minsPlayedC = promptControllerWith header goalieMinsPlayedPrompt
|
||||||
goalsAllowedC :: Controller
|
goalsAllowedC :: Controller
|
||||||
goalsAllowedC = promptControllerWith header goalsAllowedPrompt
|
goalsAllowedC = promptControllerWith header goalsAllowedPrompt
|
||||||
|
|
||||||
selectGameGoalieC :: ProgState -> Controller
|
selectGameGoalieC :: Controller
|
||||||
selectGameGoalieC = menuController . gameGoalieMenu
|
selectGameGoalieC = menuStateController gameGoalieMenu
|
||||||
|
|
||||||
header :: ProgState -> C.Update ()
|
header :: ProgState -> C.Update ()
|
||||||
header s = C.drawString $ unlines
|
header s = C.drawString $ unlines
|
||||||
|
|
|
@ -23,6 +23,7 @@ module Mtlstats.Menu (
|
||||||
-- * Menu Functions
|
-- * Menu Functions
|
||||||
menuController,
|
menuController,
|
||||||
menuControllerWith,
|
menuControllerWith,
|
||||||
|
menuStateController,
|
||||||
drawMenu,
|
drawMenu,
|
||||||
menuHandler,
|
menuHandler,
|
||||||
-- * Menus
|
-- * Menus
|
||||||
|
@ -76,6 +77,21 @@ menuControllerWith header menu = Controller
|
||||||
return True
|
return True
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- | Generate and create a controller for a menu based on the current
|
||||||
|
-- 'ProgState'
|
||||||
|
menuStateController
|
||||||
|
:: (ProgState -> Menu ())
|
||||||
|
-- ^ The function to generate the menu
|
||||||
|
-> Controller
|
||||||
|
-- ^ The resulting controller
|
||||||
|
menuStateController menuFunc = Controller
|
||||||
|
{ drawController = drawMenu . menuFunc
|
||||||
|
, handleController = \e -> do
|
||||||
|
menu <- gets menuFunc
|
||||||
|
menuHandler menu e
|
||||||
|
return True
|
||||||
|
}
|
||||||
|
|
||||||
-- | The draw function for a 'Menu'
|
-- | The draw function for a 'Menu'
|
||||||
drawMenu :: Menu a -> C.Update C.CursorMode
|
drawMenu :: Menu a -> C.Update C.CursorMode
|
||||||
drawMenu m = do
|
drawMenu m = do
|
||||||
|
|
|
@ -65,8 +65,9 @@ homeScorePrompt = numPrompt "Home score: " $
|
||||||
|
|
||||||
-- | Prompts for the away score
|
-- | Prompts for the away score
|
||||||
awayScorePrompt :: Prompt
|
awayScorePrompt :: Prompt
|
||||||
awayScorePrompt = numPrompt "Away score: " $
|
awayScorePrompt = numPrompt "Away score: " $ \score -> modify
|
||||||
modify . (progMode.gameStateL.awayScore ?~)
|
$ overtimeCheck
|
||||||
|
. (progMode.gameStateL.awayScore ?~ score)
|
||||||
|
|
||||||
-- | Prompts for the player who scored the goal
|
-- | Prompts for the player who scored the goal
|
||||||
recordGoalPrompt
|
recordGoalPrompt
|
||||||
|
|
Loading…
Reference in New Issue
Block a user