Skip to content

Commit 8748a87

Browse files
committed
Add empty values
1 parent ec10d12 commit 8748a87

File tree

8 files changed

+207
-18
lines changed

8 files changed

+207
-18
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Fix `firstgid` field name in embedded tilesets.
66
- Minimal `aeson` version is actually 2.0 (due to `KeyMap`).
7+
- `empty` values added for many «sparse» types.
78

89
## [0.0.2.0] - 2022-05-04
910

src/Codec/Tiled/Layer.hs

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
module Codec.Tiled.Layer where
1+
module Codec.Tiled.Layer
2+
( Layer(..)
3+
, empty
4+
5+
, pattern TILELAYER
6+
, pattern OBJECTGROUP
7+
, pattern IMAGELAYER
8+
, pattern GROUP
9+
) where
210

311
import Data.Text (Text)
412
import Data.Vector (Vector)
@@ -11,30 +19,30 @@ import Codec.Tiled.Object (Object)
1119
import Codec.Tiled.Property (Property)
1220

1321
data Layer = Layer
14-
{ chunks :: Maybe (Vector Chunk) -- ^ Array of chunks (optional). tilelayer only.
15-
, compression :: Maybe Text -- ^ @zlib@, @gzip@, @zstd@ or empty (default). tilelayer only.
16-
, data_ :: Maybe LayerData -- ^ Array of unsigned int (GIDs) or base64-encoded data. tilelayer only.
17-
, draworder :: Maybe Text -- ^ @topdown@ (default) or @index@. objectgroup only.
18-
, encoding :: Maybe Text -- ^ @csv@ (default) or @base64@. tilelayer only.
22+
{ chunks :: Maybe (Vector Chunk) -- ^ Array of chunks (optional). @tilelayer@ only.
23+
, compression :: Maybe Text -- ^ @zlib@, @gzip@, @zstd@ or empty (default). @tilelayer@ only.
24+
, data_ :: Maybe LayerData -- ^ Array of unsigned int (GIDs) or base64-encoded data. @tilelayer@ only.
25+
, draworder :: Maybe Text -- ^ @topdown@ (default) or @index@. @objectgroup@ only.
26+
, encoding :: Maybe Text -- ^ @csv@ (default) or @base64@. @tilelayer@ only.
1927
, height :: Maybe Int -- ^ Row count. Same as map height for fixed-size maps.
2028
, id :: Maybe Int -- ^ Incremental ID - unique across all layers
21-
, image :: Maybe FilePath -- ^ Image used by this layer. imagelayer only.
22-
, layers :: Maybe (Vector Layer) -- ^ Array of layers. group only.
29+
, image :: Maybe FilePath -- ^ Image used by this layer. @imagelayer@ only.
30+
, layers :: Maybe (Vector Layer) -- ^ Array of layers. @group@ only.
2331
, locked :: Maybe Bool -- ^ Whether layer is locked in the editor (default: false). (since Tiled 1.8.2)
2432
, name :: Text -- ^ Name assigned to this layer
25-
, objects :: Maybe (Vector Object) -- ^ Array of objects. objectgroup only.
33+
, objects :: Maybe (Vector Object) -- ^ Array of objects. @objectgroup@ only.
2634
, offsetX :: Maybe Double -- ^ Horizontal layer offset in pixels (default: 0)
2735
, offsetY :: Maybe Double -- ^ Vertical layer offset in pixels (default: 0)
2836
, opacity :: Double -- ^ Value between 0 and 1.
2937
, parallaxX :: Maybe Double -- ^ Horizontal parallax factor for this layer (default: 1).
3038
, parallaxY :: Maybe Double -- ^ Vertical parallax factor for this layer (default: 1).
3139
, properties :: Maybe (Vector Property) -- ^ Array of Properties
32-
, repeatX :: Maybe Bool -- ^ Whether the image drawn by this layer is repeated along the X axis. imagelayer only.
33-
, repeatY :: Maybe Bool -- ^ Whether the image drawn by this layer is repeated along the Y axis. imagelayer only.
40+
, repeatX :: Maybe Bool -- ^ Whether the image drawn by this layer is repeated along the X axis. @imagelayer@ only.
41+
, repeatY :: Maybe Bool -- ^ Whether the image drawn by this layer is repeated along the Y axis. @imagelayer@ only.
3442
, startX :: Maybe Int -- ^ X coordinate where layer content starts (for infinite maps)
3543
, startY :: Maybe Int -- ^ Y coordinate where layer content starts (for infinite maps)
3644
, tintColor :: Maybe Text -- ^ Hex-formatted tint color (#RRGGBB or #AARRGGBB) that is multiplied with any graphics drawn by this layer or any child layers (optional).
37-
, transparentColor :: Maybe Text -- ^ Hex-formatted color (#RRGGBB) (optional). imagelayer only.
45+
, transparentColor :: Maybe Text -- ^ Hex-formatted color (#RRGGBB) (optional). @imagelayer@ only.
3846
, type_ :: Text -- ^ @tilelayer@, @objectgroup@, @imagelayer@ or @group@
3947
, visible :: Bool -- ^ Whether layer is shown or hidden in editor
4048
, width :: Maybe Int -- ^ Column count. Same as map width for fixed-size maps.
@@ -48,3 +56,48 @@ instance FromJSON Layer where
4856

4957
instance ToJSON Layer where
5058
toJSON = genericToJSON
59+
60+
empty :: Layer
61+
empty = Layer
62+
{ chunks = Nothing
63+
, compression = Nothing
64+
, data_ = Nothing
65+
, draworder = Nothing
66+
, encoding = Nothing
67+
, height = Nothing
68+
, id = Nothing
69+
, image = Nothing
70+
, layers = Nothing
71+
, locked = Nothing
72+
, name = ""
73+
, objects = Nothing
74+
, offsetX = Nothing
75+
, offsetY = Nothing
76+
, opacity = 1.0
77+
, parallaxX = Nothing
78+
, parallaxY = Nothing
79+
, properties = Nothing
80+
, repeatX = Nothing
81+
, repeatY = Nothing
82+
, startX = Nothing
83+
, startY = Nothing
84+
, tintColor = Nothing
85+
, transparentColor = Nothing
86+
, type_ = ""
87+
, visible = True
88+
, width = Nothing
89+
, x = Nothing
90+
, y = Nothing
91+
}
92+
93+
pattern TILELAYER :: Text
94+
pattern TILELAYER = "tilelayer"
95+
96+
pattern OBJECTGROUP :: Text
97+
pattern OBJECTGROUP = "objectgroup"
98+
99+
pattern IMAGELAYER :: Text
100+
pattern IMAGELAYER = "imagelayer"
101+
102+
pattern GROUP :: Text
103+
pattern GROUP = "group"

src/Codec/Tiled/Map.hs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
module Codec.Tiled.Map where
1+
module Codec.Tiled.Map
2+
( Map(..)
3+
, empty
4+
, pattern ORTHOGONAL
5+
, pattern ISOMETRIC
6+
, pattern STAGGERED
7+
, pattern HEXAGONAL
8+
) where
29

310
import Codec.Tiled.Aeson (FromJSON(..), ToJSON(..), genericParseJSON, genericToJSON)
411
import Data.Text (Text)
@@ -40,3 +47,41 @@ instance FromJSON Map where
4047

4148
instance ToJSON Map where
4249
toJSON = genericToJSON
50+
51+
empty :: Map
52+
empty = Map
53+
{ backgroundColor = Nothing
54+
, compressionLevel = Nothing
55+
, height = 0
56+
, hexSideLength = Nothing
57+
, infinite = Nothing
58+
, layers = mempty
59+
, nextLayerId = 0
60+
, nextObjectId = 0
61+
, orientation = ""
62+
, parallaxOriginX = Nothing
63+
, parallaxOriginY = Nothing
64+
, properties = Nothing
65+
, renderOrder = Nothing
66+
, staggerAxis = Nothing
67+
, staggerIndex = Nothing
68+
, tiledVersion = ""
69+
, tileHeight = 0
70+
, tilesets = mempty
71+
, tileWidth = 0
72+
, type_ = "map"
73+
, version = ""
74+
, width = 0
75+
}
76+
77+
pattern ORTHOGONAL :: Text
78+
pattern ORTHOGONAL = "orthogonal"
79+
80+
pattern ISOMETRIC :: Text
81+
pattern ISOMETRIC = "isometric"
82+
83+
pattern STAGGERED :: Text
84+
pattern STAGGERED = "staggered"
85+
86+
pattern HEXAGONAL :: Text
87+
pattern HEXAGONAL = "hexagonal"

src/Codec/Tiled/Object/Text.hs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
module Codec.Tiled.Object.Text where
1+
module Codec.Tiled.Object.Text
2+
( Text(..)
3+
, empty
4+
) where
25

36
import Data.Text qualified as The
47
import GHC.Generics (Generic)
@@ -26,3 +29,19 @@ instance FromJSON Text where
2629

2730
instance ToJSON Text where
2831
toJSON = genericToJSON
32+
33+
empty :: Text
34+
empty = Text
35+
{ bold = Nothing
36+
, color = Nothing
37+
, fontFamily = Nothing
38+
, hAlign = Nothing
39+
, italic = Nothing
40+
, kerning = Nothing
41+
, pixelSize = Nothing
42+
, strikeout = Nothing
43+
, text = ""
44+
, underline = Nothing
45+
, vAlign = Nothing
46+
, wrap = Nothing
47+
}

src/Codec/Tiled/Tileset.hs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
module Codec.Tiled.Tileset where
1+
module Codec.Tiled.Tileset
2+
( Tileset(..)
3+
, empty
4+
) where
25

36
import Data.Text (Text)
47
import Data.Vector (Vector)
@@ -48,3 +51,32 @@ instance FromJSON Tileset where
4851

4952
instance ToJSON Tileset where
5053
toJSON = genericToJSON
54+
55+
empty :: Tileset
56+
empty = Tileset
57+
{ backgroundColor = Nothing
58+
, columns = 0
59+
, firstGid = Nothing
60+
, grid = Nothing
61+
, image = ""
62+
, imageHeight = 0
63+
, imageWidth = 0
64+
, margin = 0
65+
, name = ""
66+
, objectAlignment = Nothing
67+
, properties = Nothing
68+
, source = Nothing
69+
, spacing = 0
70+
, terrains = Nothing
71+
, tileCount = 0
72+
, tiledVersion = Nothing
73+
, tileHeight = 0
74+
, tileOffset = Nothing
75+
, tiles = Nothing
76+
, tileWidth = 0
77+
, transformations = Nothing
78+
, transparentColor = Nothing
79+
, type_ = Nothing
80+
, version = Nothing
81+
, wangSets = Nothing
82+
}

src/Codec/Tiled/Tileset/Tile.hs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
module Codec.Tiled.Tileset.Tile where
1+
module Codec.Tiled.Tileset.Tile
2+
( Tile(..)
3+
, empty
4+
) where
25

36
import Data.Text (Text)
47
import Data.Vector (Vector)
@@ -28,3 +31,17 @@ instance FromJSON Tile where
2831

2932
instance ToJSON Tile where
3033
toJSON = genericToJSON
34+
35+
empty :: Tile
36+
empty = Tile
37+
{ animation = Nothing
38+
, id = 0
39+
, image = Nothing
40+
, imageHeight = 0
41+
, imageWidth = 0
42+
, objectGroup = Nothing
43+
, probability = Nothing
44+
, properties = Nothing
45+
, terrain = Nothing
46+
, type_ = Nothing
47+
}

src/Codec/Tiled/Tileset/Transformations.hs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
module Codec.Tiled.Tileset.Transformations where
1+
module Codec.Tiled.Tileset.Transformations
2+
( Transformations(..)
3+
, empty
4+
) where
25

36
import GHC.Generics (Generic)
47

@@ -17,3 +20,11 @@ instance FromJSON Transformations where
1720

1821
instance ToJSON Transformations where
1922
toJSON = genericToJSON
23+
24+
empty :: Transformations
25+
empty = Transformations
26+
{ hFlip = Nothing
27+
, vFlip = Nothing
28+
, rotate = Nothing
29+
, preferUntransformed = Nothing
30+
}

src/Codec/Tiled/World.hs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
module Codec.Tiled.World where
1+
module Codec.Tiled.World
2+
( World(..)
3+
, empty
4+
) where
25

36
import Data.Aeson (FromJSON(..), ToJSON(..), genericParseJSON, genericToJSON)
47
import Data.Text (Text)
@@ -22,3 +25,11 @@ instance FromJSON World where
2225

2326
instance ToJSON World where
2427
toJSON = genericToJSON (mkOptions remapFields_)
28+
29+
empty :: World
30+
empty = World
31+
{ maps = Nothing
32+
, patterns = Nothing
33+
, type_ = Nothing
34+
, onlyShowAdjacentMaps = Nothing
35+
}

0 commit comments

Comments
 (0)