From bfe19c53c8540c298fa76650be03a189baa66fa5 Mon Sep 17 00:00:00 2001 From: stuebinm Date: Wed, 29 Dec 2021 02:00:55 +0100 Subject: tiles can also have properties like tile layers --- lib/TiledAbstract.hs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'lib/TiledAbstract.hs') diff --git a/lib/TiledAbstract.hs b/lib/TiledAbstract.hs index 6d58f46..0ccf26b 100644 --- a/lib/TiledAbstract.hs +++ b/lib/TiledAbstract.hs @@ -8,7 +8,9 @@ import Data.Text (Text) import qualified Data.Vector as V import Tiled (Layer (..), Object (..), Property (..), PropertyValue (..), Tile (..), Tiledmap (..), - Tileset (..)) + Tileset (..), mkTiledId, GlobalId) +import Data.Vector (Vector) +import Util (showText) class HasProperties a where getProperties :: a -> [Property] @@ -39,6 +41,14 @@ instance HasProperties Tiledmap where adjustProperties f tiledmap = tiledmap { tiledmapProperties = f (getProperties tiledmap) } +class HasData a where + getData :: a -> Maybe (Vector GlobalId) +instance HasData Layer where + getData = layerData +instance HasData Tile where + getData _ = Nothing + + class HasTypeName a where typeName :: Proxy a -> Text instance HasTypeName Layer where @@ -48,6 +58,7 @@ instance HasTypeName Tileset where instance HasTypeName Property where typeName _ = "property" + class HasName a where getName :: a -> Text instance HasName Layer where @@ -56,6 +67,9 @@ instance HasName Tileset where getName = tilesetName instance HasName Property where getName (Property n _) = n +instance HasName Tile where + getName tile = "[tile with global id " <> showText (tileId tile) <> "]" + class IsProperty a where asProperty :: a -> PropertyValue @@ -65,3 +79,9 @@ instance IsProperty PropertyValue where instance IsProperty Text where asProperty = StrProp {-# INLINE asProperty #-} + + +layerIsEmpty :: HasData a => a -> Bool +layerIsEmpty layer = case getData layer of + Nothing -> True + Just d -> all ((==) $ mkTiledId 0) d -- cgit v1.2.3