created Mtlstats.Control.CreatePlayer module
This commit is contained in:
parent
2f0a3a5c57
commit
ffc1390755
|
@ -25,15 +25,15 @@ import Control.Monad (join)
|
||||||
import Control.Monad.Trans.State (gets, modify)
|
import Control.Monad.Trans.State (gets, modify)
|
||||||
import Data.Maybe (fromJust)
|
import Data.Maybe (fromJust)
|
||||||
import Lens.Micro ((^.))
|
import Lens.Micro ((^.))
|
||||||
import Lens.Micro.Extras (view)
|
|
||||||
import qualified UI.NCurses as C
|
import qualified UI.NCurses as C
|
||||||
|
|
||||||
import Mtlstats.Actions
|
import Mtlstats.Actions
|
||||||
import Mtlstats.Control.TitleScreen
|
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.Handlers
|
import Mtlstats.Handlers
|
||||||
import Mtlstats.Menu
|
import Mtlstats.Menu
|
||||||
import Mtlstats.Prompt
|
import Mtlstats.Prompt
|
||||||
|
@ -43,16 +43,12 @@ 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
|
CreatePlayer cps -> createPlayerC cps
|
||||||
| null $ cps^.cpsNumber -> getPlayerNumC
|
|
||||||
| null $ cps^.cpsName -> getPlayerNameC
|
|
||||||
| null $ cps^.cpsPosition -> getPlayerPosC
|
|
||||||
| otherwise -> confirmCreatePlayerC
|
|
||||||
CreateGoalie cgs
|
CreateGoalie cgs
|
||||||
| null $ cgs^.cgsNumber -> getGoalieNumC
|
| null $ cgs^.cgsNumber -> getGoalieNumC
|
||||||
| null $ cgs^.cgsName -> getGoalieNameC
|
| null $ cgs^.cgsName -> getGoalieNameC
|
||||||
|
@ -74,50 +70,6 @@ newSeasonC True = menuController newSeasonMenu
|
||||||
editMenuC :: Controller
|
editMenuC :: Controller
|
||||||
editMenuC = menuController editMenu
|
editMenuC = menuController editMenu
|
||||||
|
|
||||||
getPlayerNumC :: Controller
|
|
||||||
getPlayerNumC = Controller
|
|
||||||
{ drawController = drawPrompt playerNumPrompt
|
|
||||||
, handleController = \e -> do
|
|
||||||
promptHandler playerNumPrompt e
|
|
||||||
return True
|
|
||||||
}
|
|
||||||
|
|
||||||
getPlayerNameC :: Controller
|
|
||||||
getPlayerNameC = Controller
|
|
||||||
{ drawController = drawPrompt playerNamePrompt
|
|
||||||
, handleController = \e -> do
|
|
||||||
promptHandler playerNamePrompt e
|
|
||||||
return True
|
|
||||||
}
|
|
||||||
|
|
||||||
getPlayerPosC :: Controller
|
|
||||||
getPlayerPosC = Controller
|
|
||||||
{ drawController = drawPrompt playerPosPrompt
|
|
||||||
, handleController = \e -> do
|
|
||||||
promptHandler playerPosPrompt e
|
|
||||||
return True
|
|
||||||
}
|
|
||||||
|
|
||||||
confirmCreatePlayerC :: Controller
|
|
||||||
confirmCreatePlayerC = Controller
|
|
||||||
{ drawController = \s -> do
|
|
||||||
let cps = s^.progMode.createPlayerStateL
|
|
||||||
C.drawString $ " Player number: " ++ show (fromJust $ cps^.cpsNumber) ++ "\n"
|
|
||||||
C.drawString $ " Player name: " ++ cps^.cpsName ++ "\n"
|
|
||||||
C.drawString $ "Player position: " ++ cps^.cpsPosition ++ "\n\n"
|
|
||||||
C.drawString "Create player: are you sure? (Y/N)"
|
|
||||||
return C.CursorInvisible
|
|
||||||
, handleController = \e -> do
|
|
||||||
case ynHandler e of
|
|
||||||
Just True -> do
|
|
||||||
modify addPlayer
|
|
||||||
join $ gets $ view $ progMode.createPlayerStateL.cpsSuccessCallback
|
|
||||||
Just False ->
|
|
||||||
join $ gets $ view $ progMode.createPlayerStateL.cpsFailureCallback
|
|
||||||
Nothing -> return ()
|
|
||||||
return True
|
|
||||||
}
|
|
||||||
|
|
||||||
getGoalieNumC :: Controller
|
getGoalieNumC :: Controller
|
||||||
getGoalieNumC = Controller
|
getGoalieNumC = Controller
|
||||||
{ drawController = drawPrompt goalieNumPrompt
|
{ drawController = drawPrompt goalieNumPrompt
|
||||||
|
|
|
@ -0,0 +1,85 @@
|
||||||
|
{- |
|
||||||
|
|
||||||
|
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.CreatePlayer (createPlayerC) 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 player creation
|
||||||
|
createPlayerC :: CreatePlayerState -> Controller
|
||||||
|
createPlayerC cps
|
||||||
|
| null $ cps^.cpsNumber = getPlayerNumC
|
||||||
|
| null $ cps^.cpsName = getPlayerNameC
|
||||||
|
| null $ cps^.cpsPosition = getPlayerPosC
|
||||||
|
| otherwise = confirmCreatePlayerC
|
||||||
|
|
||||||
|
getPlayerNumC :: Controller
|
||||||
|
getPlayerNumC = Controller
|
||||||
|
{ drawController = drawPrompt playerNumPrompt
|
||||||
|
, handleController = \e -> do
|
||||||
|
promptHandler playerNumPrompt e
|
||||||
|
return True
|
||||||
|
}
|
||||||
|
|
||||||
|
getPlayerNameC :: Controller
|
||||||
|
getPlayerNameC = Controller
|
||||||
|
{ drawController = drawPrompt playerNamePrompt
|
||||||
|
, handleController = \e -> do
|
||||||
|
promptHandler playerNamePrompt e
|
||||||
|
return True
|
||||||
|
}
|
||||||
|
|
||||||
|
getPlayerPosC :: Controller
|
||||||
|
getPlayerPosC = Controller
|
||||||
|
{ drawController = drawPrompt playerPosPrompt
|
||||||
|
, handleController = \e -> do
|
||||||
|
promptHandler playerPosPrompt e
|
||||||
|
return True
|
||||||
|
}
|
||||||
|
|
||||||
|
confirmCreatePlayerC :: Controller
|
||||||
|
confirmCreatePlayerC = Controller
|
||||||
|
{ drawController = \s -> do
|
||||||
|
let cps = s^.progMode.createPlayerStateL
|
||||||
|
C.drawString $ " Player number: " ++ show (fromJust $ cps^.cpsNumber) ++ "\n"
|
||||||
|
C.drawString $ " Player name: " ++ cps^.cpsName ++ "\n"
|
||||||
|
C.drawString $ "Player position: " ++ cps^.cpsPosition ++ "\n\n"
|
||||||
|
C.drawString "Create player: are you sure? (Y/N)"
|
||||||
|
return C.CursorInvisible
|
||||||
|
, handleController = \e -> do
|
||||||
|
case ynHandler e of
|
||||||
|
Just True -> do
|
||||||
|
modify addPlayer
|
||||||
|
join $ gets (^.progMode.createPlayerStateL.cpsSuccessCallback)
|
||||||
|
Just False ->
|
||||||
|
join $ gets (^.progMode.createPlayerStateL.cpsFailureCallback)
|
||||||
|
Nothing -> return ()
|
||||||
|
return True
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user