summaryrefslogtreecommitdiff
path: root/lib/Tiled2.hs
diff options
context:
space:
mode:
authorstuebinm2021-11-09 20:24:17 +0100
committerstuebinm2021-11-09 20:42:10 +0100
commit652c2030c5ef39bf1dd34d26064e1059431898f0 (patch)
tree7100fbdfabbfa0f237e05ae1d0d2e2debb380125 /lib/Tiled2.hs
parentd0dc669c495f5f9e3dae20481e0aae183f606519 (diff)
first example of a map adjustment
this also includes some more monad plumbing, and an option for the linter to actually write things out again. Some of the previous commit was reverted a bit since it turned out to be stupid, but overall it was suprisingly easy once I got around to it, so yay! i guess Also includes a fairly silly example of how to use it.
Diffstat (limited to '')
-rw-r--r--lib/Tiled2.hs11
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/Tiled2.hs b/lib/Tiled2.hs
index a82de2c..e281d00 100644
--- a/lib/Tiled2.hs
+++ b/lib/Tiled2.hs
@@ -24,9 +24,11 @@ import qualified Data.ByteString.Lazy as LB
import Data.Char (toLower)
import Data.Map (Map)
import Data.Maybe (fromMaybe)
+import Data.String (IsString (fromString))
import Data.Text (Text)
+import qualified Data.Text as T
import Data.Vector (Vector)
-import GHC.Exts (fromList, toList)
+import GHC.Exts (IsString, fromList, toList)
import GHC.Generics (Generic)
@@ -89,6 +91,8 @@ data PropertyValue = StrProp Text | BoolProp Bool
data Property = Property Text PropertyValue
deriving (Eq, Generic, Show)
+instance IsString PropertyValue where
+ fromString s = StrProp (T.pack s)
instance FromJSON Property where
parseJSON (A.Object o) = do
@@ -343,12 +347,17 @@ instance ToJSON Tiledmap where
class HasProperties a where
getProperties :: a -> [Property]
+ adjustProperties :: ([Property] -> Maybe [Property]) -> a -> a
instance HasProperties Layer where
getProperties = fromMaybe [] . layerProperties
+ adjustProperties f layer = layer
+ { layerProperties = f (getProperties layer) }
instance HasProperties Tileset where
getProperties = fromMaybe [] . tilesetProperties
+ adjustProperties f tileset = tileset
+ { tilesetProperties = f (getProperties tileset) }
class HasName a where
getName :: a -> Text