summaryrefslogtreecommitdiff
path: root/lib/Properties.hs
diff options
context:
space:
mode:
authorstuebinm2021-12-08 00:56:31 +0100
committerstuebinm2021-12-08 00:56:31 +0100
commitec9552b1d6ab303d54a8bbb8c93418f32fa29654 (patch)
tree8c4f4d7e14ce14bc6c066739f5eda13e489e518a /lib/Properties.hs
parent17a55dc7a71727a360cc642e7c55e7f2cf82d58a (diff)
rudimentary linting for overlapping layers
Diffstat (limited to '')
-rw-r--r--lib/Properties.hs17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/Properties.hs b/lib/Properties.hs
index 2747998..5845a1b 100644
--- a/lib/Properties.hs
+++ b/lib/Properties.hs
@@ -25,8 +25,10 @@ import Badges (Badge (Badge),
parseToken)
import Data.Data (Proxy (Proxy))
import Data.Maybe (fromMaybe, isJust)
+import Data.Set (Set)
import qualified Data.Set as S
import GHC.TypeLits (KnownSymbol)
+import LayerData (Collision, layerOverlaps)
import LintConfig (LintConfig (..))
import LintWriter (LintWriter, adjust, askContext, askFileDepth,
complain, dependsOn, forbid, lintConfig,
@@ -71,6 +73,11 @@ checkMap = do
unlessHasProperty "mapCopyright"
$ complain "must give the map's copyright via the \"mapCopyright\" property."
+ -- TODO: this doesn't catch collisions with the default start layer!
+ whenLayerCollisions (\(Property name _) -> name == "exitUrl" || name == "startLayer")
+ $ \cols -> warn $ "collisions between entry and / or exit layers: " <> prettyprint cols
+
+
-- | Checks a single property of a map.
--
-- Doesn't really do all that much, but could in theory be expanded into a
@@ -378,6 +385,16 @@ containsProperty :: Foldable t => t Property -> Text -> Bool
containsProperty props name = any
(\(Property name' _) -> name' == name) props
+-- | should the layers fulfilling the given predicate collide, then perform andthen.
+whenLayerCollisions
+ :: (Property -> Bool)
+ -> (Set Collision -> LintWriter Tiledmap)
+ -> LintWriter Tiledmap
+whenLayerCollisions f andthen = do
+ tiledmap <- askContext
+ let collisions = layerOverlaps . V.filter (any f . getProperties) $ tiledmapLayers tiledmap
+ unless (null collisions)
+ $ andthen collisions
----- Functions with concrete lint messages -----