Merge pull request #68 from mtlstats/new-goalie-lifetime
Automatically set lifetime stats on new goalie creation
This commit is contained in:
commit
b0638b95b8
@ -1,7 +1,7 @@
|
|||||||
# Changelog for mtlstats
|
# Changelog for mtlstats
|
||||||
|
|
||||||
## current
|
## current
|
||||||
- Edit lifetime stats on new player creation
|
- Edit lifetime stats on new player/goalie creation
|
||||||
|
|
||||||
## 0.11.0
|
## 0.11.0
|
||||||
- Added active flag to players/goalies
|
- Added active flag to players/goalies
|
||||||
|
@ -21,20 +21,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
module Mtlstats.Control (dispatch) where
|
module Mtlstats.Control (dispatch) where
|
||||||
|
|
||||||
import Control.Monad (join)
|
|
||||||
import Control.Monad.Trans.State (gets, modify)
|
|
||||||
import Data.Maybe (fromJust)
|
|
||||||
import Lens.Micro ((^.))
|
import Lens.Micro ((^.))
|
||||||
import qualified UI.NCurses as C
|
|
||||||
|
|
||||||
import Mtlstats.Actions
|
import Mtlstats.Control.CreateGoalie
|
||||||
import Mtlstats.Control.CreatePlayer
|
import Mtlstats.Control.CreatePlayer
|
||||||
import Mtlstats.Control.EditGoalie
|
import Mtlstats.Control.EditGoalie
|
||||||
import Mtlstats.Control.EditPlayer
|
import Mtlstats.Control.EditPlayer
|
||||||
import Mtlstats.Control.EditStandings
|
import Mtlstats.Control.EditStandings
|
||||||
import Mtlstats.Control.NewGame
|
import Mtlstats.Control.NewGame
|
||||||
import Mtlstats.Control.TitleScreen
|
import Mtlstats.Control.TitleScreen
|
||||||
import Mtlstats.Handlers
|
|
||||||
import Mtlstats.Menu
|
import Mtlstats.Menu
|
||||||
import Mtlstats.Prompt
|
import Mtlstats.Prompt
|
||||||
import Mtlstats.Types
|
import Mtlstats.Types
|
||||||
@ -43,16 +38,13 @@ import Mtlstats.Types
|
|||||||
-- run
|
-- run
|
||||||
dispatch :: ProgState -> Controller
|
dispatch :: ProgState -> Controller
|
||||||
dispatch s = case s^.progMode of
|
dispatch s = case s^.progMode of
|
||||||
TitleScreen -> titleScreenC
|
TitleScreen -> titleScreenC
|
||||||
MainMenu -> mainMenuC
|
MainMenu -> mainMenuC
|
||||||
NewSeason flag -> newSeasonC flag
|
NewSeason flag -> newSeasonC flag
|
||||||
NewGame gs -> newGameC gs
|
NewGame gs -> newGameC gs
|
||||||
EditMenu -> editMenuC
|
EditMenu -> editMenuC
|
||||||
CreatePlayer cps -> createPlayerC cps
|
CreatePlayer cps -> createPlayerC cps
|
||||||
CreateGoalie cgs
|
CreateGoalie cgs -> createGoalieC cgs
|
||||||
| null $ cgs^.cgsNumber -> getGoalieNumC
|
|
||||||
| null $ cgs^.cgsName -> getGoalieNameC
|
|
||||||
| otherwise -> confirmCreateGoalieC
|
|
||||||
EditPlayer eps -> editPlayerC eps
|
EditPlayer eps -> editPlayerC eps
|
||||||
EditGoalie egs -> editGoalieC egs
|
EditGoalie egs -> editGoalieC egs
|
||||||
(EditStandings esm) -> editStandingsC esm
|
(EditStandings esm) -> editStandingsC esm
|
||||||
@ -69,41 +61,3 @@ newSeasonC True = menuController newSeasonMenu
|
|||||||
|
|
||||||
editMenuC :: Controller
|
editMenuC :: Controller
|
||||||
editMenuC = menuController editMenu
|
editMenuC = menuController editMenu
|
||||||
|
|
||||||
getGoalieNumC :: Controller
|
|
||||||
getGoalieNumC = Controller
|
|
||||||
{ drawController = drawPrompt goalieNumPrompt
|
|
||||||
, handleController = \e -> do
|
|
||||||
promptHandler goalieNumPrompt e
|
|
||||||
return True
|
|
||||||
}
|
|
||||||
|
|
||||||
getGoalieNameC :: Controller
|
|
||||||
getGoalieNameC = Controller
|
|
||||||
{ drawController = drawPrompt goalieNamePrompt
|
|
||||||
, handleController = \e -> do
|
|
||||||
promptHandler goalieNamePrompt e
|
|
||||||
return True
|
|
||||||
}
|
|
||||||
|
|
||||||
confirmCreateGoalieC :: Controller
|
|
||||||
confirmCreateGoalieC = Controller
|
|
||||||
{ drawController = \s -> do
|
|
||||||
let cgs = s^.progMode.createGoalieStateL
|
|
||||||
C.drawString $ unlines
|
|
||||||
[ "Goalie number: " ++ show (fromJust $ cgs^.cgsNumber)
|
|
||||||
, " Goalie name: " ++ cgs^.cgsName
|
|
||||||
, ""
|
|
||||||
, "Create goalie: are you sure? (Y/N)"
|
|
||||||
]
|
|
||||||
return C.CursorInvisible
|
|
||||||
, handleController = \e -> do
|
|
||||||
case ynHandler e of
|
|
||||||
Just True -> do
|
|
||||||
modify addGoalie
|
|
||||||
join $ gets (^.progMode.createGoalieStateL.cgsSuccessCallback)
|
|
||||||
Just False ->
|
|
||||||
join $ gets (^.progMode.createGoalieStateL.cgsFailureCallback)
|
|
||||||
Nothing -> return ()
|
|
||||||
return True
|
|
||||||
}
|
|
||||||
|
84
src/Mtlstats/Control/CreateGoalie.hs
Normal file
84
src/Mtlstats/Control/CreateGoalie.hs
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
{- |
|
||||||
|
|
||||||
|
mtlstats
|
||||||
|
Copyright (C) 1984, 1985, 2019, 2020 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.Control.CreateGoalie (createGoalieC) where
|
||||||
|
|
||||||
|
import Control.Monad (join)
|
||||||
|
import Control.Monad.Trans.State (gets, modify)
|
||||||
|
import Data.Maybe (fromJust)
|
||||||
|
import Lens.Micro ((^.), (.~), (?~), (%~), to)
|
||||||
|
import qualified UI.NCurses as C
|
||||||
|
|
||||||
|
import Mtlstats.Actions
|
||||||
|
import Mtlstats.Handlers
|
||||||
|
import Mtlstats.Prompt
|
||||||
|
import Mtlstats.Types
|
||||||
|
|
||||||
|
-- | Handles goalie creation
|
||||||
|
createGoalieC :: CreateGoalieState -> Controller
|
||||||
|
createGoalieC cgs
|
||||||
|
| null $ cgs^.cgsNumber = getGoalieNumC
|
||||||
|
| null $ cgs^.cgsName = getGoalieNameC
|
||||||
|
| otherwise = confirmCreateGoalieC
|
||||||
|
|
||||||
|
getGoalieNumC :: Controller
|
||||||
|
getGoalieNumC = Controller
|
||||||
|
{ drawController = drawPrompt goalieNumPrompt
|
||||||
|
, handleController = \e -> do
|
||||||
|
promptHandler goalieNumPrompt e
|
||||||
|
return True
|
||||||
|
}
|
||||||
|
|
||||||
|
getGoalieNameC :: Controller
|
||||||
|
getGoalieNameC = Controller
|
||||||
|
{ drawController = drawPrompt goalieNamePrompt
|
||||||
|
, handleController = \e -> do
|
||||||
|
promptHandler goalieNamePrompt e
|
||||||
|
return True
|
||||||
|
}
|
||||||
|
|
||||||
|
confirmCreateGoalieC :: Controller
|
||||||
|
confirmCreateGoalieC = Controller
|
||||||
|
{ drawController = \s -> do
|
||||||
|
let cgs = s^.progMode.createGoalieStateL
|
||||||
|
C.drawString $ unlines
|
||||||
|
[ "Goalie number: " ++ show (fromJust $ cgs^.cgsNumber)
|
||||||
|
, " Goalie name: " ++ cgs^.cgsName
|
||||||
|
, ""
|
||||||
|
, "Create goalie: are you sure? (Y/N)"
|
||||||
|
]
|
||||||
|
return C.CursorInvisible
|
||||||
|
, handleController = \e -> do
|
||||||
|
case ynHandler e of
|
||||||
|
Just True -> do
|
||||||
|
gid <- gets (^.database.dbGoalies.to length)
|
||||||
|
cb <- gets (^.progMode.createGoalieStateL.cgsSuccessCallback)
|
||||||
|
modify
|
||||||
|
$ (progMode.editGoalieStateL
|
||||||
|
%~ (egsSelectedGoalie ?~ gid)
|
||||||
|
. (egsMode .~ EGLtGames True)
|
||||||
|
. (egsCallback .~ cb))
|
||||||
|
. addGoalie
|
||||||
|
Just False ->
|
||||||
|
join $ gets (^.progMode.createGoalieStateL.cgsFailureCallback)
|
||||||
|
Nothing -> return ()
|
||||||
|
return True
|
||||||
|
}
|
@ -39,89 +39,103 @@ import Mtlstats.Util
|
|||||||
editGoalieC :: EditGoalieState -> Controller
|
editGoalieC :: EditGoalieState -> Controller
|
||||||
editGoalieC egs
|
editGoalieC egs
|
||||||
| null $ egs^.egsSelectedGoalie = selectC
|
| null $ egs^.egsSelectedGoalie = selectC
|
||||||
| otherwise = editC $ egs^.egsMode
|
| otherwise = editC (egs^.egsCallback) (egs^.egsMode)
|
||||||
|
|
||||||
selectC :: Controller
|
selectC :: Controller
|
||||||
selectC = promptController goalieToEditPrompt
|
selectC = promptController goalieToEditPrompt
|
||||||
|
|
||||||
editC :: EditGoalieMode -> Controller
|
editC :: Action () -> EditGoalieMode -> Controller
|
||||||
editC = \case
|
editC cb =
|
||||||
EGMenu -> menuC
|
( \case
|
||||||
EGNumber -> numberC
|
EGMenu -> menuC
|
||||||
EGName -> nameC
|
EGNumber -> numberC
|
||||||
EGYtd -> ytdMenuC
|
EGName -> nameC
|
||||||
EGLifetime -> lifetimeMenuC
|
EGYtd -> ytdMenuC
|
||||||
EGYtdGames b -> ytdGamesC b
|
EGLifetime -> lifetimeMenuC
|
||||||
EGYtdMins b -> ytdMinsC b
|
EGYtdGames b -> ytdGamesC b
|
||||||
EGYtdGoals b -> ytdGoalsC b
|
EGYtdMins b -> ytdMinsC b
|
||||||
EGYtdShutouts b -> ytdShutoutsC b
|
EGYtdGoals b -> ytdGoalsC b
|
||||||
EGYtdWins b -> ytdWinsC b
|
EGYtdShutouts b -> ytdShutoutsC b
|
||||||
EGYtdLosses b -> ytdLossesC b
|
EGYtdWins b -> ytdWinsC b
|
||||||
EGYtdTies -> ytdTiesC
|
EGYtdLosses b -> ytdLossesC b
|
||||||
EGLtGames b -> ltGamesC b
|
EGYtdTies -> ytdTiesC
|
||||||
EGLtMins b -> ltMinsC b
|
EGLtGames b -> ltGamesC b
|
||||||
EGLtGoals b -> ltGoalsC b
|
EGLtMins b -> ltMinsC b
|
||||||
EGLtShutouts b -> ltShutoutsC b
|
EGLtGoals b -> ltGoalsC b
|
||||||
EGLtWins b -> ltWinsC b
|
EGLtShutouts b -> ltShutoutsC b
|
||||||
EGLtLosses b -> ltLossesC b
|
EGLtWins b -> ltWinsC b
|
||||||
EGLtTies -> ltTiesC
|
EGLtLosses b -> ltLossesC b
|
||||||
|
EGLtTies -> ltTiesC
|
||||||
|
) <*> return cb
|
||||||
|
|
||||||
menuC :: Controller
|
menuC :: Action () -> Controller
|
||||||
menuC = menuControllerWith header editGoalieMenu
|
menuC _ = menuControllerWith header editGoalieMenu
|
||||||
|
|
||||||
numberC :: Controller
|
numberC :: Action () -> Controller
|
||||||
numberC = promptController editGoalieNumberPrompt
|
numberC = promptController . editGoalieNumberPrompt
|
||||||
|
|
||||||
nameC :: Controller
|
nameC :: Action () -> Controller
|
||||||
nameC = promptController editGoalieNamePrompt
|
nameC = promptController . editGoalieNamePrompt
|
||||||
|
|
||||||
ytdMenuC :: Controller
|
ytdMenuC :: Action () -> Controller
|
||||||
ytdMenuC = menuControllerWith header editGoalieYtdMenu
|
ytdMenuC _ = menuControllerWith header editGoalieYtdMenu
|
||||||
|
|
||||||
lifetimeMenuC :: Controller
|
lifetimeMenuC :: Action () -> Controller
|
||||||
lifetimeMenuC = menuControllerWith header editGoalieLtMenu
|
lifetimeMenuC _ = menuControllerWith header editGoalieLtMenu
|
||||||
|
|
||||||
ytdGamesC :: Bool -> Controller
|
ytdGamesC :: Bool -> Action () -> Controller
|
||||||
ytdGamesC = promptController . editGoalieYtdGamesPrompt
|
ytdGamesC = curry $ promptController .
|
||||||
|
uncurry editGoalieYtdGamesPrompt
|
||||||
|
|
||||||
ytdMinsC :: Bool -> Controller
|
ytdMinsC :: Bool -> Action () -> Controller
|
||||||
ytdMinsC = promptController . editGoalieYtdMinsPrompt
|
ytdMinsC = curry $ promptController .
|
||||||
|
uncurry editGoalieYtdMinsPrompt
|
||||||
|
|
||||||
ytdGoalsC :: Bool -> Controller
|
ytdGoalsC :: Bool -> Action () -> Controller
|
||||||
ytdGoalsC = promptController . editGoalieYtdGoalsPrompt
|
ytdGoalsC = curry $ promptController .
|
||||||
|
uncurry editGoalieYtdGoalsPrompt
|
||||||
|
|
||||||
ytdShutoutsC :: Bool -> Controller
|
ytdShutoutsC :: Bool -> Action () -> Controller
|
||||||
ytdShutoutsC = promptController . editGoalieYtdShutoutsPrompt
|
ytdShutoutsC = curry $ promptController .
|
||||||
|
uncurry editGoalieYtdShutoutsPrompt
|
||||||
|
|
||||||
ytdWinsC :: Bool -> Controller
|
ytdWinsC :: Bool -> Action () -> Controller
|
||||||
ytdWinsC = promptController . editGoalieYtdWinsPrompt
|
ytdWinsC = curry $ promptController .
|
||||||
|
uncurry editGoalieYtdWinsPrompt
|
||||||
|
|
||||||
ytdLossesC :: Bool -> Controller
|
ytdLossesC :: Bool -> Action () -> Controller
|
||||||
ytdLossesC = promptController . editGoalieYtdLossesPrompt
|
ytdLossesC = curry $ promptController .
|
||||||
|
uncurry editGoalieYtdLossesPrompt
|
||||||
|
|
||||||
ytdTiesC :: Controller
|
ytdTiesC :: Action () -> Controller
|
||||||
ytdTiesC = promptController editGoalieYtdTiesPrompt
|
ytdTiesC = promptController . editGoalieYtdTiesPrompt
|
||||||
|
|
||||||
ltGamesC :: Bool -> Controller
|
ltGamesC :: Bool -> Action () -> Controller
|
||||||
ltGamesC = promptController . editGoalieLtGamesPrompt
|
ltGamesC = curry $ promptController .
|
||||||
|
uncurry editGoalieLtGamesPrompt
|
||||||
|
|
||||||
ltMinsC :: Bool -> Controller
|
ltMinsC :: Bool -> Action () -> Controller
|
||||||
ltMinsC = promptController . editGoalieLtMinsPrompt
|
ltMinsC = curry $ promptController .
|
||||||
|
uncurry editGoalieLtMinsPrompt
|
||||||
|
|
||||||
ltGoalsC :: Bool -> Controller
|
ltGoalsC :: Bool -> Action() -> Controller
|
||||||
ltGoalsC = promptController . editGoalieLtGoalsPrompt
|
ltGoalsC = curry $ promptController .
|
||||||
|
uncurry editGoalieLtGoalsPrompt
|
||||||
|
|
||||||
ltShutoutsC :: Bool -> Controller
|
ltShutoutsC :: Bool -> Action () -> Controller
|
||||||
ltShutoutsC = promptController . editGoalieLtShutoutsPrompt
|
ltShutoutsC = curry $ promptController .
|
||||||
|
uncurry editGoalieLtShutoutsPrompt
|
||||||
|
|
||||||
ltWinsC :: Bool -> Controller
|
ltWinsC :: Bool -> Action () -> Controller
|
||||||
ltWinsC = promptController . editGoalieLtWinsPrompt
|
ltWinsC = curry $ promptController .
|
||||||
|
uncurry editGoalieLtWinsPrompt
|
||||||
|
|
||||||
ltLossesC :: Bool -> Controller
|
ltLossesC :: Bool -> Action () -> Controller
|
||||||
ltLossesC = promptController . editGoalieLtLossesPrompt
|
ltLossesC = curry $ promptController .
|
||||||
|
uncurry editGoalieLtLossesPrompt
|
||||||
|
|
||||||
ltTiesC :: Controller
|
ltTiesC :: Action () -> Controller
|
||||||
ltTiesC = promptController editGoalieLtTiesPrompt
|
ltTiesC = promptController . editGoalieLtTiesPrompt
|
||||||
|
|
||||||
header :: ProgState -> C.Update ()
|
header :: ProgState -> C.Update ()
|
||||||
header s = C.drawString $ fromMaybe "" $ do
|
header s = C.drawString $ fromMaybe "" $ do
|
||||||
|
@ -52,85 +52,119 @@ goalieToEditPrompt = selectGoaliePrompt "Goalie to edit: " $
|
|||||||
modify . (progMode.editGoalieStateL.egsSelectedGoalie .~)
|
modify . (progMode.editGoalieStateL.egsSelectedGoalie .~)
|
||||||
|
|
||||||
-- | Prompt to edit a goalie's number
|
-- | Prompt to edit a goalie's number
|
||||||
editGoalieNumberPrompt :: Prompt
|
editGoalieNumberPrompt
|
||||||
|
:: Action ()
|
||||||
|
-- ^ Action to perform on completion
|
||||||
|
-> Prompt
|
||||||
editGoalieNumberPrompt = editNum "Goalie number: " EGMenu
|
editGoalieNumberPrompt = editNum "Goalie number: " EGMenu
|
||||||
(gNumber .~)
|
(gNumber .~)
|
||||||
|
|
||||||
-- | Prompt to edit a goalie's name
|
-- | Prompt to edit a goalie's name
|
||||||
editGoalieNamePrompt :: Prompt
|
editGoalieNamePrompt
|
||||||
editGoalieNamePrompt = namePrompt "Goalie name: " $ \name ->
|
:: Action ()
|
||||||
|
-- ^ Action to perform on completion
|
||||||
|
-> Prompt
|
||||||
|
editGoalieNamePrompt cb = namePrompt "Goalie name: " $ \name -> do
|
||||||
if null name
|
if null name
|
||||||
then goto EGMenu
|
then goto EGMenu
|
||||||
else doEdit EGMenu $ gName .~ name
|
else doEdit EGMenu $ gName .~ name
|
||||||
|
cb
|
||||||
|
|
||||||
-- | Prompt to edit a goalie's YTD games played
|
-- | Prompt to edit a goalie's YTD games played
|
||||||
editGoalieYtdGamesPrompt
|
editGoalieYtdGamesPrompt
|
||||||
:: Bool
|
:: Bool
|
||||||
-- ^ Indicates whether or not we're in batch mode
|
-- ^ Indicates whether or not we're in batch mode
|
||||||
|
-> Action ()
|
||||||
|
-- ^ Action to perform on completion
|
||||||
-> Prompt
|
-> Prompt
|
||||||
editGoalieYtdGamesPrompt batchMode =
|
editGoalieYtdGamesPrompt batchMode cb =
|
||||||
editNum "Year-to-date games played: " mode
|
editNum "Year-to-date games played: " mode
|
||||||
(gYtd.gsGames .~)
|
(gYtd.gsGames .~) cb'
|
||||||
where
|
where
|
||||||
mode = if batchMode then EGYtdMins True else EGYtd
|
(mode, cb') = if batchMode
|
||||||
|
then (EGYtdMins True, return ())
|
||||||
|
else (EGYtd, cb)
|
||||||
|
|
||||||
-- | Prompt to edit a goalie's YTD minutes played
|
-- | Prompt to edit a goalie's YTD minutes played
|
||||||
editGoalieYtdMinsPrompt
|
editGoalieYtdMinsPrompt
|
||||||
:: Bool
|
:: Bool
|
||||||
-- ^ Indicates whether or not we're in batch mode
|
-- ^ Indicates whether or not we're in batch mode
|
||||||
|
-> Action ()
|
||||||
|
-- ^ Action to perform on completion
|
||||||
-> Prompt
|
-> Prompt
|
||||||
editGoalieYtdMinsPrompt batchMode =
|
editGoalieYtdMinsPrompt batchMode cb =
|
||||||
editNum "Year-to-date minutes played: " mode
|
editNum "Year-to-date minutes played: " mode
|
||||||
(gYtd.gsMinsPlayed .~)
|
(gYtd.gsMinsPlayed .~) cb'
|
||||||
where
|
where
|
||||||
mode = if batchMode then EGYtdGoals True else EGYtd
|
(mode, cb') = if batchMode
|
||||||
|
then (EGYtdGoals True, return ())
|
||||||
|
else (EGYtd, cb)
|
||||||
|
|
||||||
-- | Prompt to edit a goalie's YTD goales allowed
|
-- | Prompt to edit a goalie's YTD goales allowed
|
||||||
editGoalieYtdGoalsPrompt
|
editGoalieYtdGoalsPrompt
|
||||||
:: Bool
|
:: Bool
|
||||||
-- ^ Indicates whether or not we're in batch mode
|
-- ^ Indicates whether or not we're in batch mode
|
||||||
|
-> Action ()
|
||||||
|
-- ^ Action to perform on completion
|
||||||
-> Prompt
|
-> Prompt
|
||||||
editGoalieYtdGoalsPrompt batchMode =
|
editGoalieYtdGoalsPrompt batchMode cb =
|
||||||
editNum "Year-to-date goals allowed: " mode
|
editNum "Year-to-date goals allowed: " mode
|
||||||
(gYtd.gsGoalsAllowed .~)
|
(gYtd.gsGoalsAllowed .~) cb'
|
||||||
where
|
where
|
||||||
mode = if batchMode then EGYtdShutouts True else EGYtd
|
(mode, cb') = if batchMode
|
||||||
|
then (EGYtdShutouts True, return ())
|
||||||
|
else (EGYtd, cb)
|
||||||
|
|
||||||
-- | Prompt to edit a goalie's YTD shutouts
|
-- | Prompt to edit a goalie's YTD shutouts
|
||||||
editGoalieYtdShutoutsPrompt
|
editGoalieYtdShutoutsPrompt
|
||||||
:: Bool
|
:: Bool
|
||||||
-- ^ Indicates whether or not we're in batch mode
|
-- ^ Indicates whether or not we're in batch mode
|
||||||
|
-> Action ()
|
||||||
|
-- ^ Action to perform on completion
|
||||||
-> Prompt
|
-> Prompt
|
||||||
editGoalieYtdShutoutsPrompt batchMode =
|
editGoalieYtdShutoutsPrompt batchMode cb =
|
||||||
editNum "Year-to-date shutouts: " mode
|
editNum "Year-to-date shutouts: " mode
|
||||||
(gYtd.gsShutouts .~)
|
(gYtd.gsShutouts .~) cb'
|
||||||
where
|
where
|
||||||
mode = if batchMode then EGYtdWins True else EGYtd
|
(mode, cb') = if batchMode
|
||||||
|
then (EGYtdWins True, return ())
|
||||||
|
else (EGYtd, cb)
|
||||||
|
|
||||||
-- | Prompt to edit a goalie's YTD wins
|
-- | Prompt to edit a goalie's YTD wins
|
||||||
editGoalieYtdWinsPrompt
|
editGoalieYtdWinsPrompt
|
||||||
:: Bool
|
:: Bool
|
||||||
-- ^ Indicates whether or not we're in batch mode
|
-- ^ Indicates whether or not we're in batch mode
|
||||||
|
-> Action ()
|
||||||
|
-- ^ Action to perform on completion
|
||||||
-> Prompt
|
-> Prompt
|
||||||
editGoalieYtdWinsPrompt batchMode =
|
editGoalieYtdWinsPrompt batchMode cb =
|
||||||
editNum "Year-to-date wins: " mode
|
editNum "Year-to-date wins: " mode
|
||||||
(gYtd.gsWins .~)
|
(gYtd.gsWins .~) cb'
|
||||||
where
|
where
|
||||||
mode = if batchMode then EGYtdLosses True else EGYtd
|
(mode, cb') = if batchMode
|
||||||
|
then (EGYtdLosses True, return ())
|
||||||
|
else (EGYtd, cb)
|
||||||
|
|
||||||
-- | Prompt to edit a goalie's YTD losses
|
-- | Prompt to edit a goalie's YTD losses
|
||||||
editGoalieYtdLossesPrompt
|
editGoalieYtdLossesPrompt
|
||||||
:: Bool
|
:: Bool
|
||||||
-- ^ Indicates whether or not we're in batch mode
|
-- ^ Indicates whether or not we're in batch mode
|
||||||
|
-> Action ()
|
||||||
|
-- ^ Action to perform on completion
|
||||||
-> Prompt
|
-> Prompt
|
||||||
editGoalieYtdLossesPrompt batchMode =
|
editGoalieYtdLossesPrompt batchMode cb =
|
||||||
editNum "Year-to-date losses: " mode
|
editNum "Year-to-date losses: " mode
|
||||||
(gYtd.gsLosses .~)
|
(gYtd.gsLosses .~) cb'
|
||||||
where
|
where
|
||||||
mode = if batchMode then EGYtdTies else EGYtd
|
(mode, cb') = if batchMode
|
||||||
|
then (EGYtdTies, return ())
|
||||||
|
else (EGYtd, cb)
|
||||||
|
|
||||||
-- | Prompt to edit a goalie's YTD ties
|
-- | Prompt to edit a goalie's YTD ties
|
||||||
editGoalieYtdTiesPrompt :: Prompt
|
editGoalieYtdTiesPrompt
|
||||||
|
:: Action ()
|
||||||
|
-- ^ Action to perform on completion
|
||||||
|
-> Prompt
|
||||||
editGoalieYtdTiesPrompt = editNum "Year-to-date ties: " EGYtd
|
editGoalieYtdTiesPrompt = editNum "Year-to-date ties: " EGYtd
|
||||||
(gYtd.gsTies .~)
|
(gYtd.gsTies .~)
|
||||||
|
|
||||||
@ -138,70 +172,97 @@ editGoalieYtdTiesPrompt = editNum "Year-to-date ties: " EGYtd
|
|||||||
editGoalieLtGamesPrompt
|
editGoalieLtGamesPrompt
|
||||||
:: Bool
|
:: Bool
|
||||||
-- ^ Indicates whether or not we're in batch mode
|
-- ^ Indicates whether or not we're in batch mode
|
||||||
|
-> Action ()
|
||||||
|
-- ^ Action to perform on completion
|
||||||
-> Prompt
|
-> Prompt
|
||||||
editGoalieLtGamesPrompt batchMode =
|
editGoalieLtGamesPrompt batchMode cb =
|
||||||
editNum "Lifetime games played: " mode
|
editNum "Lifetime games played: " mode
|
||||||
(gLifetime.gsGames .~)
|
(gLifetime.gsGames .~) cb'
|
||||||
where
|
where
|
||||||
mode = if batchMode then EGLtMins True else EGLifetime
|
(mode, cb') = if batchMode
|
||||||
|
then (EGLtMins True, return ())
|
||||||
|
else (EGLifetime, cb)
|
||||||
|
|
||||||
-- | Prompt to edit a goalie's lifetime minutes played
|
-- | Prompt to edit a goalie's lifetime minutes played
|
||||||
editGoalieLtMinsPrompt
|
editGoalieLtMinsPrompt
|
||||||
:: Bool
|
:: Bool
|
||||||
-- ^ Indicates whether or not we're in batch mode
|
-- ^ Indicates whether or not we're in batch mode
|
||||||
|
-> Action ()
|
||||||
|
-- ^ Action to perform on completion
|
||||||
-> Prompt
|
-> Prompt
|
||||||
editGoalieLtMinsPrompt batchMode =
|
editGoalieLtMinsPrompt batchMode cb =
|
||||||
editNum "Lifetime minutes played: " mode
|
editNum "Lifetime minutes played: " mode
|
||||||
(gLifetime.gsMinsPlayed .~)
|
(gLifetime.gsMinsPlayed .~) cb'
|
||||||
where
|
where
|
||||||
mode = if batchMode then EGLtGoals True else EGLifetime
|
(mode, cb') = if batchMode
|
||||||
|
then (EGLtGoals True, return ())
|
||||||
|
else (EGLifetime, cb)
|
||||||
|
|
||||||
-- | Prompt to edit a goalie's lifetime goals allowed
|
-- | Prompt to edit a goalie's lifetime goals allowed
|
||||||
editGoalieLtGoalsPrompt
|
editGoalieLtGoalsPrompt
|
||||||
:: Bool
|
:: Bool
|
||||||
-- ^ Indicates whether or not we're in batch mode
|
-- ^ Indicates whether or not we're in batch mode
|
||||||
|
-> Action ()
|
||||||
|
-- ^ Action to perform on completion
|
||||||
-> Prompt
|
-> Prompt
|
||||||
editGoalieLtGoalsPrompt batchMode =
|
editGoalieLtGoalsPrompt batchMode cb =
|
||||||
editNum "Lifetime goals allowed: " mode
|
editNum "Lifetime goals allowed: " mode
|
||||||
(gLifetime.gsGoalsAllowed .~)
|
(gLifetime.gsGoalsAllowed .~) cb'
|
||||||
where
|
where
|
||||||
mode = if batchMode then EGLtShutouts True else EGLifetime
|
(mode, cb') = if batchMode
|
||||||
|
then (EGLtShutouts True, return ())
|
||||||
|
else (EGLifetime, cb)
|
||||||
|
|
||||||
-- | Prompt to edit a goalie's lifetime shutouts
|
-- | Prompt to edit a goalie's lifetime shutouts
|
||||||
editGoalieLtShutoutsPrompt
|
editGoalieLtShutoutsPrompt
|
||||||
:: Bool
|
:: Bool
|
||||||
-- ^ Indicates whether or not we're in batch mode
|
-- ^ Indicates whether or not we're in batch mode
|
||||||
|
-> Action ()
|
||||||
|
-- ^ Action to perform on completion
|
||||||
-> Prompt
|
-> Prompt
|
||||||
editGoalieLtShutoutsPrompt batchMode =
|
editGoalieLtShutoutsPrompt batchMode cb =
|
||||||
editNum "Lifetime shutouts: " mode
|
editNum "Lifetime shutouts: " mode
|
||||||
(gLifetime.gsShutouts .~)
|
(gLifetime.gsShutouts .~) cb'
|
||||||
where
|
where
|
||||||
mode = if batchMode then EGLtWins True else EGLifetime
|
(mode, cb') = if batchMode
|
||||||
|
then (EGLtWins True, return ())
|
||||||
|
else (EGLifetime, cb)
|
||||||
|
|
||||||
-- | Prompt to edit a goalie's lifetime wins
|
-- | Prompt to edit a goalie's lifetime wins
|
||||||
editGoalieLtWinsPrompt
|
editGoalieLtWinsPrompt
|
||||||
:: Bool
|
:: Bool
|
||||||
-- ^ Indicates whether or not we're in batch mode
|
-- ^ Indicates whether or not we're in batch mode
|
||||||
|
-> Action ()
|
||||||
|
-- ^ Action to perform on completion
|
||||||
-> Prompt
|
-> Prompt
|
||||||
editGoalieLtWinsPrompt batchMode =
|
editGoalieLtWinsPrompt batchMode cb =
|
||||||
editNum "Lifetime wins: " mode
|
editNum "Lifetime wins: " mode
|
||||||
(gLifetime.gsWins .~)
|
(gLifetime.gsWins .~) cb'
|
||||||
where
|
where
|
||||||
mode = if batchMode then EGLtLosses True else EGLifetime
|
(mode, cb') = if batchMode
|
||||||
|
then (EGLtLosses True, return ())
|
||||||
|
else (EGLifetime, cb)
|
||||||
|
|
||||||
-- | Prompt to edit a goalie's lifetime losses
|
-- | Prompt to edit a goalie's lifetime losses
|
||||||
editGoalieLtLossesPrompt
|
editGoalieLtLossesPrompt
|
||||||
:: Bool
|
:: Bool
|
||||||
-- ^ Indicates whether or not we're in batch mode
|
-- ^ Indicates whether or not we're in batch mode
|
||||||
|
-> Action ()
|
||||||
|
-- ^ Action to perform on completion
|
||||||
-> Prompt
|
-> Prompt
|
||||||
editGoalieLtLossesPrompt batchMode =
|
editGoalieLtLossesPrompt batchMode cb =
|
||||||
editNum "Lifetime losses: " mode
|
editNum "Lifetime losses: " mode
|
||||||
(gLifetime.gsLosses .~)
|
(gLifetime.gsLosses .~) cb'
|
||||||
where
|
where
|
||||||
mode = if batchMode then EGLtTies else EGLifetime
|
(mode, cb') = if batchMode
|
||||||
|
then (EGLtTies, return ())
|
||||||
|
else (EGLifetime, cb)
|
||||||
|
|
||||||
-- | Prompt to edit a goalie's lifetime ties
|
-- | Prompt to edit a goalie's lifetime ties
|
||||||
editGoalieLtTiesPrompt :: Prompt
|
editGoalieLtTiesPrompt
|
||||||
|
:: Action ()
|
||||||
|
-- ^ Action to perform on completion
|
||||||
|
-> Prompt
|
||||||
editGoalieLtTiesPrompt = editNum "Lifetime ties: " EGLifetime
|
editGoalieLtTiesPrompt = editNum "Lifetime ties: " EGLifetime
|
||||||
(gLifetime.gsTies .~)
|
(gLifetime.gsTies .~)
|
||||||
|
|
||||||
@ -209,10 +270,13 @@ editNum
|
|||||||
:: String
|
:: String
|
||||||
-> EditGoalieMode
|
-> EditGoalieMode
|
||||||
-> (Int -> Goalie -> Goalie)
|
-> (Int -> Goalie -> Goalie)
|
||||||
|
-> Action ()
|
||||||
-> Prompt
|
-> Prompt
|
||||||
editNum pStr mode f = numPromptWithFallback pStr
|
editNum pStr mode f cb = numPromptWithFallback pStr
|
||||||
(goto mode)
|
(goto mode >> cb)
|
||||||
(doEdit mode . f)
|
(\num -> do
|
||||||
|
doEdit mode $ f num
|
||||||
|
cb)
|
||||||
|
|
||||||
doEdit :: EditGoalieMode -> (Goalie -> Goalie) -> Action ()
|
doEdit :: EditGoalieMode -> (Goalie -> Goalie) -> Action ()
|
||||||
doEdit mode f = do
|
doEdit mode f = do
|
||||||
|
@ -102,6 +102,7 @@ module Mtlstats.Types (
|
|||||||
-- ** EditGoalieState Lenses
|
-- ** EditGoalieState Lenses
|
||||||
egsSelectedGoalie,
|
egsSelectedGoalie,
|
||||||
egsMode,
|
egsMode,
|
||||||
|
egsCallback,
|
||||||
-- ** Database Lenses
|
-- ** Database Lenses
|
||||||
dbPlayers,
|
dbPlayers,
|
||||||
dbGoalies,
|
dbGoalies,
|
||||||
@ -376,6 +377,9 @@ data EditGoalieState = EditGoalieState
|
|||||||
{ _egsSelectedGoalie :: Maybe Int
|
{ _egsSelectedGoalie :: Maybe Int
|
||||||
-- ^ The index number of the 'Goalie' being edited
|
-- ^ The index number of the 'Goalie' being edited
|
||||||
, _egsMode :: EditGoalieMode
|
, _egsMode :: EditGoalieMode
|
||||||
|
-- ^ The editing mode
|
||||||
|
, _egsCallback :: Action ()
|
||||||
|
-- ^ The action to perform when the edit is complete
|
||||||
}
|
}
|
||||||
|
|
||||||
-- | 'Goalie' editing mode
|
-- | 'Goalie' editing mode
|
||||||
@ -829,6 +833,7 @@ newEditGoalieState :: EditGoalieState
|
|||||||
newEditGoalieState = EditGoalieState
|
newEditGoalieState = EditGoalieState
|
||||||
{ _egsSelectedGoalie = Nothing
|
{ _egsSelectedGoalie = Nothing
|
||||||
, _egsMode = EGMenu
|
, _egsMode = EGMenu
|
||||||
|
, _egsCallback = return ()
|
||||||
}
|
}
|
||||||
|
|
||||||
-- | Constructor for a 'Database'
|
-- | Constructor for a 'Database'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user