module Main where

import Data.IORef
import Control.Concurrent
import Control.Monad

import FRP.Yampa.Simulation
import FRP.Yampa(DTime)
import Brick.BChan
import Brick.Main
import qualified Graphics.Vty as V


import Wrapper.ToBrick
import Wrapper.FromBrick
import Game.Games
import Game.GameState
import Input

dtime :: DTime
dtime = 100000

main :: IO ()
main = do
  yampaStateRef <- newIORef neutralShowGame
  chan <- newBChan 10
  _ <- forkIO $ forever $ do
    writeBChan chan dtime
    threadDelay $ round dtime
--YampaInit
  h <- yampaInit yampaStateRef
--
  void $ customMain (V.mkVty V.defaultConfig) (Just chan) app (h, yampaStateRef, neutralShowGame)
    where neutralShowGame =(  gameStateToBrickInput neutralGameState)


yampaInit :: IORef ShowGameState ->  IO (ReactHandle Input GameState)
yampaInit ref = do
  reactInit (return NoInput)
            (outputSFResult ref)
            wholeGame









