<commit_before>{-# LANGUAGE LambdaCase #-}

module Game
  ( initialGameState
  , update
  , render
  )
where

import qualified SDL.Event                       as SDL
import qualified SDL.Input.Keyboard              as SDL
import qualified SDL.Input.Keyboard.Codes        as SDL
import qualified Graphics.Gloss                  as Gloss
import qualified Graphics.Gloss.Rendering        as Gloss


data Game = Game { counter :: Int
                 , pos :: (Int, Int)
                 }


-- Function to render a gloss picture
initialGameState = Game 0 (0, 0)


-- Update the game
update :: Game -> Game
update = id


-- Render the game to a Gloss.Picture
render :: Game -> Gloss.Picture
render game =
  let count = counter game
      (playerX, playerY) = pos game
    in Gloss.Pictures [ Gloss.Color Gloss.white $ Gloss.translate (fromIntegral playerX) (fromIntegral playerY) $ Gloss.circle 10
                      , Gloss.Color Gloss.white $ Gloss.text (show count)
                      ]<commit_msg>finally got netwire working in a pure way..<commit_after>{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NoImplicitPrelude #-}

module Game
  ( initialGameState
  , update
  , render
  )
where

import Prelude hiding ((.))

import Control.Wire hiding (id)
import FRP.Netwire.Move

import qualified SDL.Event                       as SDL
import qualified SDL.Input.Keyboard              as SDL
import qualified SDL.Input.Keyboard.Codes        as SDL
import qualified Graphics.Gloss                  as Gloss
import qualified Graphics.Gloss.Rendering        as Gloss


data Game = Game { _counter :: Double
                 }


-- A simple counter
counterWire :: (Monad m, HasTime t s) => Wire s e m a Double
counterWire = integral 0 . 1


-- The game state type, comprising of a session (fixed timestep), a main game wire, and the last game state
type GameState x e a = (Session Identity (Timed NominalDiffTime ()), Wire (Timed NominalDiffTime ()) e Identity a Game, Game)


-- Function to render a gloss picture
initialGameState :: GameState x e a
initialGameState = let session = countSession 1 <*> pure ()
                       wire = Game <$> counterWire
                       game = Game 0.0
                    in (session, wire, game)


-- Update the game
--update :: GameState x e -> GameState x e
update :: GameState Int e () -> GameState Int e ()
update (session, wire, _) = let (s, session') = runIdentity $ stepSession session
                                (r, wire') = runIdentity $ stepWire wire s (Right mempty)
                                -- Irrefutable if the game wire inhibits
                                Right game' = r
                            in (session', wire', game')


-- Render the game to a Gloss.Picture
--render :: GameState x e -> Gloss.Picture
render (_, _, game) =
  let 
      count = _counter game
      (playerX, playerY) = (0, 0)
    in Gloss.Pictures [ Gloss.Color Gloss.white $ Gloss.translate (fromIntegral playerX) (fromIntegral playerY) $ Gloss.circle 10
                      , Gloss.Color Gloss.white $ Gloss.text (show count)
                      ]
{'fraction_non_alphanumeric': 0.08572349339349017, 'fraction_numerical': 0.0045117628101836935, 'mean_word_length': 2.04612365063788, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '285946', 'n_tokens_mistral': 902, 'n_tokens_neox': 843, 'n_words': 319}