summaryrefslogtreecommitdiff
path: root/lib/CheckMap.hs
diff options
context:
space:
mode:
authorstuebinm2021-09-30 14:01:25 +0200
committerstuebinm2021-09-30 14:01:25 +0200
commite68d652323e454abf7e6c01ecedd919859cf9274 (patch)
treec64dc6b857b69d599b3b9e74923eca46301eb6ec /lib/CheckMap.hs
parentca8552c4eb69b2b8267fe0046320bccf9f547b52 (diff)
nicer json output which leaks less haskell names
Diffstat (limited to 'lib/CheckMap.hs')
-rw-r--r--lib/CheckMap.hs53
1 files changed, 32 insertions, 21 deletions
diff --git a/lib/CheckMap.hs b/lib/CheckMap.hs
index 176e3d5..49dcd2e 100644
--- a/lib/CheckMap.hs
+++ b/lib/CheckMap.hs
@@ -8,23 +8,26 @@
-- | Module that contains the high-level checking functions
module CheckMap (loadAndLintMap, MapResult(..)) where
-import Data.Aeson (ToJSON)
-import Data.Map (Map, fromList, toList)
-import Data.Maybe (mapMaybe)
-import Data.Text (Text)
-import qualified Data.Text as T
-import qualified Data.Vector as V
-import GHC.Generics (Generic)
+import Data.Aeson (ToJSON)
+import qualified Data.Aeson as A
+import Data.Map (Map, fromList, toList)
+import Data.Maybe (mapMaybe)
+import Data.Text (Text)
+import qualified Data.Text as T
+import qualified Data.Vector as V
+import GHC.Generics (Generic)
-import LintWriter (LintResult (..), LintWriter, askContext,
- filterLintLevel, lintToDep, resultToDeps,
- resultToLints, resultToOffers, runLintWriter)
-import Properties (checkLayerProperty, checkMap)
-import Tiled2 (Layer (layerName, layerProperties),
- Tiledmap (tiledmapLayers), loadTiledmap)
-import Types (Dep, Level (..), Lint (..), hint, lintLevel)
-import Util (PrettyPrint (prettyprint), prettyprint)
+import Data.Aeson.Types ((.=))
+import LintWriter (LintResult (..), LintWriter, askContext,
+ filterLintLevel, lintToDep, resultToDeps,
+ resultToLints, resultToOffers, runLintWriter)
+import Properties (checkLayerProperty, checkMap)
+import Tiled2 (Layer (layerName, layerProperties),
+ LoadResult (..), Tiledmap (tiledmapLayers),
+ loadTiledmap)
+import Types (Dep, Level (..), Lint (..), hint)
+import Util (PrettyPrint (prettyprint), prettyprint)
@@ -34,16 +37,23 @@ data MapResult = MapResult
, mapresultGeneral :: [Lint]
, mapresultDepends :: [Dep]
, mapresultProvides :: [Text]
- } deriving (Generic, ToJSON)
-
+ } deriving (Generic)
+instance ToJSON MapResult where
+ toJSON res = A.object
+ [ "layer" .= mapresultLayer res
+ , "general" .= mapresultGeneral res
+ -- TODO: not sure if these are necessary of even useful
+ , "depends" .= mapresultDepends res
+ , "provides" .= mapresultProvides res
+ ]
-- | this module's raison d'ĂȘtre
-- Lints the map at `path`, and limits local links to at most `depth`
-- layers upwards in the file hierarchy
-loadAndLintMap :: FilePath -> Int -> IO MapResult
+loadAndLintMap :: FilePath -> Int -> IO (Maybe MapResult)
loadAndLintMap path depth = loadTiledmap path >>= pure . \case
- Left err -> MapResult
+ DecodeErr err -> Just $ MapResult
{ mapresultLayer = Nothing
, mapresultDepends = []
, mapresultProvides = []
@@ -52,8 +62,9 @@ loadAndLintMap path depth = loadTiledmap path >>= pure . \case
path <> ": Fatal: " <> err
]
}
- Right waMap ->
- runLinter waMap depth
+ IOErr err -> Nothing
+ Loaded waMap ->
+ Just (runLinter waMap depth)
-- | lint a loaded map
runLinter :: Tiledmap -> Int -> MapResult