created Mtlstats.Control.CreateGoalie module
This commit is contained in:
parent
8bc9b48aa2
commit
835cb9582b
|
@ -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
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,78 @@
|
||||||
|
{- |
|
||||||
|
|
||||||
|
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 ((^.))
|
||||||
|
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
|
||||||
|
modify addGoalie
|
||||||
|
join $ gets (^.progMode.createGoalieStateL.cgsSuccessCallback)
|
||||||
|
Just False ->
|
||||||
|
join $ gets (^.progMode.createGoalieStateL.cgsFailureCallback)
|
||||||
|
Nothing -> return ()
|
||||||
|
return True
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user