summaryrefslogtreecommitdiff
path: root/lib/TiledAbstract.hs
diff options
context:
space:
mode:
authorstuebinm2021-12-29 02:00:55 +0100
committerstuebinm2021-12-29 02:00:55 +0100
commitbfe19c53c8540c298fa76650be03a189baa66fa5 (patch)
tree369fbebb5860d2139aab617ff35ede94f6c67b34 /lib/TiledAbstract.hs
parenta129ad47dd8d4202e3e64e9868e9eba4ff004fb2 (diff)
tiles can also have properties like tile layers
Diffstat (limited to 'lib/TiledAbstract.hs')
-rw-r--r--lib/TiledAbstract.hs22
1 files changed, 21 insertions, 1 deletions
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