module TD.Data.VectorPathCommand
(VectorPathCommand(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified TD.Data.Point as Point
data VectorPathCommand
= VectorPathCommandLine
{ VectorPathCommand -> Maybe Point
end_point :: Maybe Point.Point
}
| VectorPathCommandCubicBezierCurve
{ VectorPathCommand -> Maybe Point
start_control_point :: Maybe Point.Point
, VectorPathCommand -> Maybe Point
end_control_point :: Maybe Point.Point
, end_point :: Maybe Point.Point
}
deriving (VectorPathCommand -> VectorPathCommand -> Bool
(VectorPathCommand -> VectorPathCommand -> Bool)
-> (VectorPathCommand -> VectorPathCommand -> Bool)
-> Eq VectorPathCommand
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: VectorPathCommand -> VectorPathCommand -> Bool
== :: VectorPathCommand -> VectorPathCommand -> Bool
$c/= :: VectorPathCommand -> VectorPathCommand -> Bool
/= :: VectorPathCommand -> VectorPathCommand -> Bool
Eq, Int -> VectorPathCommand -> ShowS
[VectorPathCommand] -> ShowS
VectorPathCommand -> String
(Int -> VectorPathCommand -> ShowS)
-> (VectorPathCommand -> String)
-> ([VectorPathCommand] -> ShowS)
-> Show VectorPathCommand
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> VectorPathCommand -> ShowS
showsPrec :: Int -> VectorPathCommand -> ShowS
$cshow :: VectorPathCommand -> String
show :: VectorPathCommand -> String
$cshowList :: [VectorPathCommand] -> ShowS
showList :: [VectorPathCommand] -> ShowS
Show)
instance I.ShortShow VectorPathCommand where
shortShow :: VectorPathCommand -> String
shortShow VectorPathCommandLine
{ end_point :: VectorPathCommand -> Maybe Point
end_point = Maybe Point
end_point_
}
= String
"VectorPathCommandLine"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"end_point" String -> Maybe Point -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Point
end_point_
]
shortShow VectorPathCommandCubicBezierCurve
{ start_control_point :: VectorPathCommand -> Maybe Point
start_control_point = Maybe Point
start_control_point_
, end_control_point :: VectorPathCommand -> Maybe Point
end_control_point = Maybe Point
end_control_point_
, end_point :: VectorPathCommand -> Maybe Point
end_point = Maybe Point
end_point_
}
= String
"VectorPathCommandCubicBezierCurve"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"start_control_point" String -> Maybe Point -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Point
start_control_point_
, String
"end_control_point" String -> Maybe Point -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Point
end_control_point_
, String
"end_point" String -> Maybe Point -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Point
end_point_
]
instance AT.FromJSON VectorPathCommand where
parseJSON :: Value -> Parser VectorPathCommand
parseJSON v :: Value
v@(AT.Object Object
obj) = do
String
t <- Object
obj Object -> Key -> Parser String
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"@type" :: AT.Parser String
case String
t of
String
"vectorPathCommandLine" -> Value -> Parser VectorPathCommand
parseVectorPathCommandLine Value
v
String
"vectorPathCommandCubicBezierCurve" -> Value -> Parser VectorPathCommand
parseVectorPathCommandCubicBezierCurve Value
v
String
_ -> Parser VectorPathCommand
forall a. Monoid a => a
mempty
where
parseVectorPathCommandLine :: A.Value -> AT.Parser VectorPathCommand
parseVectorPathCommandLine :: Value -> Parser VectorPathCommand
parseVectorPathCommandLine = String
-> (Object -> Parser VectorPathCommand)
-> Value
-> Parser VectorPathCommand
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"VectorPathCommandLine" ((Object -> Parser VectorPathCommand)
-> Value -> Parser VectorPathCommand)
-> (Object -> Parser VectorPathCommand)
-> Value
-> Parser VectorPathCommand
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Point
end_point_ <- Object
o Object -> Key -> Parser (Maybe Point)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"end_point"
VectorPathCommand -> Parser VectorPathCommand
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (VectorPathCommand -> Parser VectorPathCommand)
-> VectorPathCommand -> Parser VectorPathCommand
forall a b. (a -> b) -> a -> b
$ VectorPathCommandLine
{ end_point :: Maybe Point
end_point = Maybe Point
end_point_
}
parseVectorPathCommandCubicBezierCurve :: A.Value -> AT.Parser VectorPathCommand
parseVectorPathCommandCubicBezierCurve :: Value -> Parser VectorPathCommand
parseVectorPathCommandCubicBezierCurve = String
-> (Object -> Parser VectorPathCommand)
-> Value
-> Parser VectorPathCommand
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"VectorPathCommandCubicBezierCurve" ((Object -> Parser VectorPathCommand)
-> Value -> Parser VectorPathCommand)
-> (Object -> Parser VectorPathCommand)
-> Value
-> Parser VectorPathCommand
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Point
start_control_point_ <- Object
o Object -> Key -> Parser (Maybe Point)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"start_control_point"
Maybe Point
end_control_point_ <- Object
o Object -> Key -> Parser (Maybe Point)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"end_control_point"
Maybe Point
end_point_ <- Object
o Object -> Key -> Parser (Maybe Point)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"end_point"
VectorPathCommand -> Parser VectorPathCommand
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (VectorPathCommand -> Parser VectorPathCommand)
-> VectorPathCommand -> Parser VectorPathCommand
forall a b. (a -> b) -> a -> b
$ VectorPathCommandCubicBezierCurve
{ start_control_point :: Maybe Point
start_control_point = Maybe Point
start_control_point_
, end_control_point :: Maybe Point
end_control_point = Maybe Point
end_control_point_
, end_point :: Maybe Point
end_point = Maybe Point
end_point_
}
parseJSON Value
_ = Parser VectorPathCommand
forall a. Monoid a => a
mempty