From ac92182b2036f2b0320859c8dcc1c277164fa7ac Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Sat, 28 Sep 2019 01:46:28 -0400 Subject: [PATCH] insert players at end of list (preserve index numbers) --- src/Mtlstats/Actions.hs | 2 +- src/Mtlstats/Prompt.hs | 3 ++- test/ActionsSpec.hs | 10 +++++----- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Mtlstats/Actions.hs b/src/Mtlstats/Actions.hs index b12d587..89d75a3 100644 --- a/src/Mtlstats/Actions.hs +++ b/src/Mtlstats/Actions.hs @@ -149,7 +149,7 @@ addPlayer s = fromMaybe s $ do pos = cps^.cpsPosition player = newPlayer num name pos Just $ s & database.dbPlayers - %~ (player:) + %~ (++[player]) -- | Awards the goal and assists to the players recordGoalAssists :: ProgState -> ProgState diff --git a/src/Mtlstats/Prompt.hs b/src/Mtlstats/Prompt.hs index 9d7f0d8..b4d6ee7 100644 --- a/src/Mtlstats/Prompt.hs +++ b/src/Mtlstats/Prompt.hs @@ -182,7 +182,8 @@ selectPlayerPrompt pStr callback = Prompt & cpsName .~ sStr & cpsSuccessCallback .~ do modify $ progMode .~ mode - callback (Just 0) + pIndex <- pred . length <$> gets (view $ database.dbPlayers) + callback $ Just pIndex & cpsFailureCallback .~ do modify $ progMode .~ mode callback Nothing diff --git a/test/ActionsSpec.hs b/test/ActionsSpec.hs index 9cc64ad..9a5ef62 100644 --- a/test/ActionsSpec.hs +++ b/test/ActionsSpec.hs @@ -342,7 +342,7 @@ addPlayerSpec = describe "addPlayer" $ do p1 = newPlayer 1 "Joe" "centre" p2 = newPlayer 2 "Bob" "defense" db = newDatabase - & dbPlayers .~ [p2] + & dbPlayers .~ [p1] s pm = newProgState & progMode .~ pm & database .~ db @@ -350,15 +350,15 @@ addPlayerSpec = describe "addPlayer" $ do context "data available" $ it "should create the player" $ let s' = addPlayer $ s $ CreatePlayer $ newCreatePlayerState - & cpsNumber ?~ 1 - & cpsName .~ "Joe" - & cpsPosition .~ "centre" + & cpsNumber ?~ 2 + & cpsName .~ "Bob" + & cpsPosition .~ "defense" in s'^.database.dbPlayers `shouldBe` [p1, p2] context "data unavailable" $ it "should not create the player" $ let s' = addPlayer $ s MainMenu - in s'^.database.dbPlayers `shouldBe` [p2] + in s'^.database.dbPlayers `shouldBe` [p1] recordGoalAssistsSpec :: Spec recordGoalAssistsSpec = describe "recordGoalAssists" $ do