From 652c2030c5ef39bf1dd34d26064e1059431898f0 Mon Sep 17 00:00:00 2001 From: stuebinm Date: Tue, 9 Nov 2021 20:24:17 +0100 Subject: 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. --- lib/Tiled2.hs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'lib/Tiled2.hs') 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 -- cgit v1.2.3