enable toggling of rookie flag for players
This commit is contained in:
parent
5b40a5942b
commit
e2aeb5bfa4
|
@ -32,6 +32,7 @@ module Mtlstats.Actions
|
||||||
, createGoalie
|
, createGoalie
|
||||||
, edit
|
, edit
|
||||||
, editPlayer
|
, editPlayer
|
||||||
|
, editSelectedPlayer
|
||||||
, editGoalie
|
, editGoalie
|
||||||
, addPlayer
|
, addPlayer
|
||||||
, addGoalie
|
, addGoalie
|
||||||
|
@ -47,6 +48,7 @@ import Data.Maybe (fromMaybe)
|
||||||
import Lens.Micro ((^.), (&), (.~), (%~))
|
import Lens.Micro ((^.), (&), (.~), (%~))
|
||||||
|
|
||||||
import Mtlstats.Types
|
import Mtlstats.Types
|
||||||
|
import Mtlstats.Util
|
||||||
|
|
||||||
-- | Starts a new season
|
-- | Starts a new season
|
||||||
startNewSeason :: ProgState -> ProgState
|
startNewSeason :: ProgState -> ProgState
|
||||||
|
@ -106,6 +108,19 @@ edit = progMode .~ EditMenu
|
||||||
editPlayer :: ProgState -> ProgState
|
editPlayer :: ProgState -> ProgState
|
||||||
editPlayer = progMode .~ EditPlayer newEditPlayerState
|
editPlayer = progMode .~ EditPlayer newEditPlayerState
|
||||||
|
|
||||||
|
-- | Edits the selected 'Player'
|
||||||
|
editSelectedPlayer
|
||||||
|
:: (Player -> Player)
|
||||||
|
-- ^ The modification to be made to the 'Player'
|
||||||
|
-> ProgState
|
||||||
|
-> ProgState
|
||||||
|
editSelectedPlayer f s = fromMaybe s $ do
|
||||||
|
n <- s^.progMode.editPlayerStateL.epsSelectedPlayer
|
||||||
|
let
|
||||||
|
players = s^.database.dbPlayers
|
||||||
|
players' = modifyNth n f players
|
||||||
|
Just $ s & database.dbPlayers .~ players'
|
||||||
|
|
||||||
-- | Starts the 'Goalie' editing process
|
-- | Starts the 'Goalie' editing process
|
||||||
editGoalie :: ProgState -> ProgState
|
editGoalie :: ProgState -> ProgState
|
||||||
editGoalie = progMode .~ EditGoalie newEditGoalieState
|
editGoalie = progMode .~ EditGoalie newEditGoalieState
|
||||||
|
|
|
@ -26,7 +26,7 @@ module Mtlstats.Menu.EditPlayer
|
||||||
) 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,19 +35,22 @@ import Mtlstats.Types.Menu
|
||||||
-- | The 'Player' edit menu
|
-- | The 'Player' edit menu
|
||||||
editPlayerMenu :: Menu ()
|
editPlayerMenu :: Menu ()
|
||||||
editPlayerMenu = Menu "*** EDIT PLAYER ***" () $ map
|
editPlayerMenu = Menu "*** EDIT PLAYER ***" () $ map
|
||||||
(\(ch, label, mode) -> MenuItem ch label $
|
(\(ch, label, action) -> MenuItem ch label $ modify action)
|
||||||
modify $ case mode of
|
|
||||||
Nothing -> edit
|
|
||||||
Just m -> progMode.editPlayerStateL.epsMode .~ m)
|
|
||||||
-- key, label, value
|
-- key, label, value
|
||||||
[ ( '1', "Edit number", Just EPNumber )
|
[ ( '1', "Edit number", set EPNumber )
|
||||||
, ( '2', "Edit name", Just EPName )
|
, ( '2', "Edit name", set EPName )
|
||||||
, ( '3', "Edit position", Just EPPosition )
|
, ( '3', "Edit position", set EPPosition )
|
||||||
, ( '4', "Edit YTD stats", Just EPYtd )
|
, ( '4', "Toggle rookie flag", toggle )
|
||||||
, ( '5', "Edit lifetime stats", Just EPLifetime )
|
, ( '5', "Edit YTD stats", set EPYtd )
|
||||||
, ( 'R', "Return to Edit Menu", Nothing )
|
, ( '6', "Edit lifetime stats", set EPLifetime )
|
||||||
|
, ( 'R', "Return to Edit Menu", edit )
|
||||||
]
|
]
|
||||||
|
|
||||||
|
where
|
||||||
|
set mode = progMode.editPlayerStateL.epsMode .~ mode
|
||||||
|
toggle = editSelectedPlayer $ pRookie %~ not
|
||||||
|
|
||||||
-- | The 'Player' YTD stats edit menu
|
-- | The 'Player' YTD stats edit menu
|
||||||
editPlayerYtdMenu :: Menu ()
|
editPlayerYtdMenu :: Menu ()
|
||||||
editPlayerYtdMenu = editMenu
|
editPlayerYtdMenu = editMenu
|
||||||
|
|
|
@ -53,6 +53,7 @@ spec = describe "Mtlstats.Actions" $ do
|
||||||
createGoalieSpec
|
createGoalieSpec
|
||||||
editSpec
|
editSpec
|
||||||
editPlayerSpec
|
editPlayerSpec
|
||||||
|
editSelectedPlayerSpec
|
||||||
editGoalieSpec
|
editGoalieSpec
|
||||||
addPlayerSpec
|
addPlayerSpec
|
||||||
addGoalieSpec
|
addGoalieSpec
|
||||||
|
@ -209,6 +210,32 @@ editPlayerSpec = describe "editPlayer" $
|
||||||
s = editPlayer newProgState
|
s = editPlayer newProgState
|
||||||
in show (s^.progMode) `shouldBe` "EditPlayer"
|
in show (s^.progMode) `shouldBe` "EditPlayer"
|
||||||
|
|
||||||
|
editSelectedPlayerSpec :: Spec
|
||||||
|
editSelectedPlayerSpec = describe "editSelectedPlayer" $ mapM_
|
||||||
|
(\(label, pState, expected) -> context label $
|
||||||
|
it "should edit the players appropriately" $ let
|
||||||
|
pState' = editSelectedPlayer (pName .~ "foo") pState
|
||||||
|
players' = pState'^.database.dbPlayers
|
||||||
|
in players' `shouldBe` expected)
|
||||||
|
|
||||||
|
-- label, initial state, expected
|
||||||
|
[ ( "wrong mode", baseState, players )
|
||||||
|
, ( "not selected", changePlayer Nothing, players )
|
||||||
|
, ( "player 0", changePlayer $ Just 0, changed0 )
|
||||||
|
, ( "player 1", changePlayer $ Just 1, changed1 )
|
||||||
|
, ( "out of bounds", changePlayer $ Just 2, players )
|
||||||
|
]
|
||||||
|
|
||||||
|
where
|
||||||
|
baseState = newProgState & database.dbPlayers .~ players
|
||||||
|
changePlayer n = baseState
|
||||||
|
& (progMode.editPlayerStateL.epsSelectedPlayer .~ n)
|
||||||
|
players = [ player 0, player 1 ]
|
||||||
|
changed0 = [ player' 0, player 1 ]
|
||||||
|
changed1 = [ player 0, player' 1 ]
|
||||||
|
player n = newPlayer n ("Player " ++ show n) "pos"
|
||||||
|
player' n = newPlayer n "foo" "pos"
|
||||||
|
|
||||||
editGoalieSpec :: Spec
|
editGoalieSpec :: Spec
|
||||||
editGoalieSpec = describe "editGoalie" $
|
editGoalieSpec = describe "editGoalie" $
|
||||||
it "should change the mode appropriately" $ let
|
it "should change the mode appropriately" $ let
|
||||||
|
|
Loading…
Reference in New Issue
Block a user