summaryrefslogtreecommitdiff
path: root/lib/Tiled.hs
diff options
context:
space:
mode:
authorstuebinm2021-12-14 00:14:12 +0100
committerstuebinm2021-12-14 00:14:12 +0100
commit34488ce52bca4031a81c57b9b1ee79ce5c4858c6 (patch)
tree105a3489131f5d260af6f0f81891d89e86f906f1 /lib/Tiled.hs
parenteeb78b3f0a634d58258873e57194ba41af3d3711 (diff)
audioVolumne is of type float, not int
also, float properties exist, apparently
Diffstat (limited to '')
-rw-r--r--lib/Tiled.hs36
1 files changed, 24 insertions, 12 deletions
diff --git a/lib/Tiled.hs b/lib/Tiled.hs
index f1d7ec6..a092b67 100644
--- a/lib/Tiled.hs
+++ b/lib/Tiled.hs
@@ -62,7 +62,7 @@ data Property = Property Text PropertyValue
-- | The value of a custom tiled property.
-- It is strongly typed via a tag in the json representation,
-- and needs a custom ToJSON and FromJSON instance because of that.
-data PropertyValue = StrProp Text | BoolProp Bool | IntProp Int
+data PropertyValue = StrProp Text | BoolProp Bool | IntProp Int | FloatProp Float
deriving (Eq, Generic, Show)
instance IsString PropertyValue where
@@ -81,22 +81,34 @@ instance FromJSON Property where
A.String "int" -> do
val <- o .: "value"
pure $ Property name (IntProp val)
+ A.String "float" -> do
+ val <- o .: "value"
+ pure $ Property name (FloatProp val)
ty -> fail $ "properties can only have types string, int, bool, but encountered type" <> show ty
parseJSON invalid = typeMismatch "Property" invalid
instance ToJSON Property where
toJSON (Property name val) = case val of
- StrProp str -> object [ "type" .= A.String "string"
- , "name" .= name
- , "value" .= str
- ]
- BoolProp bool -> object [ "type" .= A.String "bool"
- , "name" .= name
- , "value" .= bool
- ]
- IntProp int -> object [ "type" .= A.String "int"
- , "name" .= name
- , "value" .= int]
+ StrProp str -> object
+ [ "type" .= A.String "string"
+ , "name" .= name
+ , "value" .= str
+ ]
+ BoolProp bool -> object
+ [ "type" .= A.String "bool"
+ , "name" .= name
+ , "value" .= bool
+ ]
+ IntProp int -> object
+ [ "type" .= A.String "int"
+ , "name" .= name
+ , "value" .= int
+ ]
+ FloatProp float -> object
+ [ "type" .= A.String "float"
+ , "name" .= name
+ , "value" .= float
+ ]
data Point = Point { pointX :: Double
, pointY :: Double