From 5d8cbd7c9975ca1fb95fb332f7e27357cc18e982 Mon Sep 17 00:00:00 2001 From: stuebinm Date: Sun, 6 Mar 2022 16:28:05 +0100 Subject: make tiled stricter (and organise some imports) --- tiled/Data/Tiled.hs | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'tiled') 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 -- cgit v1.2.3