implemented rookie flag toggling for goalies
This commit is contained in:
parent
2c561e9807
commit
52f1e34d49
|
@ -34,6 +34,7 @@ module Mtlstats.Actions
|
|||
, editPlayer
|
||||
, editSelectedPlayer
|
||||
, editGoalie
|
||||
, editSelectedGoalie
|
||||
, addPlayer
|
||||
, addGoalie
|
||||
, resetCreatePlayerState
|
||||
|
@ -125,6 +126,19 @@ editSelectedPlayer f s = fromMaybe s $ do
|
|||
editGoalie :: ProgState -> ProgState
|
||||
editGoalie = progMode .~ EditGoalie newEditGoalieState
|
||||
|
||||
-- | Edits the selected 'Goalie'
|
||||
editSelectedGoalie
|
||||
:: (Goalie -> Goalie)
|
||||
-- ^ The modification to be made to the 'Goalie'
|
||||
-> ProgState
|
||||
-> ProgState
|
||||
editSelectedGoalie f s = fromMaybe s $ do
|
||||
n <- s^.progMode.editGoalieStateL.egsSelectedGoalie
|
||||
let
|
||||
goalies = s^.database.dbGoalies
|
||||
goalies' = modifyNth n f goalies
|
||||
Just $ s & database.dbGoalies .~ goalies'
|
||||
|
||||
-- | Adds the entered player to the roster
|
||||
addPlayer :: ProgState -> ProgState
|
||||
addPlayer s = fromMaybe s $ do
|
||||
|
|
|
@ -26,7 +26,7 @@ module Mtlstats.Menu.EditGoalie
|
|||
) where
|
||||
|
||||
import Control.Monad.Trans.State (modify)
|
||||
import Lens.Micro ((.~))
|
||||
import Lens.Micro ((.~), (%~))
|
||||
|
||||
import Mtlstats.Actions
|
||||
import Mtlstats.Types
|
||||
|
@ -35,18 +35,21 @@ import Mtlstats.Types.Menu
|
|||
-- | The 'Goalie' edit menu
|
||||
editGoalieMenu :: Menu ()
|
||||
editGoalieMenu = Menu "*** EDIT GOALTENDER ***" () $ map
|
||||
(\(ch, label, mode) -> MenuItem ch label $
|
||||
modify $ case mode of
|
||||
Nothing -> edit
|
||||
Just m -> progMode.editGoalieStateL.egsMode .~ m)
|
||||
(\(ch, label, action) -> MenuItem ch label $ modify action)
|
||||
|
||||
-- key, label, value
|
||||
[ ( '1', "Edit number", Just EGNumber )
|
||||
, ( '2', "Edit name", Just EGName )
|
||||
, ( '3', "Edit YTD stats", Just EGYtd )
|
||||
, ( '4', "Edit Lifetime stats", Just EGLifetime )
|
||||
, ( 'R', "Return to Edit Menu", Nothing )
|
||||
[ ( '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 )
|
||||
, ( 'R', "Return to Edit Menu", edit )
|
||||
]
|
||||
|
||||
where
|
||||
set mode = progMode.editGoalieStateL.egsMode .~ mode
|
||||
toggle = editSelectedGoalie (gRookie %~ not)
|
||||
|
||||
-- | The 'Goalie' YTD edit menu
|
||||
editGoalieYtdMenu :: Menu ()
|
||||
editGoalieYtdMenu = editMenu "*** EDIT GOALTENDER YEAR-TO-DATE ***"
|
||||
|
|
|
@ -55,6 +55,7 @@ spec = describe "Mtlstats.Actions" $ do
|
|||
editPlayerSpec
|
||||
editSelectedPlayerSpec
|
||||
editGoalieSpec
|
||||
editSelectedGoalieSpec
|
||||
addPlayerSpec
|
||||
addGoalieSpec
|
||||
resetCreatePlayerStateSpec
|
||||
|
@ -242,6 +243,32 @@ editGoalieSpec = describe "editGoalie" $
|
|||
s = editGoalie newProgState
|
||||
in show (s^.progMode) `shouldBe` "EditGoalie"
|
||||
|
||||
editSelectedGoalieSpec :: Spec
|
||||
editSelectedGoalieSpec = describe "editSelectedGoalie" $ mapM_
|
||||
(\(label, pState, expected) -> context label $
|
||||
it "should edit the goalies appropriately" $ let
|
||||
pState' = editSelectedGoalie (gName .~ "foo") pState
|
||||
goalies' = pState'^.database.dbGoalies
|
||||
in goalies' `shouldBe` expected)
|
||||
|
||||
-- label, initial state, expected
|
||||
[ ( "wrong mode", baseState, goalies )
|
||||
, ( "not selected", changeGoalie Nothing, goalies )
|
||||
, ( "player 0", changeGoalie $ Just 0, changed0 )
|
||||
, ( "player 1", changeGoalie $ Just 1, changed1 )
|
||||
, ( "out of bounds", changeGoalie $ Just 2, goalies )
|
||||
]
|
||||
|
||||
where
|
||||
baseState = newProgState & database.dbGoalies .~ goalies
|
||||
changeGoalie n = baseState
|
||||
& (progMode.editGoalieStateL.egsSelectedGoalie .~ n)
|
||||
goalies = [ goalie 0, goalie 1 ]
|
||||
changed0 = [ goalie' 0, goalie 1 ]
|
||||
changed1 = [ goalie 0, goalie' 1 ]
|
||||
goalie n = newGoalie n ("Player " ++ show n)
|
||||
goalie' n = newGoalie n "foo"
|
||||
|
||||
addPlayerSpec :: Spec
|
||||
addPlayerSpec = describe "addPlayer" $ do
|
||||
let
|
||||
|
|
Loading…
Reference in New Issue
Block a user