created Action type
This commit is contained in:
parent
fd9ffd5220
commit
c95520832d
|
@ -24,7 +24,7 @@ module Mtlstats (initState, mainLoop) where
|
||||||
import Control.Monad (void)
|
import Control.Monad (void)
|
||||||
import Control.Monad.Extra (whenM)
|
import Control.Monad.Extra (whenM)
|
||||||
import Control.Monad.Trans.Class (lift)
|
import Control.Monad.Trans.Class (lift)
|
||||||
import Control.Monad.Trans.State (StateT, get)
|
import Control.Monad.Trans.State (get)
|
||||||
import Data.Maybe (fromJust)
|
import Data.Maybe (fromJust)
|
||||||
import qualified UI.NCurses as C
|
import qualified UI.NCurses as C
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ initState = do
|
||||||
return newProgState
|
return newProgState
|
||||||
|
|
||||||
-- | Main program loop
|
-- | Main program loop
|
||||||
mainLoop :: StateT ProgState C.Curses ()
|
mainLoop :: Action ()
|
||||||
mainLoop = do
|
mainLoop = do
|
||||||
get >>= lift . draw
|
get >>= lift . draw
|
||||||
w <- lift C.defaultWindow
|
w <- lift C.defaultWindow
|
||||||
|
|
|
@ -21,7 +21,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
module Mtlstats.Events (handleEvent) where
|
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 ((^.), (.~))
|
||||||
import Lens.Micro.Extras (view)
|
import Lens.Micro.Extras (view)
|
||||||
import qualified UI.NCurses as C
|
import qualified UI.NCurses as C
|
||||||
|
@ -34,7 +34,7 @@ import Mtlstats.Types
|
||||||
handleEvent
|
handleEvent
|
||||||
:: C.Event
|
:: C.Event
|
||||||
-- ^ The even being handled
|
-- ^ The even being handled
|
||||||
-> StateT ProgState C.Curses Bool
|
-> Action Bool
|
||||||
handleEvent e = do
|
handleEvent e = do
|
||||||
m <- gets $ view progMode
|
m <- gets $ view progMode
|
||||||
case m of
|
case m of
|
||||||
|
|
|
@ -29,7 +29,7 @@ module Mtlstats.Menu (
|
||||||
gameTypeMenu
|
gameTypeMenu
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Monad.Trans.State (StateT, modify)
|
import Control.Monad.Trans.State (modify)
|
||||||
import Lens.Micro ((^.), (.~))
|
import Lens.Micro ((^.), (.~))
|
||||||
import qualified UI.NCurses as C
|
import qualified UI.NCurses as C
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ drawMenu :: Menu a -> C.Update ()
|
||||||
drawMenu = C.drawString . show
|
drawMenu = C.drawString . show
|
||||||
|
|
||||||
-- | The event handler for a 'Menu'
|
-- | 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) =
|
menuHandler m (C.EventCharacter c) =
|
||||||
case filter (\i -> i ^. miKey == c) $ m ^. menuItems of
|
case filter (\i -> i ^. miKey == c) $ m ^. menuItems of
|
||||||
i:_ -> i ^. miAction
|
i:_ -> i ^. miAction
|
||||||
|
|
|
@ -23,6 +23,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
module Mtlstats.Types (
|
module Mtlstats.Types (
|
||||||
-- * Types
|
-- * Types
|
||||||
|
Action,
|
||||||
ProgState (..),
|
ProgState (..),
|
||||||
GameState (..),
|
GameState (..),
|
||||||
ProgMode (..),
|
ProgMode (..),
|
||||||
|
@ -86,6 +87,7 @@ module Mtlstats.Types (
|
||||||
pPoints
|
pPoints
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
import Control.Monad.Trans.State (StateT)
|
||||||
import Data.Aeson
|
import Data.Aeson
|
||||||
( FromJSON
|
( FromJSON
|
||||||
, ToJSON
|
, ToJSON
|
||||||
|
@ -100,6 +102,10 @@ import Data.Aeson
|
||||||
)
|
)
|
||||||
import Lens.Micro (Lens', lens, (&), (^.), (.~))
|
import Lens.Micro (Lens', lens, (&), (^.), (.~))
|
||||||
import Lens.Micro.TH (makeLenses)
|
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
|
-- | Represents the program state
|
||||||
data ProgState = ProgState
|
data ProgState = ProgState
|
||||||
|
|
|
@ -36,7 +36,6 @@ module Mtlstats.Types.Menu (
|
||||||
miAction,
|
miAction,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Monad.Trans.State (StateT)
|
|
||||||
import Lens.Micro ((^.))
|
import Lens.Micro ((^.))
|
||||||
import Lens.Micro.TH (makeLenses)
|
import Lens.Micro.TH (makeLenses)
|
||||||
import qualified UI.NCurses as C
|
import qualified UI.NCurses as C
|
||||||
|
@ -59,7 +58,7 @@ data MenuItem a = MenuItem
|
||||||
-- ^ The key that selects the menu item
|
-- ^ The key that selects the menu item
|
||||||
, _miDescription :: String
|
, _miDescription :: String
|
||||||
-- ^ The description of the menu item
|
-- ^ The description of the menu item
|
||||||
, _miAction :: StateT ProgState C.Curses a
|
, _miAction :: Action a
|
||||||
-- ^ The action to be performed when selected
|
-- ^ The action to be performed when selected
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user