{-# LANGUAGE RecordWildCards #-}

module Main where

import Control.Monad
import qualified Data.Map as M
import qualified Graphics.UI.SDL as SDL
import System.Environment (getArgs)
import System.Random

import SDLClient.SpriteSheet

rmap :: IO (M.Map (Int, Int) Int)
rmap = fmap M.fromList $ sequence $ [ go (x, y) | x <- [0..11], y <- [0..11] ]
  where go (x, y) = do r <- randomIO
                       return ((x, y), r `mod` 3)

main :: IO ()
main = do
  (texture:_) <- getArgs
  SDL.init [SDL.InitVideo, SDL.InitAudio]
  screen <- SDL.setVideoMode 640 480 8 [SDL.SWSurface]
  s1   <- loadSpriteSheet "test.texture"
  s2   <- loadSpriteSheet "rug.texture"
  s3   <- loadSpriteSheet "black.texture"
  let toSpriteSheet 0 = s1
      toSpriteSheet 1 = s2
      toSpriteSheet 2 = s3
  pic    <- rmap
  drawMap toSpriteSheet pic screen
  SDL.updateRect screen $ SDL.Rect 0 0 640 480
  _ <- getLine
  SDL.quit
