diff options
Diffstat (limited to '')
-rw-r--r-- | lib/Tiled2.hs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/Tiled2.hs b/lib/Tiled2.hs index a82de2c..e281d00 100644 --- a/lib/Tiled2.hs +++ b/lib/Tiled2.hs @@ -24,9 +24,11 @@ import qualified Data.ByteString.Lazy as LB import Data.Char (toLower) import Data.Map (Map) import Data.Maybe (fromMaybe) +import Data.String (IsString (fromString)) import Data.Text (Text) +import qualified Data.Text as T import Data.Vector (Vector) -import GHC.Exts (fromList, toList) +import GHC.Exts (IsString, fromList, toList) import GHC.Generics (Generic) @@ -89,6 +91,8 @@ data PropertyValue = StrProp Text | BoolProp Bool data Property = Property Text PropertyValue deriving (Eq, Generic, Show) +instance IsString PropertyValue where + fromString s = StrProp (T.pack s) instance FromJSON Property where parseJSON (A.Object o) = do @@ -343,12 +347,17 @@ instance ToJSON Tiledmap where class HasProperties a where getProperties :: a -> [Property] + adjustProperties :: ([Property] -> Maybe [Property]) -> a -> a instance HasProperties Layer where getProperties = fromMaybe [] . layerProperties + adjustProperties f layer = layer + { layerProperties = f (getProperties layer) } instance HasProperties Tileset where getProperties = fromMaybe [] . tilesetProperties + adjustProperties f tileset = tileset + { tilesetProperties = f (getProperties tileset) } class HasName a where getName :: a -> Text |