summaryrefslogtreecommitdiff
path: root/tiled/Data
diff options
context:
space:
mode:
authorstuebinm2022-03-06 16:28:05 +0100
committerstuebinm2022-03-19 20:00:02 +0100
commit5d8cbd7c9975ca1fb95fb332f7e27357cc18e982 (patch)
treee4a644a5fedf18fb418b58b8e1869416f2488298 /tiled/Data
parent11417fc194673decbfcb6e8b7e3da0af203feff1 (diff)
make tiled stricter (and organise some imports)
Diffstat (limited to 'tiled/Data')
-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