logic branch for database saving on new season

This commit is contained in:
Jonathan Lamothe 2020-01-14 02:42:30 -05:00
parent 3b4ce50ae8
commit 2bf8d15bd4
4 changed files with 18 additions and 14 deletions

View File

@ -54,7 +54,9 @@ import Mtlstats.Util
-- | Starts a new season -- | Starts a new season
startNewSeason :: ProgState -> ProgState startNewSeason :: ProgState -> ProgState
startNewSeason = (progMode .~ NewSeason) . (database . dbGames .~ 0) startNewSeason
= (progMode .~ NewSeason False)
. (database.dbGames .~ 0)
-- | Resets all players year-to-date stats -- | Resets all players year-to-date stats
resetYtd :: ProgState -> ProgState resetYtd :: ProgState -> ProgState

View File

@ -41,10 +41,10 @@ import Mtlstats.Types
-- run -- run
dispatch :: ProgState -> Controller dispatch :: ProgState -> Controller
dispatch s = case s^.progMode of dispatch s = case s^.progMode of
MainMenu -> mainMenuC MainMenu -> mainMenuC
NewSeason -> newSeasonC NewSeason flag -> newSeasonC flag
NewGame gs -> newGameC gs NewGame gs -> newGameC gs
EditMenu -> editMenuC EditMenu -> editMenuC
CreatePlayer cps CreatePlayer cps
| null $ cps^.cpsNumber -> getPlayerNumC | null $ cps^.cpsNumber -> getPlayerNumC
| null $ cps^.cpsName -> getPlayerNameC | null $ cps^.cpsName -> getPlayerNameC
@ -63,13 +63,9 @@ mainMenuC = Controller
, handleController = menuHandler mainMenu , handleController = menuHandler mainMenu
} }
newSeasonC :: Controller newSeasonC :: Bool -> Controller
newSeasonC = Controller newSeasonC False = promptController newSeasonPrompt
{ drawController = const $ drawMenu newSeasonMenu newSeasonC True = menuController newSeasonMenu
, handleController = \e -> do
menuHandler newSeasonMenu e
return True
}
editMenuC :: Controller editMenuC :: Controller
editMenuC = menuController editMenu editMenuC = menuController editMenu

View File

@ -34,6 +34,7 @@ module Mtlstats.Prompt (
numPromptWithFallback, numPromptWithFallback,
selectPrompt, selectPrompt,
-- * Individual prompts -- * Individual prompts
newSeasonPrompt,
playerNumPrompt, playerNumPrompt,
playerNamePrompt, playerNamePrompt,
playerPosPrompt, playerPosPrompt,
@ -167,6 +168,11 @@ numPromptWithFallback pStr fallback act = Prompt
, promptSpecialKey = const $ return () , promptSpecialKey = const $ return ()
} }
-- | Prompts the user for a filename to save a backup of the database
-- to
newSeasonPrompt :: Prompt
newSeasonPrompt = undefined
-- | Builds a selection prompt -- | Builds a selection prompt
selectPrompt :: SelectParams a -> Prompt selectPrompt :: SelectParams a -> Prompt
selectPrompt params = Prompt selectPrompt params = Prompt

View File

@ -232,7 +232,7 @@ data ProgState = ProgState
-- | The program mode -- | The program mode
data ProgMode data ProgMode
= MainMenu = MainMenu
| NewSeason | NewSeason Bool
| NewGame GameState | NewGame GameState
| EditMenu | EditMenu
| CreatePlayer CreatePlayerState | CreatePlayer CreatePlayerState
@ -242,7 +242,7 @@ data ProgMode
instance Show ProgMode where instance Show ProgMode where
show MainMenu = "MainMenu" show MainMenu = "MainMenu"
show NewSeason = "NewSeason" show (NewSeason _) = "NewSeason"
show (NewGame _) = "NewGame" show (NewGame _) = "NewGame"
show EditMenu = "EditMenu" show EditMenu = "EditMenu"
show (CreatePlayer _) = "CreatePlayer" show (CreatePlayer _) = "CreatePlayer"