aeson-tiled 0.0.2.2 → 0.0.2.3
raw patch · 5 files changed
+63/−4 lines, 5 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ Codec.Tiled.Aeson: omitField :: ToJSON a => a -> Bool
+ Codec.Tiled.Aeson: omittedField :: FromJSON a => Maybe a
+ Codec.Tiled.World.IO: WorldError :: Text -> WorldError
+ Codec.Tiled.World.IO: instance GHC.Classes.Eq Codec.Tiled.World.IO.WorldError
+ Codec.Tiled.World.IO: instance GHC.Exception.Type.Exception Codec.Tiled.World.IO.WorldError
+ Codec.Tiled.World.IO: instance GHC.Show.Show Codec.Tiled.World.IO.WorldError
+ Codec.Tiled.World.IO: newtype WorldError
+ Codec.Tiled.World.IO: readFile :: MonadIO m => FilePath -> m World
+ Codec.Tiled.World.IO: writeFile :: MonadIO m => FilePath -> World -> m ()
- Codec.Tiled.Property: Property :: Text -> Maybe Text -> Text -> Value -> Property
+ Codec.Tiled.Property: Property :: Text -> Maybe Text -> Maybe Text -> Value -> Property
- Codec.Tiled.Property: [propertyType] :: Property -> Text
+ Codec.Tiled.Property: [propertyType] :: Property -> Maybe Text
Files
- ChangeLog.md +7/−0
- aeson-tiled.cabal +9/−3
- src/Codec/Tiled/Property.hs +1/−1
- src/Codec/Tiled/World/IO.hs +37/−0
- tests/Main.hs +9/−0
ChangeLog.md view
@@ -1,5 +1,10 @@ # Change Log +## [0.0.2.3] - 2023-11-08++- Exposed `Codec.Tiled.World.IO`.+- Made `propertytype` optional.+ ## [0.0.2.2] - 2022-12-24 - Fixed bits and flags in Data.Tiled.GID.@@ -27,6 +32,8 @@ Initial release. +[0.0.2.3]: https://github.com/haskell-game/aeson-tiled/releases/tag/v0.0.2.3+[0.0.2.2]: https://github.com/haskell-game/aeson-tiled/releases/tag/v0.0.2.2 [0.0.2.1]: https://github.com/haskell-game/aeson-tiled/releases/tag/v0.0.2.1 [0.0.2.0]: https://github.com/haskell-game/aeson-tiled/releases/tag/v0.0.2.0 [0.0.1.0]: https://github.com/haskell-game/aeson-tiled/releases/tag/v0.0.1.0
aeson-tiled.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: aeson-tiled-version: 0.0.2.2+version: 0.0.2.3 synopsis: Aeson instances for the Tiled map editor. description: The mighty Tiled 2D map editor is an open source@@ -16,10 +16,11 @@ build-type: Simple extra-source-files:- README.md,- ChangeLog.md, maps/microgue/*.tmj, maps/microgue/*.tsj+extra-doc-files:+ README.md,+ ChangeLog.md library hs-source-dirs: src@@ -50,6 +51,7 @@ Codec.Tiled.Tileset.WangSet Codec.Tiled.Tileset.WangTile Codec.Tiled.World+ Codec.Tiled.World.IO Codec.Tiled.World.Map Codec.Tiled.World.Pattern Data.Tiled.GID@@ -108,3 +110,7 @@ PatternSynonyms, RecordWildCards, StrictData,++source-repository head+ type: git+ location: https://github.com/haskell-game/aeson-tiled
src/Codec/Tiled/Property.hs view
@@ -9,7 +9,7 @@ data Property = Property { name :: Text -- ^ Name of the property , type_ :: Maybe Text -- ^ Type of the property (@string@ (default), @int@, @float@, @bool@, @color@, @file@, @object@ or @class@)- , propertyType :: Text -- ^ Name of the custom property type, when applicable+ , propertyType :: Maybe Text -- ^ Name of the custom property type, when applicable , value :: Value -- ^ Value of the property } deriving (Eq, Show, Generic)
+ src/Codec/Tiled/World/IO.hs view
@@ -0,0 +1,37 @@+module Codec.Tiled.World.IO+ ( WorldError(..)+ , readFile+ , writeFile+ ) where++import Prelude hiding (readFile, writeFile)++import Control.Exception (Exception, throwIO)+import Control.Monad.IO.Class (MonadIO(..))+import Data.Aeson qualified as Aeson+import Data.ByteString (ByteString)+import Data.ByteString qualified as ByteString+import Data.Text (Text)+import Data.Text qualified as Text++import Codec.Tiled.World (World)++newtype WorldError = WorldError Text+ deriving (Eq, Show)++instance Exception WorldError++readFile :: MonadIO m => FilePath -> m World+readFile source = liftIO do+ bytes <- ByteString.readFile source+ case decodeMap bytes of+ Left msg ->+ throwIO $ WorldError (Text.pack msg)+ Right res ->+ pure res++decodeMap :: ByteString -> Either String World+decodeMap = Aeson.eitherDecodeStrict'++writeFile :: MonadIO m => FilePath -> World -> m ()+writeFile destination = liftIO . Aeson.encodeFile destination
tests/Main.hs view
@@ -24,6 +24,8 @@ [ testCase "Embedded tileset" mapTestRoundtripEmbedded , testCase "External tileset" mapTestRoundtripExternal ]+ , testGroup "Custom properties"+ [ testCase "Property name" mapTestPropertyName ] ] mapTestRoundtripEmbedded :: IO ()@@ -43,6 +45,13 @@ Map.writeFile out embeddedZstd embeddedZstdOut <- Map.readFile out embeddedZstd @?= embeddedZstdOut++mapTestPropertyName :: IO ()+mapTestPropertyName = do+ testMap <- Map.readFile "maps/property-name.tmj"+ print testMap+ -- This will fail with “key "propertytype" not found” or+ -- similar if aeson is not able to parse it correctly. tilesetCodecTests :: TestTree tilesetCodecTests = testGroup "Tileset"