From 67bb12920c675761a97a527be675bbe6785607d3 Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Fri, 25 Oct 2019 00:37:14 -0400 Subject: [PATCH] added goalie creation to main menu --- src/Mtlstats/Actions.hs | 19 ++++++++++++++----- src/Mtlstats/Menu.hs | 4 +++- test/ActionsSpec.hs | 7 +++++++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/Mtlstats/Actions.hs b/src/Mtlstats/Actions.hs index 7a9b686..fcd240e 100644 --- a/src/Mtlstats/Actions.hs +++ b/src/Mtlstats/Actions.hs @@ -31,6 +31,7 @@ module Mtlstats.Actions , updateGameStats , validateGameDate , createPlayer + , createGoalie , addPlayer , recordGoalAssists , awardGoal @@ -139,13 +140,21 @@ validateGameDate s = fromMaybe s $ do -- | Starts player creation mode createPlayer :: ProgState -> ProgState createPlayer = let - cb = modify $ progMode .~ MainMenu - cps - = newCreatePlayerState - & cpsSuccessCallback .~ cb - & cpsFailureCallback .~ cb + callback = modify $ progMode .~ MainMenu + cps = newCreatePlayerState + & cpsSuccessCallback .~ callback + & cpsFailureCallback .~ callback in progMode .~ CreatePlayer cps +-- | Starts goalie creation mode +createGoalie :: ProgState -> ProgState +createGoalie = let + callback = modify $ progMode .~ MainMenu + cgs = newCreateGoalieState + & cgsSuccessCallback .~ callback + & cgsFailureCallback .~ callback + in progMode .~ CreateGoalie cgs + -- | Adds the entered player to the roster addPlayer :: ProgState -> ProgState addPlayer s = fromMaybe s $ do diff --git a/src/Mtlstats/Menu.hs b/src/Mtlstats/Menu.hs index d3a6f62..d1521f7 100644 --- a/src/Mtlstats/Menu.hs +++ b/src/Mtlstats/Menu.hs @@ -71,7 +71,9 @@ mainMenu = Menu "*** MAIN MENU ***" True modify startNewGame >> return True , MenuItem '3' "Create Player" $ modify createPlayer >> return True - , MenuItem '4' "Exit" $ do + , MenuItem '4' "Create Goalie" $ + modify createGoalie >> return True + , MenuItem '5' "Exit" $ do db <- gets $ view database liftIO $ do dir <- getAppUserDataDirectory appName diff --git a/test/ActionsSpec.hs b/test/ActionsSpec.hs index bb09dea..343e442 100644 --- a/test/ActionsSpec.hs +++ b/test/ActionsSpec.hs @@ -54,6 +54,7 @@ spec = describe "Mtlstats.Actions" $ do updateGameStatsSpec validateGameDateSpec createPlayerSpec + createGoalieSpec addPlayerSpec recordGoalAssistsSpec awardGoalSpec @@ -353,6 +354,12 @@ createPlayerSpec = describe "createPlayer" $ s = createPlayer newProgState in show (s^.progMode) `shouldBe` "CreatePlayer" +createGoalieSpec :: Spec +createGoalieSpec = describe "createGoalie" $ + it "should change the mode appropriately" $ let + s = createGoalie newProgState + in show (s^.progMode) `shouldBe` "CreateGoalie" + addPlayerSpec :: Spec addPlayerSpec = describe "addPlayer" $ do let