module Rattletrap.Type.Attribute.RigidBodyState where import qualified Rattletrap.BitGet as BitGet import qualified Rattletrap.BitPut as BitPut import qualified Rattletrap.Schema as Schema import qualified Rattletrap.Type.Rotation as Rotation import qualified Rattletrap.Type.Vector as Vector import qualified Rattletrap.Type.Version as Version import qualified Rattletrap.Utility.Json as Json import qualified Rattletrap.Utility.Monad as Monad data RigidBodyState = RigidBodyState { RigidBodyState -> Bool sleeping :: Bool, RigidBodyState -> Vector location :: Vector.Vector, RigidBodyState -> Rotation rotation :: Rotation.Rotation, RigidBodyState -> Maybe Vector linearVelocity :: Maybe Vector.Vector, RigidBodyState -> Maybe Vector angularVelocity :: Maybe Vector.Vector } deriving (RigidBodyState -> RigidBodyState -> Bool (RigidBodyState -> RigidBodyState -> Bool) -> (RigidBodyState -> RigidBodyState -> Bool) -> Eq RigidBodyState forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a $c== :: RigidBodyState -> RigidBodyState -> Bool == :: RigidBodyState -> RigidBodyState -> Bool $c/= :: RigidBodyState -> RigidBodyState -> Bool /= :: RigidBodyState -> RigidBodyState -> Bool Eq, Int -> RigidBodyState -> ShowS [RigidBodyState] -> ShowS RigidBodyState -> String (Int -> RigidBodyState -> ShowS) -> (RigidBodyState -> String) -> ([RigidBodyState] -> ShowS) -> Show RigidBodyState forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a $cshowsPrec :: Int -> RigidBodyState -> ShowS showsPrec :: Int -> RigidBodyState -> ShowS $cshow :: RigidBodyState -> String show :: RigidBodyState -> String $cshowList :: [RigidBodyState] -> ShowS showList :: [RigidBodyState] -> ShowS Show) instance Json.FromJSON RigidBodyState where parseJSON :: Value -> Parser RigidBodyState parseJSON = String -> (Object -> Parser RigidBodyState) -> Value -> Parser RigidBodyState forall a. String -> (Object -> Parser a) -> Value -> Parser a Json.withObject String "RigidBodyState" ((Object -> Parser RigidBodyState) -> Value -> Parser RigidBodyState) -> (Object -> Parser RigidBodyState) -> Value -> Parser RigidBodyState forall a b. (a -> b) -> a -> b $ \Object object -> do Bool sleeping <- Object -> String -> Parser Bool forall value. FromJSON value => Object -> String -> Parser value Json.required Object object String "sleeping" Vector location <- Object -> String -> Parser Vector forall value. FromJSON value => Object -> String -> Parser value Json.required Object object String "location" Rotation rotation <- Object -> String -> Parser Rotation forall value. FromJSON value => Object -> String -> Parser value Json.required Object object String "rotation" Maybe Vector linearVelocity <- Object -> String -> Parser (Maybe Vector) forall value. FromJSON value => Object -> String -> Parser (Maybe value) Json.optional Object object String "linear_velocity" Maybe Vector angularVelocity <- Object -> String -> Parser (Maybe Vector) forall value. FromJSON value => Object -> String -> Parser (Maybe value) Json.optional Object object String "angular_velocity" RigidBodyState -> Parser RigidBodyState forall a. a -> Parser a forall (f :: * -> *) a. Applicative f => a -> f a pure RigidBodyState { Bool sleeping :: Bool sleeping :: Bool sleeping, Vector location :: Vector location :: Vector location, Rotation rotation :: Rotation rotation :: Rotation rotation, Maybe Vector linearVelocity :: Maybe Vector linearVelocity :: Maybe Vector linearVelocity, Maybe Vector angularVelocity :: Maybe Vector angularVelocity :: Maybe Vector angularVelocity } instance Json.ToJSON RigidBodyState where toJSON :: RigidBodyState -> Value toJSON RigidBodyState x = [(Key, Value)] -> Value Json.object [ String -> Bool -> (Key, Value) forall value e p. (ToJSON value, KeyValue e p) => String -> value -> p Json.pair String "sleeping" (Bool -> (Key, Value)) -> Bool -> (Key, Value) forall a b. (a -> b) -> a -> b $ RigidBodyState -> Bool sleeping RigidBodyState x, String -> Vector -> (Key, Value) forall value e p. (ToJSON value, KeyValue e p) => String -> value -> p Json.pair String "location" (Vector -> (Key, Value)) -> Vector -> (Key, Value) forall a b. (a -> b) -> a -> b $ RigidBodyState -> Vector location RigidBodyState x, String -> Rotation -> (Key, Value) forall value e p. (ToJSON value, KeyValue e p) => String -> value -> p Json.pair String "rotation" (Rotation -> (Key, Value)) -> Rotation -> (Key, Value) forall a b. (a -> b) -> a -> b $ RigidBodyState -> Rotation rotation RigidBodyState x, String -> Maybe Vector -> (Key, Value) forall value e p. (ToJSON value, KeyValue e p) => String -> value -> p Json.pair String "linear_velocity" (Maybe Vector -> (Key, Value)) -> Maybe Vector -> (Key, Value) forall a b. (a -> b) -> a -> b $ RigidBodyState -> Maybe Vector linearVelocity RigidBodyState x, String -> Maybe Vector -> (Key, Value) forall value e p. (ToJSON value, KeyValue e p) => String -> value -> p Json.pair String "angular_velocity" (Maybe Vector -> (Key, Value)) -> Maybe Vector -> (Key, Value) forall a b. (a -> b) -> a -> b $ RigidBodyState -> Maybe Vector angularVelocity RigidBodyState x ] schema :: Schema.Schema schema :: Schema schema = String -> Value -> Schema Schema.named String "attribute-rigid-body-state" (Value -> Schema) -> Value -> Schema forall a b. (a -> b) -> a -> b $ [((Key, Value), Bool)] -> Value Schema.object [ (String -> Value -> (Key, Value) forall value e p. (ToJSON value, KeyValue e p) => String -> value -> p Json.pair String "sleeping" (Value -> (Key, Value)) -> Value -> (Key, Value) forall a b. (a -> b) -> a -> b $ Schema -> Value Schema.ref Schema Schema.boolean, Bool True), (String -> Value -> (Key, Value) forall value e p. (ToJSON value, KeyValue e p) => String -> value -> p Json.pair String "location" (Value -> (Key, Value)) -> Value -> (Key, Value) forall a b. (a -> b) -> a -> b $ Schema -> Value Schema.ref Schema Vector.schema, Bool True), (String -> Value -> (Key, Value) forall value e p. (ToJSON value, KeyValue e p) => String -> value -> p Json.pair String "rotation" (Value -> (Key, Value)) -> Value -> (Key, Value) forall a b. (a -> b) -> a -> b $ Schema -> Value Schema.ref Schema Rotation.schema, Bool True), ( String -> Value -> (Key, Value) forall value e p. (ToJSON value, KeyValue e p) => String -> value -> p Json.pair String "linear_velocity" (Value -> (Key, Value)) -> (Schema -> Value) -> Schema -> (Key, Value) forall b c a. (b -> c) -> (a -> b) -> a -> c . Schema -> Value Schema.json (Schema -> (Key, Value)) -> Schema -> (Key, Value) forall a b. (a -> b) -> a -> b $ Schema -> Schema Schema.maybe Schema Vector.schema, Bool False ), ( String -> Value -> (Key, Value) forall value e p. (ToJSON value, KeyValue e p) => String -> value -> p Json.pair String "angular_velocity" (Value -> (Key, Value)) -> (Schema -> Value) -> Schema -> (Key, Value) forall b c a. (b -> c) -> (a -> b) -> a -> c . Schema -> Value Schema.json (Schema -> (Key, Value)) -> Schema -> (Key, Value) forall a b. (a -> b) -> a -> b $ Schema -> Schema Schema.maybe Schema Vector.schema, Bool False ) ] bitPut :: RigidBodyState -> BitPut.BitPut bitPut :: RigidBodyState -> BitPut bitPut RigidBodyState rigidBodyStateAttribute = Bool -> BitPut BitPut.bool (RigidBodyState -> Bool sleeping RigidBodyState rigidBodyStateAttribute) BitPut -> BitPut -> BitPut forall a. Semigroup a => a -> a -> a <> Vector -> BitPut Vector.bitPut (RigidBodyState -> Vector location RigidBodyState rigidBodyStateAttribute) BitPut -> BitPut -> BitPut forall a. Semigroup a => a -> a -> a <> Rotation -> BitPut Rotation.bitPut (RigidBodyState -> Rotation rotation RigidBodyState rigidBodyStateAttribute) BitPut -> BitPut -> BitPut forall a. Semigroup a => a -> a -> a <> (Vector -> BitPut) -> Maybe Vector -> BitPut forall m a. Monoid m => (a -> m) -> Maybe a -> m forall (t :: * -> *) m a. (Foldable t, Monoid m) => (a -> m) -> t a -> m foldMap Vector -> BitPut Vector.bitPut (RigidBodyState -> Maybe Vector linearVelocity RigidBodyState rigidBodyStateAttribute) BitPut -> BitPut -> BitPut forall a. Semigroup a => a -> a -> a <> (Vector -> BitPut) -> Maybe Vector -> BitPut forall m a. Monoid m => (a -> m) -> Maybe a -> m forall (t :: * -> *) m a. (Foldable t, Monoid m) => (a -> m) -> t a -> m foldMap Vector -> BitPut Vector.bitPut (RigidBodyState -> Maybe Vector angularVelocity RigidBodyState rigidBodyStateAttribute) bitGet :: Version.Version -> BitGet.BitGet RigidBodyState bitGet :: Version -> BitGet RigidBodyState bitGet Version version = String -> BitGet RigidBodyState -> BitGet RigidBodyState forall a. String -> BitGet a -> BitGet a BitGet.label String "RigidBodyState" (BitGet RigidBodyState -> BitGet RigidBodyState) -> BitGet RigidBodyState -> BitGet RigidBodyState forall a b. (a -> b) -> a -> b $ do Bool sleeping <- String -> BitGet Bool -> BitGet Bool forall a. String -> BitGet a -> BitGet a BitGet.label String "sleeping" BitGet Bool BitGet.bool Vector location <- String -> BitGet Vector -> BitGet Vector forall a. String -> BitGet a -> BitGet a BitGet.label String "location" (BitGet Vector -> BitGet Vector) -> BitGet Vector -> BitGet Vector forall a b. (a -> b) -> a -> b $ Version -> BitGet Vector Vector.bitGet Version version Rotation rotation <- String -> BitGet Rotation -> BitGet Rotation forall a. String -> BitGet a -> BitGet a BitGet.label String "rotation" (BitGet Rotation -> BitGet Rotation) -> BitGet Rotation -> BitGet Rotation forall a b. (a -> b) -> a -> b $ Version -> BitGet Rotation Rotation.bitGet Version version Maybe Vector linearVelocity <- String -> BitGet (Maybe Vector) -> BitGet (Maybe Vector) forall a. String -> BitGet a -> BitGet a BitGet.label String "linearVelocity" (BitGet (Maybe Vector) -> BitGet (Maybe Vector)) -> BitGet (Maybe Vector) -> BitGet (Maybe Vector) forall a b. (a -> b) -> a -> b $ Bool -> BitGet Vector -> BitGet (Maybe Vector) forall (m :: * -> *) a. Applicative m => Bool -> m a -> m (Maybe a) Monad.whenMaybe (Bool -> Bool not Bool sleeping) (Version -> BitGet Vector Vector.bitGet Version version) Maybe Vector angularVelocity <- String -> BitGet (Maybe Vector) -> BitGet (Maybe Vector) forall a. String -> BitGet a -> BitGet a BitGet.label String "angularVelocity" (BitGet (Maybe Vector) -> BitGet (Maybe Vector)) -> BitGet (Maybe Vector) -> BitGet (Maybe Vector) forall a b. (a -> b) -> a -> b $ Bool -> BitGet Vector -> BitGet (Maybe Vector) forall (m :: * -> *) a. Applicative m => Bool -> m a -> m (Maybe a) Monad.whenMaybe (Bool -> Bool not Bool sleeping) (Version -> BitGet Vector Vector.bitGet Version version) RigidBodyState -> BitGet RigidBodyState forall a. a -> Get BitString Identity a forall (f :: * -> *) a. Applicative f => a -> f a pure RigidBodyState { Bool sleeping :: Bool sleeping :: Bool sleeping, Vector location :: Vector location :: Vector location, Rotation rotation :: Rotation rotation :: Rotation rotation, Maybe Vector linearVelocity :: Maybe Vector linearVelocity :: Maybe Vector linearVelocity, Maybe Vector angularVelocity :: Maybe Vector angularVelocity :: Maybe Vector angularVelocity }