diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Tiled2.hs | 81 |
1 files changed, 51 insertions, 30 deletions
diff --git a/lib/Tiled2.hs b/lib/Tiled2.hs index 3c881ec..2a9c5b5 100644 --- a/lib/Tiled2.hs +++ b/lib/Tiled2.hs @@ -35,6 +35,7 @@ aesonOptions :: Int -> Options aesonOptions l = defaultOptions { omitNothingFields = True , rejectUnknownFields = True + -- can't be bothered to do a nixer prefix strip , fieldLabelModifier = drop l . map toLower } @@ -49,6 +50,8 @@ mkTiledId i = GlobalId { unGlobalId = i } newtype LocalId = LocalId { unLocalId :: Int } deriving (Ord, Eq, Enum, Num, Generic, Show, FromJSON, ToJSON, FromJSONKey, ToJSONKey) +-- | TODO: type-check colours? +type Color = Text data XYPair a = XYPair a a @@ -149,31 +152,37 @@ instance ToJSON Object where toJSON = genericToJSON (aesonOptions 6) -data Layer = Layer { layerWidth :: Maybe Double +data Layer = Layer { layerWidth :: Maybe Double -- ^ Column count. Same as map width for fixed-size maps. - , layerHeight :: Maybe Double + , layerHeight :: Maybe Double -- ^ Row count. Same as map height for fixed-size maps. - , layerName :: Text + , layerName :: Text -- ^ Name assigned to this layer - , layerType :: String + , layerType :: String -- ^ “tilelayer”, “objectgroup”, or “imagelayer” - , layerVisible :: Bool + , layerVisible :: Bool -- ^ Whether layer is shown or hidden in editor - , layerX :: Double + , layerX :: Double -- ^ Horizontal layer offset in tiles. Always 0. - , layerY :: Double + , layerY :: Double -- ^ Vertical layer offset in tiles. Always 0. - , layerData :: Maybe (Vector GlobalId) + , layerData :: Maybe (Vector GlobalId) -- ^ Array of GIDs. tilelayer only. - , layerObjects :: Maybe (Vector Object) + , layerObjects :: Maybe (Vector Object) -- ^ Array of Objects. objectgroup only. - , layerProperties :: Maybe [Property] + , layerProperties :: Maybe [Property] -- ^ string key-value pairs. - , layerOpacity :: Float + , layerOpacity :: Float -- ^ Value between 0 and 1 - , layerDraworder :: Maybe String + , layerDraworder :: Maybe String -- ^ “topdown” (default) or “index”. objectgroup only. - , layerId :: Int + , layerId :: Int + , layerOffsetx :: Maybe Int + , layerOffsety :: Maybe Int + , layerParallaxx :: Maybe Float + , layerParallaxy :: Maybe Float + , layerTintColor :: Maybe Color + , layerTransparentColor :: Maybe Color } deriving (Eq, Generic, Show) instance FromJSON Layer where @@ -230,39 +239,49 @@ instance ToJSON Tile where -data Tileset = Tileset { tilesetFirstgid :: GlobalId +data Tileset = Tileset { tilesetFirstgid :: GlobalId -- ^ GID corresponding to the first tile in the set - , tilesetImage :: Text + , tilesetImage :: Text -- ^ Image used for tiles in this set - , tilesetName :: Text + , tilesetName :: Text -- ^ Name given to this tileset - , tilesetTilewidth :: Int + , tilesetTilewidth :: Int -- ^ Maximum width of tiles in this set - , tilesetTileheight :: Int + , tilesetTileheight :: Int -- ^ Maximum height of tiles in this set - , tilesetImagewidth :: Int + , tilesetImagewidth :: Int -- ^ Width of source image in pixels - , tilesetImageheight :: Int + , tilesetImageheight :: Int -- ^ Height of source image in pixels - , tilesetProperties :: Maybe [Property] + , tilesetProperties :: Maybe [Property] -- ^ String key-value pairs - , tilesetPropertytypes :: Maybe (Map Text Text) + , tilesetPropertytypes :: Maybe (Map Text Text) -- ^ String key-value pairs - , tilesetMargin :: Int + , tilesetMargin :: Int -- ^ Buffer between image edge and first tile (pixels) - , tilesetSpacing :: Int + , tilesetSpacing :: Int -- ^ Spacing between adjacent tiles in image (pixels) - , tilesetTileproperties :: Maybe (Map GlobalId (Map Text Text)) + , tilesetTileproperties :: Maybe (Map GlobalId (Map Text Text)) -- ^ Per-tile properties, indexed by gid as string - , tilesetTerrains :: Maybe (Vector Terrain) + , tilesetTerrains :: Maybe (Vector Terrain) -- ^ Array of Terrains (optional) - , tilesetColumns :: Int + , tilesetColumns :: Int -- ^ The number of tile columns in the tileset - , tilesetTilecount :: Int + , tilesetTilecount :: Int -- ^ The number of tiles in this tileset - , tilesetTiles :: Maybe (Vector Tile) + , tilesetTiles :: Maybe (Vector Tile) -- ^ Tiles (optional) - , tilesetTransparentcolor :: Maybe String + , tilesetTransparentcolor :: Maybe Text + , tilesetEditorsettings :: Maybe Value + , tilesetBackgroundColor :: Maybe Text + , tilesetGrid :: Maybe Value + , tilesetSource :: Maybe Text + , tilesetTiledversion :: Maybe Text + , tilesetTileoffset :: Maybe Value + , tilesetTransformations :: Maybe Value + , tilesetVersion :: Maybe Value + , tilesetWangsets :: Maybe Value + , tilesetType :: Maybe Text } deriving (Eq, Generic, Show) newtype TransitiveTilesetMap = TransitiveTilesetMap (Map LocalId Value) @@ -306,8 +325,10 @@ data Tiledmap = Tiledmap { tiledmapVersion :: Float , tiledmapInfinite :: Bool , tiledmapNextlayerid :: Maybe Int , tiledmapHexsidelength :: Maybe Int + , tiledmapStaggeraxis :: Maybe Text , tiledmapStaggerindex :: Maybe String , tiledmapType :: String + , tiledmapEditorsettings :: Maybe Value } deriving (Eq, Generic, Show) instance FromJSON Tiledmap where |