broke goalie input functions for game off into separate modules
This commit is contained in:
@@ -37,13 +37,11 @@ module Mtlstats.Actions
|
||||
, addGoalie
|
||||
, resetCreatePlayerState
|
||||
, resetCreateGoalieState
|
||||
, finishGameGoalieEntry
|
||||
, recordGoalAssists
|
||||
, awardGoal
|
||||
, awardAssist
|
||||
, resetGoalData
|
||||
, assignPMins
|
||||
, recordGoalieStats
|
||||
, backHome
|
||||
, scrollUp
|
||||
, scrollDown
|
||||
@@ -201,11 +199,6 @@ resetCreateGoalieState = progMode.createGoalieStateL
|
||||
%~ (cgsNumber .~ Nothing)
|
||||
. (cgsName .~ "")
|
||||
|
||||
-- | Attempts to finish game goalie entry
|
||||
finishGameGoalieEntry :: ProgState -> ProgState
|
||||
finishGameGoalieEntry s = s & progMode.gameStateL.gameGoaliesRecorded
|
||||
.~ not (null $ s^.progMode.gameStateL.gameGoalieStats)
|
||||
|
||||
-- | Awards the goal and assists to the players
|
||||
recordGoalAssists :: ProgState -> ProgState
|
||||
recordGoalAssists ps = fromMaybe ps $ do
|
||||
@@ -281,37 +274,6 @@ assignPMins mins s = fromMaybe s $ do
|
||||
)
|
||||
. (gameSelectedPlayer .~ Nothing)
|
||||
|
||||
-- | Records the goalie's game stats
|
||||
recordGoalieStats :: ProgState -> ProgState
|
||||
recordGoalieStats s = fromMaybe s $ do
|
||||
let gs = s^.progMode.gameStateL
|
||||
gid <- gs^.gameSelectedGoalie
|
||||
goalie <- nth gid $ s^.database.dbGoalies
|
||||
mins <- gs^.gameGoalieMinsPlayed
|
||||
goals <- gs^.gameGoalsAllowed
|
||||
|
||||
let
|
||||
gameStats = M.findWithDefault newGoalieStats gid $ gs^.gameGoalieStats
|
||||
bumpVal = if gameStats^.gsGames == 0
|
||||
then 1
|
||||
else 0
|
||||
|
||||
bumpStats gs = gs
|
||||
& gsGames +~ bumpVal
|
||||
& gsMinsPlayed +~ mins
|
||||
& gsGoalsAllowed +~ goals
|
||||
|
||||
Just $ s
|
||||
& progMode.gameStateL
|
||||
%~ (gameGoalieStats %~ updateMap gid newGoalieStats bumpStats)
|
||||
. (gameSelectedGoalie .~ Nothing)
|
||||
. (gameGoalieMinsPlayed .~ Nothing)
|
||||
. (gameGoalsAllowed .~ Nothing)
|
||||
& database.dbGoalies
|
||||
%~ modifyNth gid (\goalie -> goalie
|
||||
& gYtd %~ bumpStats
|
||||
& gLifetime %~ bumpStats)
|
||||
|
||||
-- | Resets the program state back to the main menu
|
||||
backHome :: ProgState -> ProgState
|
||||
backHome
|
||||
|
||||
68
src/Mtlstats/Actions/GoalieInput.hs
Normal file
68
src/Mtlstats/Actions/GoalieInput.hs
Normal file
@@ -0,0 +1,68 @@
|
||||
{- |
|
||||
|
||||
mtlstats
|
||||
Copyright (C) 2019 Rhéal Lamothe
|
||||
<rheal.lamothe@gmail.com>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or (at
|
||||
your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
-}
|
||||
|
||||
module Mtlstats.Actions.GoalieInput
|
||||
( finishGoalieEntry
|
||||
, recordGoalieStats
|
||||
) where
|
||||
|
||||
import qualified Data.Map as M
|
||||
import Data.Maybe (fromMaybe)
|
||||
import Lens.Micro ((^.), (&), (.~), (%~), (+~))
|
||||
|
||||
import Mtlstats.Types
|
||||
import Mtlstats.Util
|
||||
|
||||
-- | Attempts to finish game goalie entry
|
||||
finishGoalieEntry :: ProgState -> ProgState
|
||||
finishGoalieEntry s = s & progMode.gameStateL.gameGoaliesRecorded
|
||||
.~ not (null $ s^.progMode.gameStateL.gameGoalieStats)
|
||||
|
||||
-- | Records the goalie's game stats
|
||||
recordGoalieStats :: ProgState -> ProgState
|
||||
recordGoalieStats s = fromMaybe s $ do
|
||||
let gs = s^.progMode.gameStateL
|
||||
gid <- gs^.gameSelectedGoalie
|
||||
goalie <- nth gid $ s^.database.dbGoalies
|
||||
mins <- gs^.gameGoalieMinsPlayed
|
||||
goals <- gs^.gameGoalsAllowed
|
||||
|
||||
let
|
||||
gameStats = M.findWithDefault newGoalieStats gid $ gs^.gameGoalieStats
|
||||
bumpVal = if gameStats^.gsGames == 0
|
||||
then 1
|
||||
else 0
|
||||
|
||||
bumpStats gs = gs
|
||||
& gsGames +~ bumpVal
|
||||
& gsMinsPlayed +~ mins
|
||||
& gsGoalsAllowed +~ goals
|
||||
|
||||
Just $ s
|
||||
& progMode.gameStateL
|
||||
%~ (gameGoalieStats %~ updateMap gid newGoalieStats bumpStats)
|
||||
. (gameSelectedGoalie .~ Nothing)
|
||||
. (gameGoalieMinsPlayed .~ Nothing)
|
||||
. (gameGoalsAllowed .~ Nothing)
|
||||
& database.dbGoalies
|
||||
%~ modifyNth gid (\goalie -> goalie
|
||||
& gYtd %~ bumpStats
|
||||
& gLifetime %~ bumpStats)
|
||||
@@ -27,6 +27,7 @@ import qualified UI.NCurses as C
|
||||
|
||||
import Mtlstats.Format
|
||||
import Mtlstats.Prompt
|
||||
import Mtlstats.Prompt.GoalieInput
|
||||
import Mtlstats.Types
|
||||
import Mtlstats.Util
|
||||
|
||||
|
||||
@@ -39,17 +39,14 @@ module Mtlstats.Prompt (
|
||||
playerNumPrompt,
|
||||
playerNamePrompt,
|
||||
playerPosPrompt,
|
||||
goalieNumPrompt,
|
||||
goalieNamePrompt,
|
||||
selectPlayerPrompt,
|
||||
selectGoaliePrompt,
|
||||
recordGoalPrompt,
|
||||
recordAssistPrompt,
|
||||
pMinPlayerPrompt,
|
||||
assignPMinsPrompt,
|
||||
goalieNumPrompt,
|
||||
goalieNamePrompt,
|
||||
selectGameGoaliePrompt,
|
||||
goalieMinsPlayedPrompt,
|
||||
goalsAllowedPrompt,
|
||||
playerToEditPrompt
|
||||
) where
|
||||
|
||||
@@ -222,6 +219,16 @@ playerPosPrompt :: Prompt
|
||||
playerPosPrompt = strPrompt "Player position: " $
|
||||
modify . (progMode.createPlayerStateL.cpsPosition .~)
|
||||
|
||||
-- | Prompts tor the goalie's number
|
||||
goalieNumPrompt :: Prompt
|
||||
goalieNumPrompt = numPrompt "Goalie number: " $
|
||||
modify . (progMode.createGoalieStateL.cgsNumber ?~)
|
||||
|
||||
-- | Prompts for the goalie's name
|
||||
goalieNamePrompt :: Prompt
|
||||
goalieNamePrompt = strPrompt "Goalie name: " $
|
||||
modify . (progMode.createGoalieStateL.cgsName .~)
|
||||
|
||||
-- | Selects a player (creating one if necessary)
|
||||
selectPlayerPrompt
|
||||
:: String
|
||||
@@ -324,37 +331,6 @@ assignPMinsPrompt :: Prompt
|
||||
assignPMinsPrompt = numPrompt "Penalty minutes: " $
|
||||
modify . assignPMins
|
||||
|
||||
-- | Prompts tor the goalie's number
|
||||
goalieNumPrompt :: Prompt
|
||||
goalieNumPrompt = numPrompt "Goalie number: " $
|
||||
modify . (progMode.createGoalieStateL.cgsNumber ?~)
|
||||
|
||||
-- | Prompts for the goalie's name
|
||||
goalieNamePrompt :: Prompt
|
||||
goalieNamePrompt = strPrompt "Goalie name: " $
|
||||
modify . (progMode.createGoalieStateL.cgsName .~)
|
||||
|
||||
-- | Prompts for a goalie who played in the game
|
||||
selectGameGoaliePrompt :: Prompt
|
||||
selectGameGoaliePrompt = selectGoaliePrompt "Which goalie played this game: " $
|
||||
\case
|
||||
Nothing -> modify finishGameGoalieEntry
|
||||
Just n -> modify $ progMode.gameStateL.gameSelectedGoalie ?~ n
|
||||
|
||||
-- | Prompts for the number of minutes the goalie has played
|
||||
goalieMinsPlayedPrompt :: Prompt
|
||||
goalieMinsPlayedPrompt = numPrompt "Minutes played: " $
|
||||
modify . (progMode.gameStateL.gameGoalieMinsPlayed ?~)
|
||||
|
||||
-- | Prompts for the number of goals the goalie allowed
|
||||
goalsAllowedPrompt :: Prompt
|
||||
goalsAllowedPrompt = numPrompt "Goals allowed: " $ \n -> do
|
||||
modify (progMode.gameStateL.gameGoalsAllowed ?~ n)
|
||||
mins <- fromMaybe 0 <$> gets (^.progMode.gameStateL.gameGoalieMinsPlayed)
|
||||
when (mins >= gameLength) $
|
||||
modify $ progMode.gameStateL.gameGoaliesRecorded .~ True
|
||||
modify recordGoalieStats
|
||||
|
||||
playerToEditPrompt :: Prompt
|
||||
playerToEditPrompt = selectPlayerPrompt "Player to edit: " $
|
||||
modify . (progMode.editPlayerStateL.epsSelectedPlayer .~)
|
||||
|
||||
59
src/Mtlstats/Prompt/GoalieInput.hs
Normal file
59
src/Mtlstats/Prompt/GoalieInput.hs
Normal file
@@ -0,0 +1,59 @@
|
||||
{- |
|
||||
|
||||
mtlstats
|
||||
Copyright (C) 2019 Rhéal Lamothe
|
||||
<rheal.lamothe@gmail.com>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or (at
|
||||
your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
-}
|
||||
|
||||
{-# LANGUAGE LambdaCase #-}
|
||||
|
||||
module Mtlstats.Prompt.GoalieInput
|
||||
( selectGameGoaliePrompt
|
||||
, goalieMinsPlayedPrompt
|
||||
, goalsAllowedPrompt
|
||||
) where
|
||||
|
||||
import Control.Monad (when)
|
||||
import Control.Monad.Trans.State (gets, modify)
|
||||
import Data.Maybe (fromMaybe)
|
||||
import Lens.Micro ((^.), (.~), (?~))
|
||||
|
||||
import Mtlstats.Actions.GoalieInput
|
||||
import Mtlstats.Config
|
||||
import Mtlstats.Prompt
|
||||
import Mtlstats.Types
|
||||
|
||||
-- | Prompts for a goalie who played in the game
|
||||
selectGameGoaliePrompt :: Prompt
|
||||
selectGameGoaliePrompt = selectGoaliePrompt "Which goalie played this game: " $
|
||||
\case
|
||||
Nothing -> modify finishGoalieEntry
|
||||
Just n -> modify $ progMode.gameStateL.gameSelectedGoalie ?~ n
|
||||
|
||||
-- | Prompts for the number of minutes the goalie has played
|
||||
goalieMinsPlayedPrompt :: Prompt
|
||||
goalieMinsPlayedPrompt = numPrompt "Minutes played: " $
|
||||
modify . (progMode.gameStateL.gameGoalieMinsPlayed ?~)
|
||||
|
||||
-- | Prompts for the number of goals the goalie allowed
|
||||
goalsAllowedPrompt :: Prompt
|
||||
goalsAllowedPrompt = numPrompt "Goals allowed: " $ \n -> do
|
||||
modify (progMode.gameStateL.gameGoalsAllowed ?~ n)
|
||||
mins <- fromMaybe 0 <$> gets (^.progMode.gameStateL.gameGoalieMinsPlayed)
|
||||
when (mins >= gameLength) $
|
||||
modify $ progMode.gameStateL.gameGoaliesRecorded .~ True
|
||||
modify recordGoalieStats
|
||||
Reference in New Issue
Block a user