From 8b96ea32accff561f4f2a33b604a9a2bbe0a9168 Mon Sep 17 00:00:00 2001
From: stuebinm <stuebinm@disroot.org>
Date: Mon, 27 Dec 2021 18:03:27 +0100
Subject: [PATCH] warn if main.json does not link back to lobby

---
 lib/CheckMap.hs | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/lib/CheckMap.hs b/lib/CheckMap.hs
index 8854b4c..2677a30 100644
--- a/lib/CheckMap.hs
+++ b/lib/CheckMap.hs
@@ -31,9 +31,10 @@ import           Tiled            (Layer (layerLayers, layerName),
                                    LoadResult (..),
                                    Tiledmap (tiledmapLayers, tiledmapTilesets),
                                    loadTiledmap)
-import           Types            (Dep, Hint (Hint, hintLevel, hintMsg),
+import           Types            (Dep (MapLink), Hint (Hint, hintLevel, hintMsg),
                                    Level (..), lintsToHints)
 import           Util             (PrettyPrint (prettyprint), prettyprint)
+import System.FilePath (takeFileName)
 
 
 
@@ -84,16 +85,18 @@ loadAndLintMap config path depth = loadTiledmap path <&> (\case
         ])
     IOErr _ -> Nothing
     Loaded waMap ->
-      Just (runLinter config waMap depth))
+      Just (runLinter (takeFileName path == "main.json") config waMap depth))
 
 -- | lint a loaded map
-runLinter :: LintConfig' -> Tiledmap -> Int -> MapResult
-runLinter config tiledmap depth = MapResult
+runLinter :: Bool -> LintConfig' -> Tiledmap -> Int -> MapResult
+runLinter isMain config tiledmap depth = MapResult
   { mapresultLayer = invertThing layer
   , mapresultTileset = invertThing tileset
-  , mapresultGeneral = lintsToHints $ resultToLints generalResult
+  , mapresultGeneral =
+    ([Hint Warning "main.json should link back to the lobby" | isMain && not (any linksLobby layerDeps)])
+    <> lintsToHints (resultToLints generalResult)
   , mapresultDepends = resultToDeps generalResult
-    <> concatMap resultToDeps layer
+    <> layerDeps
     <> concatMap resultToDeps tileset
   , mapresultProvides = concatMap resultToOffers layer
   , mapresultAdjusted = Just adjustedMap
@@ -101,6 +104,10 @@ runLinter config tiledmap depth = MapResult
     <> resultToBadges generalResult
   }
   where
+    linksLobby = \case
+      MapLink link -> "/@/rc3_21/lobby" `T.isPrefixOf` link
+      _ -> False
+    layerDeps = concatMap resultToDeps layer
     layer = checkLayerRec config depth (V.toList $ tiledmapLayers tiledmap)
     tileset = checkThing tiledmapTilesets checkTileset
     generalResult = runLintWriter config tiledmap depth checkMap
-- 
GitLab