summaryrefslogtreecommitdiff
path: root/lib/Tiled2.hs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lib/Tiled2.hs9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/Tiled2.hs b/lib/Tiled2.hs
index a729083..7e462cc 100644
--- a/lib/Tiled2.hs
+++ b/lib/Tiled2.hs
@@ -441,11 +441,14 @@ instance ToJSON Tiledmap where
, "nextobjectid" .= tiledmapNextobjectid
]
+data LoadResult = Loaded Tiledmap | IOErr String | DecodeErr String
-- | Load a Tiled map from the given 'FilePath'.
-loadTiledmap :: FilePath -> IO (Either String Tiledmap)
+loadTiledmap :: FilePath -> IO LoadResult
loadTiledmap path = do
res <- try (BS.readFile path)
pure $ case res of
- Right file -> mapLeft ("Json decode error or not a Tiled map: " <>) . eitherDecode . LB.fromStrict $ file
- Left (err :: SomeException) -> Left $ "IO Error: " <> show err
+ Right file -> case eitherDecode . LB.fromStrict $ file of
+ Left err -> DecodeErr err
+ Right map -> Loaded map
+ Left (err :: SomeException) -> IOErr $ show err