From 7e409fdbd4d5b03a2d926a20cc9c5dfeef0f1cda Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Thu, 13 Feb 2020 23:18:53 -0500 Subject: [PATCH 1/9] added cpsActiveFlag and cgsActiveFlag --- src/Mtlstats/Types.hs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Mtlstats/Types.hs b/src/Mtlstats/Types.hs index b2adc9e..7b2cd69 100644 --- a/src/Mtlstats/Types.hs +++ b/src/Mtlstats/Types.hs @@ -89,12 +89,14 @@ module Mtlstats.Types ( cpsName, cpsPosition, cpsRookieFlag, + cpsActiveFlag, cpsSuccessCallback, cpsFailureCallback, -- ** CreateGoalieState Lenses cgsNumber, cgsName, cgsRookieFlag, + cgsActiveFlag, cgsSuccessCallback, cgsFailureCallback, -- ** EditPlayerState Lenses @@ -332,6 +334,8 @@ data CreatePlayerState = CreatePlayerState -- ^ The player's position , _cpsRookieFlag :: Maybe Bool -- ^ Indicates whether or not the player is a rookie + , _cpsActiveFlag :: Maybe Bool + -- ^ Indicates whether or not the plauer is active , _cpsSuccessCallback :: Action () -- ^ The function to call on success , _cpsFailureCallback :: Action () @@ -346,6 +350,8 @@ data CreateGoalieState = CreateGoalieState -- ^ The goalie's name , _cgsRookieFlag :: Maybe Bool -- ^ Indicates whether or not the goalie is a rookie + , _cgsActiveFlag :: Maybe Bool + -- ^ Indicates whether or not the goalie is active , _cgsSuccessCallback :: Action () -- ^ The function to call on success , _cgsFailureCallback :: Action () @@ -814,6 +820,7 @@ newCreatePlayerState = CreatePlayerState , _cpsName = "" , _cpsPosition = "" , _cpsRookieFlag = Nothing + , _cpsActiveFlag = Nothing , _cpsSuccessCallback = return () , _cpsFailureCallback = return () } @@ -824,6 +831,7 @@ newCreateGoalieState = CreateGoalieState { _cgsNumber = Nothing , _cgsName = "" , _cgsRookieFlag = Nothing + , _cgsActiveFlag = Nothing , _cgsSuccessCallback = return () , _cgsFailureCallback = return () } From 8d7a7997b1431676b449a69107f09fdce2fe14e5 Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Thu, 13 Feb 2020 23:23:18 -0500 Subject: [PATCH 2/9] created active flag controller branches --- src/Mtlstats/Control/CreateGoalie.hs | 4 ++++ src/Mtlstats/Control/CreatePlayer.hs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/Mtlstats/Control/CreateGoalie.hs b/src/Mtlstats/Control/CreateGoalie.hs index d902210..6e6cf45 100644 --- a/src/Mtlstats/Control/CreateGoalie.hs +++ b/src/Mtlstats/Control/CreateGoalie.hs @@ -37,6 +37,7 @@ createGoalieC cgs | null $ cgs^.cgsNumber = getGoalieNumC | null $ cgs^.cgsName = getGoalieNameC | null $ cgs^.cgsRookieFlag = getRookieFlagC + | null $ cgs^.cgsActiveFlag = getActiveFlagC | otherwise = confirmCreateGoalieC getGoalieNumC :: Controller @@ -55,6 +56,9 @@ getRookieFlagC = Controller return True } +getActiveFlagC :: Controller +getActiveFlagC = undefined + confirmCreateGoalieC :: Controller confirmCreateGoalieC = Controller { drawController = \s -> do diff --git a/src/Mtlstats/Control/CreatePlayer.hs b/src/Mtlstats/Control/CreatePlayer.hs index 2aeb4d2..a2946d6 100644 --- a/src/Mtlstats/Control/CreatePlayer.hs +++ b/src/Mtlstats/Control/CreatePlayer.hs @@ -38,6 +38,7 @@ createPlayerC cps | null $ cps^.cpsName = getPlayerNameC | null $ cps^.cpsPosition = getPlayerPosC | null $ cps^.cpsRookieFlag = getRookieFlagC + | null $ cps^.cpsActiveFlag = getActiveFlagC | otherwise = confirmCreatePlayerC getPlayerNumC :: Controller @@ -59,6 +60,9 @@ getRookieFlagC = Controller return True } +getActiveFlagC :: Controller +getActiveFlagC = undefined + confirmCreatePlayerC :: Controller confirmCreatePlayerC = Controller { drawController = \s -> do From 439aab99d3af11d94b4656f1fffae8ac9bf64a3d Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Thu, 13 Feb 2020 23:28:10 -0500 Subject: [PATCH 3/9] prompt whether or not a new player/goalie is active --- src/Mtlstats/Control/CreateGoalie.hs | 9 ++++++++- src/Mtlstats/Control/CreatePlayer.hs | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Mtlstats/Control/CreateGoalie.hs b/src/Mtlstats/Control/CreateGoalie.hs index 6e6cf45..ef32144 100644 --- a/src/Mtlstats/Control/CreateGoalie.hs +++ b/src/Mtlstats/Control/CreateGoalie.hs @@ -57,7 +57,14 @@ getRookieFlagC = Controller } getActiveFlagC :: Controller -getActiveFlagC = undefined +getActiveFlagC = Controller + { drawController = const $ do + C.drawString "Is this goalie active? (Y/N)" + return C.CursorInvisible + , handleController = \e -> do + modify $ progMode.createGoalieStateL.cgsActiveFlag .~ ynHandler e + return True + } confirmCreateGoalieC :: Controller confirmCreateGoalieC = Controller diff --git a/src/Mtlstats/Control/CreatePlayer.hs b/src/Mtlstats/Control/CreatePlayer.hs index a2946d6..f9a44d7 100644 --- a/src/Mtlstats/Control/CreatePlayer.hs +++ b/src/Mtlstats/Control/CreatePlayer.hs @@ -61,7 +61,14 @@ getRookieFlagC = Controller } getActiveFlagC :: Controller -getActiveFlagC = undefined +getActiveFlagC = Controller + { drawController = const $ do + C.drawString "Is the player active? (Y/N)" + return C.CursorInvisible + , handleController = \e -> do + modify $ progMode.createPlayerStateL.cpsActiveFlag .~ ynHandler e + return True + } confirmCreatePlayerC :: Controller confirmCreatePlayerC = Controller From 960fbb3443c19cce9bcd2acb7ff8937e82680413 Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Thu, 13 Feb 2020 23:30:31 -0500 Subject: [PATCH 4/9] display active flags in new player/goalie creation summaries --- src/Mtlstats/Control/CreateGoalie.hs | 1 + src/Mtlstats/Control/CreatePlayer.hs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Mtlstats/Control/CreateGoalie.hs b/src/Mtlstats/Control/CreateGoalie.hs index ef32144..4e445fc 100644 --- a/src/Mtlstats/Control/CreateGoalie.hs +++ b/src/Mtlstats/Control/CreateGoalie.hs @@ -75,6 +75,7 @@ confirmCreateGoalieC = Controller [ ( "Goalie number", maybe "?" show $ cgs^.cgsNumber ) , ( "Goalie name", cgs^.cgsName ) , ( "Rookie", maybe "?" show $ cgs^.cgsRookieFlag ) + , ( "Active", maybe "?" show $ cgs^.cgsActiveFlag ) ] ++ [ "" , "Create goalie: are you sure? (Y/N)" diff --git a/src/Mtlstats/Control/CreatePlayer.hs b/src/Mtlstats/Control/CreatePlayer.hs index f9a44d7..90e7f97 100644 --- a/src/Mtlstats/Control/CreatePlayer.hs +++ b/src/Mtlstats/Control/CreatePlayer.hs @@ -80,6 +80,7 @@ confirmCreatePlayerC = Controller , ( "Player name", cps^.cpsName ) , ( "Player position", cps^.cpsPosition ) , ( "Rookie", maybe "?" show $ cps^.cpsRookieFlag ) + , ( "Active", maybe "?" show $ cps^.cpsActiveFlag ) ] ++ [ "" , "Create player: are you sure? (Y/N)" From e28ef1ff0e76b7c7bcf85cea706be09a83dea441 Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Thu, 13 Feb 2020 23:40:43 -0500 Subject: [PATCH 5/9] record active flag on player creation --- src/Mtlstats/Actions.hs | 2 ++ test/ActionsSpec.hs | 40 +++++++++++++++++++++++++--------------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/Mtlstats/Actions.hs b/src/Mtlstats/Actions.hs index ea97a55..08d08ee 100644 --- a/src/Mtlstats/Actions.hs +++ b/src/Mtlstats/Actions.hs @@ -163,11 +163,13 @@ addPlayer s = fromMaybe s $ do let cps = s^.progMode.createPlayerStateL num <- cps^.cpsNumber rFlag <- cps^.cpsRookieFlag + aFlag <- cps^.cpsActiveFlag let name = cps^.cpsName pos = cps^.cpsPosition player = newPlayer num name pos & pRookie .~ rFlag + & pActive .~ aFlag Just $ s & database.dbPlayers %~ (++[player]) diff --git a/test/ActionsSpec.hs b/test/ActionsSpec.hs index f0cb89a..718fe27 100644 --- a/test/ActionsSpec.hs +++ b/test/ActionsSpec.hs @@ -321,30 +321,40 @@ addPlayerSpec = describe "addPlayer" $ mapM_ ps' = addPlayer ps in ps'^.database.dbPlayers `shouldBe` players) - -- label, expectation, progMode, players - [ ( "wrong mode", failure, MainMenu, [joe] ) - , ( "missing number", failure, noNum, [joe] ) - , ( "missing rookie flag", failure, noRookie, [joe] ) - , ( "rookie", success, mkRookie, [joe, rookie] ) - , ( "normal player", success, mkNormal, [joe, normal] ) + -- label, expectation, progMode, players + [ ( "wrong mode", failure, MainMenu, [joe] ) + , ( "missing number", failure, noNum, [joe] ) + , ( "missing rookie flag", failure, noRookie, [joe] ) + , ( "missing active flag", failure, noActive, [joe] ) + , ( "rookie", success, mkRookie, [joe, rookie] ) + , ( "retired", success, mkRetired, [joe, retired] ) + , ( "normal player", success, mkNormal, [joe, normal] ) ] where failure = "should not create the player" success = "should create the player" - noNum = mkpm Nothing (Just False) - noRookie = mkpm (Just 3) Nothing - mkRookie = mkpm (Just 3) (Just True) - mkNormal = mkpm (Just 3) (Just False) + noNum = mkpm Nothing (Just False) (Just True) + noRookie = mkpm (Just 3) Nothing (Just True) + noActive = mkpm (Just 3) (Just False) Nothing + mkRookie = mkpm (Just 3) (Just True) (Just True) + mkRetired = mkpm (Just 3) (Just False) (Just False) + mkNormal = mkpm (Just 3) (Just False) (Just True) joe = newPlayer 2 "Joe" "centre" - rookie = bob True - normal = bob False - bob rf = newPlayer 3 "Bob" "defense" & pRookie .~ rf - mkpm n rf = CreatePlayer $ newCreatePlayerState + rookie = bob True True + retired = bob False False + normal = bob False True + + bob r a = newPlayer 3 "Bob" "defense" + & pRookie .~ r + & pActive .~ a + + mkpm n r a = CreatePlayer $ newCreatePlayerState & cpsNumber .~ n & cpsName .~ "Bob" & cpsPosition .~ "defense" - & cpsRookieFlag .~ rf + & cpsRookieFlag .~ r + & cpsActiveFlag .~ a addGoalieSpec :: Spec addGoalieSpec = describe "addGoalie" $ mapM_ From 9b07c6d2497d4f8147cad3a145ab898a20e668ff Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Thu, 13 Feb 2020 23:55:00 -0500 Subject: [PATCH 6/9] record active flag on goalie creation --- src/Mtlstats/Actions.hs | 2 ++ test/ActionsSpec.hs | 54 ++++++++++++++++++++++++----------------- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/src/Mtlstats/Actions.hs b/src/Mtlstats/Actions.hs index 08d08ee..582f0e6 100644 --- a/src/Mtlstats/Actions.hs +++ b/src/Mtlstats/Actions.hs @@ -179,10 +179,12 @@ addGoalie s = fromMaybe s $ do let cgs = s^.progMode.createGoalieStateL num <- cgs^.cgsNumber rFlag <- cgs^.cgsRookieFlag + aFlag <- cgs^.cgsActiveFlag let name = cgs^.cgsName goalie = newGoalie num name & gRookie .~ rFlag + & gActive .~ aFlag Just $ s & database.dbGoalies %~ (++[goalie]) diff --git a/test/ActionsSpec.hs b/test/ActionsSpec.hs index 718fe27..1f18d5b 100644 --- a/test/ActionsSpec.hs +++ b/test/ActionsSpec.hs @@ -341,11 +341,11 @@ addPlayerSpec = describe "addPlayer" $ mapM_ mkRetired = mkpm (Just 3) (Just False) (Just False) mkNormal = mkpm (Just 3) (Just False) (Just True) joe = newPlayer 2 "Joe" "centre" - rookie = bob True True - retired = bob False False - normal = bob False True + rookie = player True True + retired = player False False + normal = player False True - bob r a = newPlayer 3 "Bob" "defense" + player r a = newPlayer 3 "Bob" "defense" & pRookie .~ r & pActive .~ a @@ -366,29 +366,39 @@ addGoalieSpec = describe "addGoalie" $ mapM_ ps' = addGoalie ps in ps'^.database.dbGoalies `shouldBe` goalies) - -- label, expectation, progMode, expected goalies - [ ( "wrong mode", failure, MainMenu, [joe] ) - , ( "no number", failure, noNum, [joe] ) - , ( "no rookie flag", failure, noRookie, [joe] ) - , ( "rookie", success, mkRookie, [joe, rookie] ) - , ( "normal goalie", success, mkNormal, [joe, normal] ) + -- label, expectation, progMode, expected goalies + [ ( "wrong mode", failure, MainMenu, [joe] ) + , ( "no number", failure, noNum, [joe] ) + , ( "no rookie flag", failure, noRookie, [joe] ) + , ( "no active flag", failure, noActive, [joe] ) + , ( "rookie", success, mkRookie, [joe, rookie] ) + , ( "retired", success, mkRetired, [joe, retired] ) + , ( "normal goalie", success, mkNormal, [joe, normal] ) ] where - failure = "should not create the goalie" - success = "should create the goalie" - noNum = cgs Nothing (Just False) - noRookie = cgs (Just 3) Nothing - mkRookie = cgs (Just 3) (Just True) - mkNormal = cgs (Just 3) (Just False) - joe = newGoalie 2 "Joe" - rookie = bob True - normal = bob False - bob r = newGoalie 3 "Bob" & gRookie .~ r - cgs n rf = CreateGoalie $ newCreateGoalieState + failure = "should not create the goalie" + success = "should create the goalie" + noNum = cgs Nothing (Just False) (Just True) + noRookie = cgs (Just 3) Nothing (Just True) + noActive = cgs (Just 3) (Just False) Nothing + mkRookie = cgs (Just 3) (Just True) (Just True) + mkRetired = cgs (Just 3) (Just False) (Just False) + mkNormal = cgs (Just 3) (Just False) (Just True) + joe = newGoalie 2 "Joe" + rookie = goalie True True + retired = goalie False False + normal = goalie False True + + goalie r a = newGoalie 3 "Bob" + & gRookie .~ r + & gActive .~ a + + cgs n r a = CreateGoalie $ newCreateGoalieState & cgsNumber .~ n & cgsName .~ "Bob" - & cgsRookieFlag .~ rf + & cgsRookieFlag .~ r + & cgsActiveFlag .~ a resetCreatePlayerStateSpec :: Spec resetCreatePlayerStateSpec = describe "resetCreatePlayerState" $ let From 747bdf8f324b8845b333162d2706ec2d094f3ea5 Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Fri, 14 Feb 2020 00:01:23 -0500 Subject: [PATCH 7/9] assume player is active on creation of rookie --- src/Mtlstats/Control/CreatePlayer.hs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Mtlstats/Control/CreatePlayer.hs b/src/Mtlstats/Control/CreatePlayer.hs index 90e7f97..940fec1 100644 --- a/src/Mtlstats/Control/CreatePlayer.hs +++ b/src/Mtlstats/Control/CreatePlayer.hs @@ -56,7 +56,11 @@ getRookieFlagC = Controller C.drawString "Is this player a rookie? (Y/N)" return C.CursorInvisible , handleController = \e -> do - modify $ progMode.createPlayerStateL.cpsRookieFlag .~ ynHandler e + modify $ case ynHandler e of + Just True -> progMode.createPlayerStateL + %~ (cpsRookieFlag ?~ True) + . (cpsActiveFlag ?~ True) + rf -> progMode.createPlayerStateL.cpsRookieFlag .~ rf return True } From dff11a831660c9de84d716acc653e92f3b5fd9c5 Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Fri, 14 Feb 2020 00:07:29 -0500 Subject: [PATCH 8/9] assume goalie is active on creation of rookie --- src/Mtlstats/Control/CreateGoalie.hs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Mtlstats/Control/CreateGoalie.hs b/src/Mtlstats/Control/CreateGoalie.hs index 4e445fc..e994ece 100644 --- a/src/Mtlstats/Control/CreateGoalie.hs +++ b/src/Mtlstats/Control/CreateGoalie.hs @@ -52,7 +52,11 @@ getRookieFlagC = Controller C.drawString "Is this goalie a rookie? (Y/N)" return C.CursorInvisible , handleController = \e -> do - modify $ progMode.createGoalieStateL.cgsRookieFlag .~ ynHandler e + modify $ case ynHandler e of + Just True -> progMode.createGoalieStateL + %~ (cgsRookieFlag ?~ True) + . (cgsActiveFlag ?~ True) + rf -> progMode.createGoalieStateL.cgsRookieFlag .~ rf return True } From d18cb7dd5910c7a0aaf1efa729e0ef2a38a45dad Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Fri, 14 Feb 2020 00:09:34 -0500 Subject: [PATCH 9/9] updated change log --- ChangeLog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog.md b/ChangeLog.md index 008ee0b..51b727e 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -3,6 +3,7 @@ ## current - Added autocomplete to player position prompt - Don't prompt for lifetime stats on rookie player/goalie creation +- Ask whether a player/goalie is active on creation ## 0.12.0 - Edit lifetime stats on new player/goalie creation