module Rattletrap.Decode.PartyLeaderAttribute
  ( decodePartyLeaderAttributeBits
  )
where

import Rattletrap.Decode.Common
import Rattletrap.Decode.RemoteId
import Rattletrap.Decode.Word8le
import Rattletrap.Type.PartyLeaderAttribute
import Rattletrap.Type.Word8le

decodePartyLeaderAttributeBits
  :: (Int, Int, Int) -> DecodeBits PartyLeaderAttribute
decodePartyLeaderAttributeBits :: (Int, Int, Int) -> DecodeBits PartyLeaderAttribute
decodePartyLeaderAttributeBits (Int, Int, Int)
version = do
  Word8le
systemId <- DecodeBits Word8le
decodeWord8leBits
  Word8le -> Maybe (RemoteId, Word8le) -> PartyLeaderAttribute
PartyLeaderAttribute Word8le
systemId (Maybe (RemoteId, Word8le) -> PartyLeaderAttribute)
-> BitGet (Maybe (RemoteId, Word8le))
-> DecodeBits PartyLeaderAttribute
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Bool
-> BitGet (RemoteId, Word8le) -> BitGet (Maybe (RemoteId, Word8le))
forall (m :: * -> *) (f :: * -> *) a.
(Applicative m, Alternative f) =>
Bool -> m a -> m (f a)
decodeWhen
    (Word8le
systemId Word8le -> Word8le -> Bool
forall a. Eq a => a -> a -> Bool
/= Word8 -> Word8le
Word8le Word8
0)
    ((,) (RemoteId -> Word8le -> (RemoteId, Word8le))
-> BitGet RemoteId -> BitGet (Word8le -> (RemoteId, Word8le))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Int, Int, Int) -> Word8le -> BitGet RemoteId
decodeRemoteIdBits (Int, Int, Int)
version Word8le
systemId BitGet (Word8le -> (RemoteId, Word8le))
-> DecodeBits Word8le -> BitGet (RemoteId, Word8le)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> DecodeBits Word8le
decodeWord8leBits)