module Rattletrap.Decode.RigidBodyStateAttribute
  ( decodeRigidBodyStateAttributeBits
  )
where

import Rattletrap.Decode.Common
import Rattletrap.Decode.Rotation
import Rattletrap.Decode.Vector
import Rattletrap.Type.RigidBodyStateAttribute

decodeRigidBodyStateAttributeBits
  :: (Int, Int, Int) -> DecodeBits RigidBodyStateAttribute
decodeRigidBodyStateAttributeBits :: (Int, Int, Int) -> DecodeBits RigidBodyStateAttribute
decodeRigidBodyStateAttributeBits (Int, Int, Int)
version = do
  Bool
sleeping <- BitGet Bool
getBool
  Bool
-> Vector
-> Rotation
-> Maybe Vector
-> Maybe Vector
-> RigidBodyStateAttribute
RigidBodyStateAttribute Bool
sleeping
    (Vector
 -> Rotation
 -> Maybe Vector
 -> Maybe Vector
 -> RigidBodyStateAttribute)
-> BitGet Vector
-> BitGet
     (Rotation
      -> Maybe Vector -> Maybe Vector -> RigidBodyStateAttribute)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Int, Int, Int) -> BitGet Vector
decodeVectorBits (Int, Int, Int)
version
    BitGet
  (Rotation
   -> Maybe Vector -> Maybe Vector -> RigidBodyStateAttribute)
-> BitGet Rotation
-> BitGet (Maybe Vector -> Maybe Vector -> RigidBodyStateAttribute)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Int, Int, Int) -> BitGet Rotation
decodeRotationBits (Int, Int, Int)
version
    BitGet (Maybe Vector -> Maybe Vector -> RigidBodyStateAttribute)
-> BitGet (Maybe Vector)
-> BitGet (Maybe Vector -> RigidBodyStateAttribute)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Bool -> BitGet Vector -> BitGet (Maybe Vector)
forall (m :: * -> *) (f :: * -> *) a.
(Applicative m, Alternative f) =>
Bool -> m a -> m (f a)
decodeWhen (Bool -> Bool
not Bool
sleeping) ((Int, Int, Int) -> BitGet Vector
decodeVectorBits (Int, Int, Int)
version)
    BitGet (Maybe Vector -> RigidBodyStateAttribute)
-> BitGet (Maybe Vector) -> DecodeBits RigidBodyStateAttribute
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Bool -> BitGet Vector -> BitGet (Maybe Vector)
forall (m :: * -> *) (f :: * -> *) a.
(Applicative m, Alternative f) =>
Bool -> m a -> m (f a)
decodeWhen (Bool -> Bool
not Bool
sleeping) ((Int, Int, Int) -> BitGet Vector
decodeVectorBits (Int, Int, Int)
version)