summaryrefslogtreecommitdiff
path: root/lib/Tiled2.hs
diff options
context:
space:
mode:
authorstuebinm2021-09-18 01:34:36 +0200
committerstuebinm2021-09-18 01:34:36 +0200
commit77d1f4ce4eb3ba40d884cc4ed7fa693e16538c8d (patch)
treed452b0287f352609a7aae9e6d24f43a0eedc6e6c /lib/Tiled2.hs
parentb17396b2eeefdf113b862b254cb152557bebf68d (diff)
type check properties
/finally/ figured out that all properties just look like {name, value, type} so now that's abstracted away and Properties.hs doesn't look like javascript anymore
Diffstat (limited to '')
-rw-r--r--lib/Tiled2.hs26
1 files changed, 25 insertions, 1 deletions
diff --git a/lib/Tiled2.hs b/lib/Tiled2.hs
index bc752a5..20886bd 100644
--- a/lib/Tiled2.hs
+++ b/lib/Tiled2.hs
@@ -8,6 +8,7 @@
-- cover some of the types and records that are available in the format. For
-- those you should read the TMX documentation at
-- http://doc.mapeditor.org/en/latest/reference/tmx-map-format/
+{-# LANGUAGE NamedFieldPuns #-}
module Tiled2 where
import Control.Applicative ((<|>))
@@ -66,6 +67,29 @@ parseDefault :: FromJSON a => A.Object -> Text -> a -> Parser a
parseDefault o s d = fromMaybe d <$> o .:? s
+-- | workadventure custom property
+data Property = Property { propertyName :: Text
+ --, propertyType :: Text (unnecessary since always string)
+ , propertyValue :: Text
+ } deriving (Eq, Generic, Show)
+
+instance FromJSON Property where
+ parseJSON (A.Object o) = do
+ propertyType <- o .: "type"
+ if propertyType /= A.String "string"
+ then typeMismatch "type" "string"
+ else do
+ propertyName <- o .: "name"
+ propertyValue <- o .: "value"
+ pure $ Property { propertyName, propertyValue }
+ parseJSON invalid = typeMismatch "Property" invalid
+
+instance ToJSON Property where
+ toJSON prop = object [ "type" .= A.String "string"
+ , "name" .= propertyName prop
+ , "value" .= propertyName prop
+ ]
+
data Object = Object { objectId :: Int
-- ^ Incremental id - unique across all objects
, objectWidth :: Double
@@ -154,7 +178,7 @@ data Layer = Layer { layerWidth :: Double
-- ^ Array of GIDs. tilelayer only.
, layerObjects :: Maybe (Vector Object)
-- ^ Array of Objects. objectgroup only.
- , layerProperties :: [Map Text Value]
+ , layerProperties :: [Property]
-- ^ string key-value pairs.
, layerOpacity :: Float
-- ^ Value between 0 and 1