diff --git a/src/Mtlstats.hs b/src/Mtlstats.hs index 440d87c..bc790ce 100644 --- a/src/Mtlstats.hs +++ b/src/Mtlstats.hs @@ -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 diff --git a/src/Mtlstats/Events.hs b/src/Mtlstats/Events.hs index 47fafc7..483e611 100644 --- a/src/Mtlstats/Events.hs +++ b/src/Mtlstats/Events.hs @@ -21,7 +21,7 @@ along with this program. If not, see . 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 diff --git a/src/Mtlstats/Menu.hs b/src/Mtlstats/Menu.hs index 7244120..d42f8f2 100644 --- a/src/Mtlstats/Menu.hs +++ b/src/Mtlstats/Menu.hs @@ -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 diff --git a/src/Mtlstats/Types.hs b/src/Mtlstats/Types.hs index e8f12cd..0152dba 100644 --- a/src/Mtlstats/Types.hs +++ b/src/Mtlstats/Types.hs @@ -23,6 +23,7 @@ along with this program. If not, see . 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 diff --git a/src/Mtlstats/Types/Menu.hs b/src/Mtlstats/Types/Menu.hs index 8bc9476..70292b7 100644 --- a/src/Mtlstats/Types/Menu.hs +++ b/src/Mtlstats/Types/Menu.hs @@ -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 }