-------------------------------------------------------------------------------
-- Animation
-- 2018 Francesco Ariis GPLv3
-------------------------------------------------------------------------------

-- {-# LANGUAGE DeriveGeneric #-}
-- {-# LANGUAGE DefaultSignatures #-}
-- {-# LANGUAGE StandaloneDeriving #-}
-- {-# LANGUAGE FlexibleInstances #-}

module Terminal.Game.Animation (module Terminal.Game.Animation,
                                module T
                               ) where

import Terminal.Game.Plane

import Control.Timer.Tick as T

-- import Data.Serialize

-- import qualified Data.ByteString as BS
-- import qualified Data.Bifunctor as BF

-- | An @Animation@ is a series of timed time-separated 'Plane's.
type Animation = T.Timed Plane

-- | Creates an 'Animation'.
creaAnimation :: Loop -> [(Integer, Plane)] -> Animation
creaAnimation = creaTimedRes

-- | Alias for 'fetchFrame'.
fetchAniFrame :: Animation -> Plane
fetchAniFrame = fetchFrame

-- | Alias for 'isExpired'.
isAniExpired :: Animation -> Bool
isAniExpired = isExpired


-------------------
-- SERIALISATION --
-------------------

-- deriving instance Generic loc => Generic (Frame loc)
-- instance (Generic loc, Serialize loc) => Serialize (Frame loc Integer)

-- -- xxx vanno messe in timers
-- instance Serialize ExpBehaviour
-- instance Serialize Loop

-- instance Serialize Cell
-- instance Serialize Plane
-- instance Serialize Animation

-- encodeAni :: FilePath -> Animation -> IO ()
-- encodeAni fp fs = BS.writeFile fp (encode fs)

-- decodeAni :: FilePath -> IO (Either String Animation)
-- decodeAni fp = fmap decode (BS.readFile fp) >>=
--                   return . BF.bimap err id
--     where
--           err se = fp ++ ": " ++ se