Skip to content

Commit

Permalink
Add "class" attribute to several elements. (#64)
Browse files Browse the repository at this point in the history
* Add "class" attribute to several elements.

In the TMX version 1.9
(https://doc.mapeditor.org/en/stable/reference/tmx-changelog/#tiled-1-9),
the "type" attribute for <tile> and <object> was renamed to "class".

Also, the "class" field was added to several elements, namely, <map>,
<tileset>, <layer>, <imagelayer>, <objectgroup>, <group>, <wangset>
and <wangcolor>.

This patch adds the "class" attribute to all of the elements that are
specified in version 1.9 and that are implemented by the go-tiled
library.

* Add deprecated comments to <object> and <tile>.
  • Loading branch information
jabolopes authored Aug 12, 2022
1 parent 025534c commit 94829bf
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions tmx_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type Group struct {
ID uint32 `xml:"id,attr"`
// The name of the group layer.
Name string `xml:"name,attr"`
// The class of the group layer (since 1.9, defaults to "").
Class string `xml:"class,attr"`
// Rendering offset of the image layer in pixels. Defaults to 0. (since 0.15)
OffsetX int `xml:"offsetx,attr"`
// Rendering offset of the image layer in pixels. Defaults to 0. (since 0.15)
Expand Down
2 changes: 2 additions & 0 deletions tmx_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type ImageLayer struct {
ID uint32 `xml:"id,attr"`
// The name of the image layer.
Name string `xml:"name,attr"`
// The class of the image layer (since 1.9, defaults to "").
Class string `xml:"class,attr"`
// Rendering offset of the image layer in pixels. Defaults to 0. (since 0.15)
OffsetX int `xml:"offsetx,attr"`
// Rendering offset of the image layer in pixels. Defaults to 0. (since 0.15)
Expand Down
2 changes: 2 additions & 0 deletions tmx_layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ type Layer struct {
ID uint32 `xml:"id,attr"`
// The name of the layer.
Name string `xml:"name,attr"`
// The class of this layer (since 1.9, defaults to "").
Class string `xml:"class,attr"`
// The opacity of the layer as a value from 0 to 1. Defaults to 1.
Opacity float32 `xml:"opacity,attr"`
// Whether the layer is shown (1) or hidden (0). Defaults to 1.
Expand Down
2 changes: 2 additions & 0 deletions tmx_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ type Map struct {
Version string `xml:"version,attr"`
// The Tiled version used to generate this file
TiledVersion string `xml:"tiledversion,attr"`
// The class of this map (since 1.9, defaults to "").
Class string `xml:"class,attr"`
// Map orientation. Tiled supports "orthogonal", "isometric", "staggered" (since 0.9) and "hexagonal" (since 0.11).
Orientation string `xml:"orientation,attr"`
// The order in which tiles on tile layers are rendered. Valid values are right-down (the default), right-up, left-down and left-up.
Expand Down
8 changes: 7 additions & 1 deletion tmx_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ type ObjectGroup struct {
ID uint32 `xml:"id,attr"`
// The name of the object group.
Name string `xml:"name,attr"`
// The class of the object group (since 1.9, defaults to "").
Class string `xml:"class,attr"`
// The color used to display the objects in this group.
Color *HexColor `xml:"color,attr"`
// The opacity of the layer as a value from 0 to 1. Defaults to 1.
Expand Down Expand Up @@ -97,8 +99,12 @@ type Object struct {
ID uint32 `xml:"id,attr"`
// The name of the object. An arbitrary string.
Name string `xml:"name,attr"`
// The type of the object. An arbitrary string.
// The type of the object. An arbitrary string. (until 1.8)
//
// Deprecated: replaced by Class since 1.9
Type string `xml:"type,attr"`
// The class of the object. An arbitrary string. (defaults to "", renamed from 'type' since 1.9)
Class string `xml:"class,attr"`
// The x coordinate of the object.
X float64 `xml:"x,attr"`
// The y coordinate of the object.
Expand Down
8 changes: 7 additions & 1 deletion tmx_tileset.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type Tileset struct {
SourceLoaded bool `xml:"-"`
// The name of this tileset.
Name string `xml:"name,attr"`
// The class of this tileset (since 1.9, defaults to "").
Class string `xml:"class,attr"`
// The (maximum) width of the tiles in this tileset.
TileWidth int `xml:"tilewidth,attr"`
// The (maximum) height of the tiles in this tileset.
Expand Down Expand Up @@ -76,8 +78,12 @@ type Terrain struct {
type TilesetTile struct {
// The local tile ID within its tileset.
ID uint32 `xml:"id,attr"`
// The type of the tile. Refers to an object type and is used by tile objects. (optional) (since 1.0)
// The type of the tile. Refers to an object type and is used by tile objects. (optional) (since 1.0, until 1.8)
//
// Deprecated: replaced by Class since 1.9
Type string `xml:"type,attr"`
// The type of the tile. Refers to an object type and is used by tile objects. (optional) (renamed from 'type' since 1.9)
Class string `xml:"class,attr"`
// Defines the terrain type of each corner of the tile, given as comma-separated indexes in the terrain types
// array in the order top-left, top-right, bottom-left, bottom-right.
// Leaving out a value means that corner has no terrain. (optional) (since 0.9)
Expand Down

0 comments on commit 94829bf

Please sign in to comment.