Merge pull request #75 from mtlstats/active-check

ask whether player/goalie is active on creation
This commit is contained in:
Jonathan Lamothe 2020-02-14 00:15:17 -05:00 committed by GitHub
commit 2607fc5ce8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 100 additions and 35 deletions

View File

@ -3,6 +3,7 @@
## current ## current
- Added autocomplete to player position prompt - Added autocomplete to player position prompt
- Don't prompt for lifetime stats on rookie player/goalie creation - Don't prompt for lifetime stats on rookie player/goalie creation
- Ask whether a player/goalie is active on creation
## 0.12.0 ## 0.12.0
- Edit lifetime stats on new player/goalie creation - Edit lifetime stats on new player/goalie creation

View File

@ -163,11 +163,13 @@ addPlayer s = fromMaybe s $ do
let cps = s^.progMode.createPlayerStateL let cps = s^.progMode.createPlayerStateL
num <- cps^.cpsNumber num <- cps^.cpsNumber
rFlag <- cps^.cpsRookieFlag rFlag <- cps^.cpsRookieFlag
aFlag <- cps^.cpsActiveFlag
let let
name = cps^.cpsName name = cps^.cpsName
pos = cps^.cpsPosition pos = cps^.cpsPosition
player = newPlayer num name pos player = newPlayer num name pos
& pRookie .~ rFlag & pRookie .~ rFlag
& pActive .~ aFlag
Just $ s & database.dbPlayers Just $ s & database.dbPlayers
%~ (++[player]) %~ (++[player])
@ -177,10 +179,12 @@ addGoalie s = fromMaybe s $ do
let cgs = s^.progMode.createGoalieStateL let cgs = s^.progMode.createGoalieStateL
num <- cgs^.cgsNumber num <- cgs^.cgsNumber
rFlag <- cgs^.cgsRookieFlag rFlag <- cgs^.cgsRookieFlag
aFlag <- cgs^.cgsActiveFlag
let let
name = cgs^.cgsName name = cgs^.cgsName
goalie = newGoalie num name goalie = newGoalie num name
& gRookie .~ rFlag & gRookie .~ rFlag
& gActive .~ aFlag
Just $ s & database.dbGoalies Just $ s & database.dbGoalies
%~ (++[goalie]) %~ (++[goalie])

View File

@ -37,6 +37,7 @@ createGoalieC cgs
| null $ cgs^.cgsNumber = getGoalieNumC | null $ cgs^.cgsNumber = getGoalieNumC
| null $ cgs^.cgsName = getGoalieNameC | null $ cgs^.cgsName = getGoalieNameC
| null $ cgs^.cgsRookieFlag = getRookieFlagC | null $ cgs^.cgsRookieFlag = getRookieFlagC
| null $ cgs^.cgsActiveFlag = getActiveFlagC
| otherwise = confirmCreateGoalieC | otherwise = confirmCreateGoalieC
getGoalieNumC :: Controller getGoalieNumC :: Controller
@ -51,7 +52,21 @@ getRookieFlagC = Controller
C.drawString "Is this goalie a rookie? (Y/N)" C.drawString "Is this goalie a rookie? (Y/N)"
return C.CursorInvisible return C.CursorInvisible
, handleController = \e -> do , 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
}
getActiveFlagC :: Controller
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 return True
} }
@ -64,6 +79,7 @@ confirmCreateGoalieC = Controller
[ ( "Goalie number", maybe "?" show $ cgs^.cgsNumber ) [ ( "Goalie number", maybe "?" show $ cgs^.cgsNumber )
, ( "Goalie name", cgs^.cgsName ) , ( "Goalie name", cgs^.cgsName )
, ( "Rookie", maybe "?" show $ cgs^.cgsRookieFlag ) , ( "Rookie", maybe "?" show $ cgs^.cgsRookieFlag )
, ( "Active", maybe "?" show $ cgs^.cgsActiveFlag )
] ]
++ [ "" ++ [ ""
, "Create goalie: are you sure? (Y/N)" , "Create goalie: are you sure? (Y/N)"

View File

@ -38,6 +38,7 @@ createPlayerC cps
| null $ cps^.cpsName = getPlayerNameC | null $ cps^.cpsName = getPlayerNameC
| null $ cps^.cpsPosition = getPlayerPosC | null $ cps^.cpsPosition = getPlayerPosC
| null $ cps^.cpsRookieFlag = getRookieFlagC | null $ cps^.cpsRookieFlag = getRookieFlagC
| null $ cps^.cpsActiveFlag = getActiveFlagC
| otherwise = confirmCreatePlayerC | otherwise = confirmCreatePlayerC
getPlayerNumC :: Controller getPlayerNumC :: Controller
@ -55,7 +56,21 @@ getRookieFlagC = Controller
C.drawString "Is this player a rookie? (Y/N)" C.drawString "Is this player a rookie? (Y/N)"
return C.CursorInvisible return C.CursorInvisible
, handleController = \e -> do , 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
}
getActiveFlagC :: Controller
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 return True
} }
@ -69,6 +84,7 @@ confirmCreatePlayerC = Controller
, ( "Player name", cps^.cpsName ) , ( "Player name", cps^.cpsName )
, ( "Player position", cps^.cpsPosition ) , ( "Player position", cps^.cpsPosition )
, ( "Rookie", maybe "?" show $ cps^.cpsRookieFlag ) , ( "Rookie", maybe "?" show $ cps^.cpsRookieFlag )
, ( "Active", maybe "?" show $ cps^.cpsActiveFlag )
] ]
++ [ "" ++ [ ""
, "Create player: are you sure? (Y/N)" , "Create player: are you sure? (Y/N)"

View File

@ -89,12 +89,14 @@ module Mtlstats.Types (
cpsName, cpsName,
cpsPosition, cpsPosition,
cpsRookieFlag, cpsRookieFlag,
cpsActiveFlag,
cpsSuccessCallback, cpsSuccessCallback,
cpsFailureCallback, cpsFailureCallback,
-- ** CreateGoalieState Lenses -- ** CreateGoalieState Lenses
cgsNumber, cgsNumber,
cgsName, cgsName,
cgsRookieFlag, cgsRookieFlag,
cgsActiveFlag,
cgsSuccessCallback, cgsSuccessCallback,
cgsFailureCallback, cgsFailureCallback,
-- ** EditPlayerState Lenses -- ** EditPlayerState Lenses
@ -332,6 +334,8 @@ data CreatePlayerState = CreatePlayerState
-- ^ The player's position -- ^ The player's position
, _cpsRookieFlag :: Maybe Bool , _cpsRookieFlag :: Maybe Bool
-- ^ Indicates whether or not the player is a rookie -- ^ Indicates whether or not the player is a rookie
, _cpsActiveFlag :: Maybe Bool
-- ^ Indicates whether or not the plauer is active
, _cpsSuccessCallback :: Action () , _cpsSuccessCallback :: Action ()
-- ^ The function to call on success -- ^ The function to call on success
, _cpsFailureCallback :: Action () , _cpsFailureCallback :: Action ()
@ -346,6 +350,8 @@ data CreateGoalieState = CreateGoalieState
-- ^ The goalie's name -- ^ The goalie's name
, _cgsRookieFlag :: Maybe Bool , _cgsRookieFlag :: Maybe Bool
-- ^ Indicates whether or not the goalie is a rookie -- ^ Indicates whether or not the goalie is a rookie
, _cgsActiveFlag :: Maybe Bool
-- ^ Indicates whether or not the goalie is active
, _cgsSuccessCallback :: Action () , _cgsSuccessCallback :: Action ()
-- ^ The function to call on success -- ^ The function to call on success
, _cgsFailureCallback :: Action () , _cgsFailureCallback :: Action ()
@ -814,6 +820,7 @@ newCreatePlayerState = CreatePlayerState
, _cpsName = "" , _cpsName = ""
, _cpsPosition = "" , _cpsPosition = ""
, _cpsRookieFlag = Nothing , _cpsRookieFlag = Nothing
, _cpsActiveFlag = Nothing
, _cpsSuccessCallback = return () , _cpsSuccessCallback = return ()
, _cpsFailureCallback = return () , _cpsFailureCallback = return ()
} }
@ -824,6 +831,7 @@ newCreateGoalieState = CreateGoalieState
{ _cgsNumber = Nothing { _cgsNumber = Nothing
, _cgsName = "" , _cgsName = ""
, _cgsRookieFlag = Nothing , _cgsRookieFlag = Nothing
, _cgsActiveFlag = Nothing
, _cgsSuccessCallback = return () , _cgsSuccessCallback = return ()
, _cgsFailureCallback = return () , _cgsFailureCallback = return ()
} }

View File

@ -321,30 +321,40 @@ addPlayerSpec = describe "addPlayer" $ mapM_
ps' = addPlayer ps ps' = addPlayer ps
in ps'^.database.dbPlayers `shouldBe` players) in ps'^.database.dbPlayers `shouldBe` players)
-- label, expectation, progMode, players -- label, expectation, progMode, players
[ ( "wrong mode", failure, MainMenu, [joe] ) [ ( "wrong mode", failure, MainMenu, [joe] )
, ( "missing number", failure, noNum, [joe] ) , ( "missing number", failure, noNum, [joe] )
, ( "missing rookie flag", failure, noRookie, [joe] ) , ( "missing rookie flag", failure, noRookie, [joe] )
, ( "rookie", success, mkRookie, [joe, rookie] ) , ( "missing active flag", failure, noActive, [joe] )
, ( "normal player", success, mkNormal, [joe, normal] ) , ( "rookie", success, mkRookie, [joe, rookie] )
, ( "retired", success, mkRetired, [joe, retired] )
, ( "normal player", success, mkNormal, [joe, normal] )
] ]
where where
failure = "should not create the player" failure = "should not create the player"
success = "should create the player" success = "should create the player"
noNum = mkpm Nothing (Just False) noNum = mkpm Nothing (Just False) (Just True)
noRookie = mkpm (Just 3) Nothing noRookie = mkpm (Just 3) Nothing (Just True)
mkRookie = mkpm (Just 3) (Just True) noActive = mkpm (Just 3) (Just False) Nothing
mkNormal = mkpm (Just 3) (Just False) 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" joe = newPlayer 2 "Joe" "centre"
rookie = bob True rookie = player True True
normal = bob False retired = player False False
bob rf = newPlayer 3 "Bob" "defense" & pRookie .~ rf normal = player False True
mkpm n rf = CreatePlayer $ newCreatePlayerState
player r a = newPlayer 3 "Bob" "defense"
& pRookie .~ r
& pActive .~ a
mkpm n r a = CreatePlayer $ newCreatePlayerState
& cpsNumber .~ n & cpsNumber .~ n
& cpsName .~ "Bob" & cpsName .~ "Bob"
& cpsPosition .~ "defense" & cpsPosition .~ "defense"
& cpsRookieFlag .~ rf & cpsRookieFlag .~ r
& cpsActiveFlag .~ a
addGoalieSpec :: Spec addGoalieSpec :: Spec
addGoalieSpec = describe "addGoalie" $ mapM_ addGoalieSpec = describe "addGoalie" $ mapM_
@ -356,29 +366,39 @@ addGoalieSpec = describe "addGoalie" $ mapM_
ps' = addGoalie ps ps' = addGoalie ps
in ps'^.database.dbGoalies `shouldBe` goalies) in ps'^.database.dbGoalies `shouldBe` goalies)
-- label, expectation, progMode, expected goalies -- label, expectation, progMode, expected goalies
[ ( "wrong mode", failure, MainMenu, [joe] ) [ ( "wrong mode", failure, MainMenu, [joe] )
, ( "no number", failure, noNum, [joe] ) , ( "no number", failure, noNum, [joe] )
, ( "no rookie flag", failure, noRookie, [joe] ) , ( "no rookie flag", failure, noRookie, [joe] )
, ( "rookie", success, mkRookie, [joe, rookie] ) , ( "no active flag", failure, noActive, [joe] )
, ( "normal goalie", success, mkNormal, [joe, normal] ) , ( "rookie", success, mkRookie, [joe, rookie] )
, ( "retired", success, mkRetired, [joe, retired] )
, ( "normal goalie", success, mkNormal, [joe, normal] )
] ]
where where
failure = "should not create the goalie" failure = "should not create the goalie"
success = "should create the goalie" success = "should create the goalie"
noNum = cgs Nothing (Just False) noNum = cgs Nothing (Just False) (Just True)
noRookie = cgs (Just 3) Nothing noRookie = cgs (Just 3) Nothing (Just True)
mkRookie = cgs (Just 3) (Just True) noActive = cgs (Just 3) (Just False) Nothing
mkNormal = cgs (Just 3) (Just False) mkRookie = cgs (Just 3) (Just True) (Just True)
joe = newGoalie 2 "Joe" mkRetired = cgs (Just 3) (Just False) (Just False)
rookie = bob True mkNormal = cgs (Just 3) (Just False) (Just True)
normal = bob False joe = newGoalie 2 "Joe"
bob r = newGoalie 3 "Bob" & gRookie .~ r rookie = goalie True True
cgs n rf = CreateGoalie $ newCreateGoalieState 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 & cgsNumber .~ n
& cgsName .~ "Bob" & cgsName .~ "Bob"
& cgsRookieFlag .~ rf & cgsRookieFlag .~ r
& cgsActiveFlag .~ a
resetCreatePlayerStateSpec :: Spec resetCreatePlayerStateSpec :: Spec
resetCreatePlayerStateSpec = describe "resetCreatePlayerState" $ let resetCreatePlayerStateSpec = describe "resetCreatePlayerState" $ let