diff options
author | stuebinm | 2021-12-04 04:33:01 +0100 |
---|---|---|
committer | stuebinm | 2021-12-04 04:34:11 +0100 |
commit | 6cfdefc3438100ea829b1c86e790a0f2d56ec503 (patch) | |
tree | 04a190c2ddddcfa317bb5fda326f8e6fcaaa7eff /lib/Tiled.hs | |
parent | c61f8b2ac2ecf5ff96401e1a913d41a6d5a4a343 (diff) |
lots of code reorganising and some deduplication
it was kinda getting messy in places.
Also found some accidental isomorphisms between types, so these are now
only one type because the consequences were getting silly.
Diffstat (limited to '')
-rw-r--r-- | lib/Tiled.hs (renamed from lib/Tiled2.hs) | 51 |
1 files changed, 1 insertions, 50 deletions
diff --git a/lib/Tiled2.hs b/lib/Tiled.hs index 44f2db7..9df52d3 100644 --- a/lib/Tiled2.hs +++ b/lib/Tiled.hs @@ -13,7 +13,7 @@ -- cover some of the types and records that are available in the format. For -- those you should read the TMX documentation at -- http://doc.mapeditor.org/en/latest/reference/tmx-map-format/ -module Tiled2 where +module Tiled where import Control.Exception (try) import Control.Exception.Base (SomeException) @@ -24,8 +24,6 @@ import qualified Data.ByteString as BS import qualified Data.ByteString.Lazy as LB import Data.Char (toLower) import Data.Map (Map) -import Data.Maybe (fromMaybe) -import Data.Proxy (Proxy) import Data.String (IsString (fromString)) import Data.Text (Text) import qualified Data.Text as T @@ -377,53 +375,6 @@ instance FromJSON Tiledmap where instance ToJSON Tiledmap where toJSON = genericToJSON (aesonOptions 8) - -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) } - -instance HasProperties Tiledmap where - getProperties = fromMaybe [] . tiledmapProperties - adjustProperties f tiledmap = tiledmap - { tiledmapProperties = f (getProperties tiledmap) } - -class HasTypeName a where - typeName :: Proxy a -> Text -instance HasTypeName Layer where - typeName _ = "layer" -instance HasTypeName Tileset where - typeName _ = "tileset" -instance HasTypeName Property where - typeName _ = "property" - -class HasName a where - getName :: a -> Text -instance HasName Layer where - getName = layerName -instance HasName Tileset where - getName = tilesetName -instance HasName Property where - getName (Property n _) = n - -class IsProperty a where - asProperty :: a -> PropertyValue -instance IsProperty PropertyValue where - asProperty = id - {-# INLINE asProperty #-} -instance IsProperty Text where - asProperty = StrProp - {-# INLINE asProperty #-} - data LoadResult = Loaded Tiledmap | IOErr String | DecodeErr String -- | Load a Tiled map from the given 'FilePath'. |