From bbe906ed445b77ad5dc0e1257ce652fe4a6e88cc 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 0b5b58a..6cd2893 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') 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) @@ -94,14 +93,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 @@ -203,7 +201,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