created Action type

This commit is contained in:
Jonathan Lamothe 2019-08-23 09:22:32 -04:00
parent fd9ffd5220
commit c95520832d
5 changed files with 13 additions and 8 deletions

View File

@ -24,7 +24,7 @@ module Mtlstats (initState, mainLoop) where
import Control.Monad (void)
import Control.Monad.Extra (whenM)
import Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.State (StateT, get)
import Control.Monad.Trans.State (get)
import Data.Maybe (fromJust)
import qualified UI.NCurses as C
@ -40,7 +40,7 @@ initState = do
return newProgState
-- | Main program loop
mainLoop :: StateT ProgState C.Curses ()
mainLoop :: Action ()
mainLoop = do
get >>= lift . draw
w <- lift C.defaultWindow

View File

@ -21,7 +21,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
module Mtlstats.Events (handleEvent) where
import Control.Monad.Trans.State (StateT, gets, modify)
import Control.Monad.Trans.State (gets, modify)
import Lens.Micro ((^.), (.~))
import Lens.Micro.Extras (view)
import qualified UI.NCurses as C
@ -34,7 +34,7 @@ import Mtlstats.Types
handleEvent
:: C.Event
-- ^ The even being handled
-> StateT ProgState C.Curses Bool
-> Action Bool
handleEvent e = do
m <- gets $ view progMode
case m of

View File

@ -29,7 +29,7 @@ module Mtlstats.Menu (
gameTypeMenu
) where
import Control.Monad.Trans.State (StateT, modify)
import Control.Monad.Trans.State (modify)
import Lens.Micro ((^.), (.~))
import qualified UI.NCurses as C
@ -42,7 +42,7 @@ drawMenu :: Menu a -> C.Update ()
drawMenu = C.drawString . show
-- | The event handler for a 'Menu'
menuHandler :: Menu a -> C.Event -> StateT ProgState C.Curses a
menuHandler :: Menu a -> C.Event -> Action a
menuHandler m (C.EventCharacter c) =
case filter (\i -> i ^. miKey == c) $ m ^. menuItems of
i:_ -> i ^. miAction

View File

@ -23,6 +23,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
module Mtlstats.Types (
-- * Types
Action,
ProgState (..),
GameState (..),
ProgMode (..),
@ -86,6 +87,7 @@ module Mtlstats.Types (
pPoints
) where
import Control.Monad.Trans.State (StateT)
import Data.Aeson
( FromJSON
, ToJSON
@ -100,6 +102,10 @@ import Data.Aeson
)
import Lens.Micro (Lens', lens, (&), (^.), (.~))
import Lens.Micro.TH (makeLenses)
import UI.NCurses (Curses)
-- | Action which maintains program state
type Action a = StateT ProgState Curses a
-- | Represents the program state
data ProgState = ProgState

View File

@ -36,7 +36,6 @@ module Mtlstats.Types.Menu (
miAction,
) where
import Control.Monad.Trans.State (StateT)
import Lens.Micro ((^.))
import Lens.Micro.TH (makeLenses)
import qualified UI.NCurses as C
@ -59,7 +58,7 @@ data MenuItem a = MenuItem
-- ^ The key that selects the menu item
, _miDescription :: String
-- ^ The description of the menu item
, _miAction :: StateT ProgState C.Curses a
, _miAction :: Action a
-- ^ The action to be performed when selected
}