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) --- lib/CheckMap.hs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'lib/CheckMap.hs') diff --git a/lib/CheckMap.hs b/lib/CheckMap.hs index 9dc3a4c..9e3027c 100644 --- a/lib/CheckMap.hs +++ b/lib/CheckMap.hs @@ -25,6 +25,9 @@ import qualified Data.Vector as V import Badges (Badge) +import Data.Tiled (Layer (layerLayers, layerName), + Tiledmap (tiledmapLayers, tiledmapTilesets), + loadTiledmap) import LintConfig (LintConfig (configAssemblyTag), LintConfig') import LintWriter (LintResult, invertLintResult, resultToAdjusted, resultToBadges, @@ -32,10 +35,6 @@ import LintWriter (LintResult, invertLintResult, runLintWriter) import Properties (checkLayer, checkMap, checkTileset) import System.FilePath (takeFileName) -import Data.Tiled (Layer (layerLayers, layerName), - LoadResult (..), - Tiledmap (tiledmapLayers, tiledmapTilesets), - loadTiledmap) import Types (Dep (MapLink), Hint (Hint, hintLevel, hintMsg), Level (..), lintsToHints) @@ -102,14 +101,13 @@ shrinkMapResult !res = res { mapresultAdjusted = () } -- Lints the map at `path`, and limits local links to at most `depth` -- layers upwards in the file hierarchy loadAndLintMap :: LintConfig' -> FilePath -> Int -> IO (Maybe (MapResult Full)) -loadAndLintMap config path depth = loadTiledmap path <&> (\case - DecodeErr err -> Just (MapResult mempty mempty mempty mempty Nothing mempty +loadAndLintMap config path depth = loadTiledmap path <&> \case + Left err -> Just (MapResult mempty mempty mempty mempty Nothing mempty [ Hint Fatal . toText $ path <> ": Fatal: " <> err ]) - IOErr _ -> Nothing - Loaded waMap -> - Just (runLinter (takeFileName path == "main.json") config waMap depth)) + Right waMap -> + Just (runLinter (takeFileName path == "main.json") config waMap depth) -- | lint a loaded map runLinter :: Bool -> LintConfig' -> Tiledmap -> Int -> MapResult Full @@ -212,7 +210,6 @@ instance PrettyPrint (Level, MapResult a) where prettyLints getter = fmap (\(h, cs) -> prettyprint h <> "\n (in " - -- foldl :: ((length of current line, acc) -> next ctxt -> list) -> ... <> snd (foldl (\(l,a) c -> case l of 0 -> (T.length c, c) _ | l < 70 -> (l+2+T.length c, a <> ", " <> c) -- cgit v1.2.3