module Rattletrap.Type.Attribute.Rotation where

import qualified Rattletrap.BitGet as BitGet
import qualified Rattletrap.BitPut as BitPut
import qualified Rattletrap.Schema as Schema
import qualified Rattletrap.Type.Int8Vector as Int8Vector
import qualified Rattletrap.Utility.Json as Json

newtype Rotation = Rotation
  { Rotation -> Int8Vector
value :: Int8Vector.Int8Vector
  }
  deriving (Rotation -> Rotation -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Rotation -> Rotation -> Bool
$c/= :: Rotation -> Rotation -> Bool
== :: Rotation -> Rotation -> Bool
$c== :: Rotation -> Rotation -> Bool
Eq, Int -> Rotation -> ShowS
[Rotation] -> ShowS
Rotation -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Rotation] -> ShowS
$cshowList :: [Rotation] -> ShowS
show :: Rotation -> String
$cshow :: Rotation -> String
showsPrec :: Int -> Rotation -> ShowS
$cshowsPrec :: Int -> Rotation -> ShowS
Show)

instance Json.FromJSON Rotation where
  parseJSON :: Value -> Parser Rotation
parseJSON = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Int8Vector -> Rotation
Rotation forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. FromJSON a => Value -> Parser a
Json.parseJSON

instance Json.ToJSON Rotation where
  toJSON :: Rotation -> Value
toJSON = forall a. ToJSON a => a -> Value
Json.toJSON forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rotation -> Int8Vector
value

schema :: Schema.Schema
schema :: Schema
schema = String -> Value -> Schema
Schema.named String
"attribute-rotation" forall a b. (a -> b) -> a -> b
$ Schema -> Value
Schema.ref Schema
Int8Vector.schema

bitPut :: Rotation -> BitPut.BitPut
bitPut :: Rotation -> BitPut
bitPut = Int8Vector -> BitPut
Int8Vector.bitPut forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rotation -> Int8Vector
value

bitGet :: BitGet.BitGet Rotation
bitGet :: BitGet Rotation
bitGet = forall a. String -> BitGet a -> BitGet a
BitGet.label String
"Rotation" forall a b. (a -> b) -> a -> b
$ do
  Int8Vector
value <- forall a. String -> BitGet a -> BitGet a
BitGet.label String
"value" BitGet Int8Vector
Int8Vector.bitGet
  forall (f :: * -> *) a. Applicative f => a -> f a
pure Rotation {Int8Vector
value :: Int8Vector
value :: Int8Vector
value}