Merge pull request #75 from mtlstats/active-check
ask whether player/goalie is active on creation
This commit is contained in:
commit
2607fc5ce8
|
@ -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
|
||||
|
|
|
@ -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])
|
||||
|
||||
|
@ -177,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])
|
||||
|
||||
|
|
|
@ -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
|
||||
|
@ -51,7 +52,21 @@ 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
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -64,6 +79,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)"
|
||||
|
|
|
@ -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
|
||||
|
@ -55,7 +56,21 @@ 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
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -69,6 +84,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)"
|
||||
|
|
|
@ -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 ()
|
||||
}
|
||||
|
|
|
@ -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 = player True True
|
||||
retired = player False False
|
||||
normal = player False True
|
||||
|
||||
player 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_
|
||||
|
@ -356,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
|
||||
|
|
Loading…
Reference in New Issue
Block a user