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