summaryrefslogtreecommitdiff
path: root/tiled/Data/Tiled.hs
diff options
context:
space:
mode:
authorstuebinm2022-03-06 16:28:05 +0100
committerstuebinm2022-03-06 16:28:05 +0100
commitbbe906ed445b77ad5dc0e1257ce652fe4a6e88cc (patch)
tree3d6347760f4f7d3c9ada6136845f01ee27412a4b /tiled/Data/Tiled.hs
parent2469cc9fc3ac44a77e1c1aea412d75468b6f3181 (diff)
make tiled stricter (and organise some imports)
Diffstat (limited to '')
-rw-r--r--tiled/Data/Tiled.hs18
1 files changed, 4 insertions, 14 deletions
diff --git a/tiled/Data/Tiled.hs b/tiled/Data/Tiled.hs
index 046a080..8a8036e 100644
--- a/tiled/Data/Tiled.hs
+++ b/tiled/Data/Tiled.hs
@@ -19,12 +19,9 @@ module Data.Tiled where
import Universum
--- TODO: what ever are these aeson imports
import Data.Aeson hiding (Object)
import qualified Data.Aeson as A
import Data.Aeson.Types (typeMismatch)
-import qualified Data.ByteString as BS
-import qualified Data.ByteString.Lazy as LB
import Data.Char (toLower)
@@ -382,15 +379,8 @@ instance FromJSON Tiledmap where
instance ToJSON Tiledmap where
toJSON = genericToJSON (aesonOptions 8)
-data LoadResult = Loaded Tiledmap | IOErr String | DecodeErr String
- deriving Show
-
-- | Load a Tiled map from the given 'FilePath'.
-loadTiledmap :: FilePath -> IO LoadResult
-loadTiledmap path = do
- res <- try (BS.readFile path)
- pure $ case res of
- Right file -> case eitherDecode . LB.fromStrict $ file of
- Left err -> DecodeErr err
- Right tiledmap -> Loaded tiledmap
- Left (err :: SomeException) -> IOErr $ show err
+loadTiledmap :: FilePath -> IO (Either String Tiledmap)
+loadTiledmap path = eitherDecodeFileStrict' path <&> \case
+ Left err -> Left err
+ Right tiledmap -> Right tiledmap