Merge pull request #61 from mtlstats/active-col
Added active field to players/goalies
This commit is contained in:
commit
fcfbcea72f
|
@ -1,5 +1,8 @@
|
|||
# Changelog for mtlstats
|
||||
|
||||
## current
|
||||
- Added active flag to players/goalies
|
||||
|
||||
## 0.10.0
|
||||
- Don't show player number zero in reports
|
||||
- Fixed player/goalie name capitalisation on edit
|
||||
|
|
|
@ -51,8 +51,12 @@ goalieDetails g = let
|
|||
goalieName :: Goalie -> String
|
||||
goalieName g = let
|
||||
|
||||
prefix = if g^.gActive
|
||||
then ""
|
||||
else "*"
|
||||
|
||||
suffix = if g^.gRookie
|
||||
then "*"
|
||||
else ""
|
||||
|
||||
in g^.gName ++ suffix
|
||||
in prefix ++ g^.gName ++ suffix
|
||||
|
|
|
@ -49,8 +49,12 @@ playerDetails p = unlines $ top ++ [""] ++ table
|
|||
playerName :: Player -> String
|
||||
playerName p = let
|
||||
|
||||
prefix = if p^.pActive
|
||||
then ""
|
||||
else "*"
|
||||
|
||||
suffix = if p^.pRookie
|
||||
then "*"
|
||||
else ""
|
||||
|
||||
in p^.pName ++ suffix
|
||||
in prefix ++ p^.pName ++ suffix
|
||||
|
|
|
@ -40,15 +40,17 @@ editGoalieMenu = Menu "*** EDIT GOALTENDER ***" () $ map
|
|||
-- key, label, value
|
||||
[ ( '1', "Edit number", set EGNumber )
|
||||
, ( '2', "Edit name", set EGName )
|
||||
, ( '3', "Toggle rookie flag", toggle )
|
||||
, ( '4', "Edit YTD stats", set EGYtd )
|
||||
, ( '5', "Edit Lifetime stats", set EGLifetime )
|
||||
, ( '3', "Toggle rookie flag", toggleRookie )
|
||||
, ( '4', "Toggle active flag", toggleActive )
|
||||
, ( '5', "Edit YTD stats", set EGYtd )
|
||||
, ( '6', "Edit Lifetime stats", set EGLifetime )
|
||||
, ( 'R', "Return to Edit Menu", edit )
|
||||
]
|
||||
|
||||
where
|
||||
set mode = progMode.editGoalieStateL.egsMode .~ mode
|
||||
toggle = editSelectedGoalie (gRookie %~ not)
|
||||
set mode = progMode.editGoalieStateL.egsMode .~ mode
|
||||
toggleRookie = editSelectedGoalie (gRookie %~ not)
|
||||
toggleActive = editSelectedGoalie (gActive %~ not)
|
||||
|
||||
-- | The 'Goalie' YTD edit menu
|
||||
editGoalieYtdMenu :: Menu ()
|
||||
|
|
|
@ -41,15 +41,17 @@ editPlayerMenu = Menu "*** EDIT PLAYER ***" () $ map
|
|||
[ ( '1', "Edit number", set EPNumber )
|
||||
, ( '2', "Edit name", set EPName )
|
||||
, ( '3', "Edit position", set EPPosition )
|
||||
, ( '4', "Toggle rookie flag", toggle )
|
||||
, ( '5', "Edit YTD stats", set EPYtd )
|
||||
, ( '6', "Edit lifetime stats", set EPLifetime )
|
||||
, ( '4', "Toggle rookie flag", toggleRookie )
|
||||
, ( '5', "Toggle active flag", toggleActive )
|
||||
, ( '6', "Edit YTD stats", set EPYtd )
|
||||
, ( '7', "Edit lifetime stats", set EPLifetime )
|
||||
, ( 'R', "Return to Edit Menu", edit )
|
||||
]
|
||||
|
||||
where
|
||||
set mode = progMode.editPlayerStateL.epsMode .~ mode
|
||||
toggle = editSelectedPlayer $ pRookie %~ not
|
||||
set mode = progMode.editPlayerStateL.epsMode .~ mode
|
||||
toggleRookie = editSelectedPlayer $ pRookie %~ not
|
||||
toggleActive = editSelectedPlayer $ pActive %~ not
|
||||
|
||||
-- | The 'Player' YTD stats edit menu
|
||||
editPlayerYtdMenu :: Menu ()
|
||||
|
|
|
@ -107,6 +107,7 @@ module Mtlstats.Types (
|
|||
pName,
|
||||
pPosition,
|
||||
pRookie,
|
||||
pActive,
|
||||
pYtd,
|
||||
pLifetime,
|
||||
-- ** PlayerStats Lenses
|
||||
|
@ -117,6 +118,7 @@ module Mtlstats.Types (
|
|||
gNumber,
|
||||
gName,
|
||||
gRookie,
|
||||
gActive,
|
||||
gYtd,
|
||||
gLifetime,
|
||||
-- ** GoalieStats Lenses
|
||||
|
@ -411,6 +413,8 @@ data Player = Player
|
|||
-- ^ The player's position
|
||||
, _pRookie :: Bool
|
||||
-- ^ Indicates that the player is a rookie
|
||||
, _pActive :: Bool
|
||||
-- ^ Indicates that the player is active
|
||||
, _pYtd :: PlayerStats
|
||||
-- ^ The Player's year-to-date stats
|
||||
, _pLifetime :: PlayerStats
|
||||
|
@ -435,6 +439,8 @@ data Goalie = Goalie
|
|||
-- ^ The goalie's name
|
||||
, _gRookie :: Bool
|
||||
-- ^ Indicates that the goalie is a rookie
|
||||
, _gActive :: Bool
|
||||
-- ^ Indicates that the goalie is active
|
||||
, _gYtd :: GoalieStats
|
||||
-- ^ The goalie's year-to-date stats
|
||||
, _gLifetime :: GoalieStats
|
||||
|
@ -555,23 +561,26 @@ instance FromJSON Player where
|
|||
<*> v .: "name"
|
||||
<*> v .: "position"
|
||||
<*> v .:? "rookie" .!= False
|
||||
<*> v .:? "active" .!= True
|
||||
<*> v .:? "ytd" .!= newPlayerStats
|
||||
<*> v .:? "lifetime" .!= newPlayerStats
|
||||
|
||||
instance ToJSON Player where
|
||||
toJSON (Player num name pos rk ytd lt) = object
|
||||
toJSON (Player num name pos rk act ytd lt) = object
|
||||
[ "number" .= num
|
||||
, "name" .= name
|
||||
, "position" .= pos
|
||||
, "rookie" .= rk
|
||||
, "active" .= act
|
||||
, "ytd" .= ytd
|
||||
, "lifetime" .= lt
|
||||
]
|
||||
toEncoding (Player num name pos rk ytd lt) = pairs $
|
||||
toEncoding (Player num name pos rk act ytd lt) = pairs $
|
||||
"number" .= num <>
|
||||
"name" .= name <>
|
||||
"position" .= pos <>
|
||||
"rookie" .= rk <>
|
||||
"active" .= act <>
|
||||
"ytd" .= ytd <>
|
||||
"lifetime" .= lt
|
||||
|
||||
|
@ -597,21 +606,24 @@ instance FromJSON Goalie where
|
|||
<$> v .: "number"
|
||||
<*> v .: "name"
|
||||
<*> v .:? "rookie" .!= False
|
||||
<*> v .:? "active" .!= True
|
||||
<*> v .:? "ytd" .!= newGoalieStats
|
||||
<*> v .:? "lifetime" .!= newGoalieStats
|
||||
|
||||
instance ToJSON Goalie where
|
||||
toJSON (Goalie num name rk ytd lt) = object
|
||||
toJSON (Goalie num name rk act ytd lt) = object
|
||||
[ "number" .= num
|
||||
, "name" .= name
|
||||
, "ytd" .= ytd
|
||||
, "rookie" .= rk
|
||||
, "active" .= act
|
||||
, "lifetime" .= lt
|
||||
]
|
||||
toEncoding (Goalie num name rk ytd lt) = pairs $
|
||||
toEncoding (Goalie num name rk act ytd lt) = pairs $
|
||||
"number" .= num <>
|
||||
"name" .= name <>
|
||||
"rookie" .= rk <>
|
||||
"active" .= act <>
|
||||
"ytd" .= ytd <>
|
||||
"lifetime" .= lt
|
||||
|
||||
|
@ -795,6 +807,7 @@ newPlayer num name pos = Player
|
|||
, _pName = name
|
||||
, _pPosition = pos
|
||||
, _pRookie = True
|
||||
, _pActive = True
|
||||
, _pYtd = newPlayerStats
|
||||
, _pLifetime = newPlayerStats
|
||||
}
|
||||
|
@ -818,6 +831,7 @@ newGoalie num name = Goalie
|
|||
{ _gNumber = num
|
||||
, _gName = name
|
||||
, _gRookie = True
|
||||
, _gActive = True
|
||||
, _gYtd = newGoalieStats
|
||||
, _gLifetime = newGoalieStats
|
||||
}
|
||||
|
|
|
@ -76,10 +76,16 @@ goalieNameSpec = describe "goalieName" $ mapM_
|
|||
it ("should be " ++ expected) $
|
||||
goalieName g `shouldBe` expected)
|
||||
|
||||
-- label, goalie, expected
|
||||
[ ( "rookie", goalie True, "foo*" )
|
||||
, ( "non-rookie", goalie False, "foo" )
|
||||
-- label, goalie, expected
|
||||
[ ( "rookie", rookie, "foo*" )
|
||||
, ( "non-rookie", active, "foo" )
|
||||
, ( "retired", retired, "*foo" )
|
||||
]
|
||||
|
||||
where
|
||||
goalie r = newGoalie 1 "foo" & gRookie .~ r
|
||||
rookie = goalie True True
|
||||
active = goalie False True
|
||||
retired = goalie False False
|
||||
goalie r a = newGoalie 1 "foo"
|
||||
& gRookie .~ r
|
||||
& gActive .~ a
|
||||
|
|
|
@ -71,9 +71,13 @@ playerNameSpec = describe "playerName" $ mapM_
|
|||
-- label, player, expected
|
||||
[ ( "rookie", rookie, "foo*" )
|
||||
, ( "non-rookie", nonRookie, "foo" )
|
||||
, ( "retired", retired, "*foo" )
|
||||
]
|
||||
|
||||
where
|
||||
rookie = player True
|
||||
nonRookie = player False
|
||||
player r = newPlayer 1 "foo" "centre" & pRookie .~ r
|
||||
rookie = player True True
|
||||
nonRookie = player False True
|
||||
retired = player False False
|
||||
player r a = newPlayer 1 "foo" "centre"
|
||||
& pRookie .~ r
|
||||
& pActive .~ a
|
||||
|
|
|
@ -281,6 +281,7 @@ playerJSON = Object $ HM.fromList
|
|||
, ( "name", toJSON ("Joe" :: String) )
|
||||
, ( "position", toJSON ("centre" :: String) )
|
||||
, ( "rookie", toJSON False )
|
||||
, ( "active", toJSON True )
|
||||
, ( "ytd", playerStatsJSON 1 )
|
||||
, ( "lifetime", playerStatsJSON 2 )
|
||||
]
|
||||
|
@ -309,6 +310,7 @@ goalieJSON = Object $ HM.fromList
|
|||
[ ( "number", toJSON (1 :: Int) )
|
||||
, ( "name", toJSON ("Joe" :: String ) )
|
||||
, ( "rookie", toJSON False )
|
||||
, ( "active", toJSON True )
|
||||
, ( "ytd", goalieStatsJSON 1 )
|
||||
, ( "lifetime", goalieStatsJSON 2 )
|
||||
]
|
||||
|
@ -848,6 +850,7 @@ makePlayer = Player
|
|||
<*> makeName
|
||||
<*> makeName
|
||||
<*> makeBool
|
||||
<*> makeBool
|
||||
<*> makePlayerStats
|
||||
<*> makePlayerStats
|
||||
|
||||
|
@ -857,6 +860,7 @@ makeGoalie = Goalie
|
|||
<$> makeNum
|
||||
<*> makeName
|
||||
<*> makeBool
|
||||
<*> makeBool
|
||||
<*> makeGoalieStats
|
||||
<*> makeGoalieStats
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user