tmx

package
v0.0.0-...-768a320 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2014 License: MIT Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Data

type Data struct {
	Encoding    string  `xml:"encoding,attr"`
	Compression string  `xml:"compression,attr"`
	CharData    []byte  `xml:",chardata"`
	Tiles       []*Tile `xml:"tile" json:"-"`
}

func (*Data) Data

func (data *Data) Data() (ii []int64, err error)

type Image

type Image struct {
	XMLName xml.Name `xml:"image" json:"-"`

	ImageFormat      string `xml:"format,attr" json:"imageformat,omitempty"`     //format: Used for embedded images, in combination with a data child element. Valid values are file extensions like png, gif, jpg, bmp, etc. (since 0.9.0)
	Id               int    `xml:"id,attr" json:"-"`                             // id: Used by some versions of Tiled Java. Deprecated and unsupported by Tiled Qt.
	ImageSource      string `xml:"source,attr" json:"image,omitempty"`           // source: The reference to the tileset image file (Tiled supports most common image formats).
	TransparentColor string `xml:"trans,attr" json:"transparentcolor,omitempty"` // trans: Defines a specific color that is treated as transparent (example value: "#FF00FF" for magenta). Up until Tiled 0.10, this value is written out without a # but this is planned to change.
	Width            int    `xml:"width,attr" json:"imagewidth,omitempty"`       // width: The image width in pixels (optional, used for tile index correction when the image changes)
	Height           int    `xml:"height,attr" json:"imageheight,omitempty"`     // height: The image height in pixels (optional)

}

<image>

As of the current version of Tiled Qt, each tileset has a single image associated with it, which is cut into smaller tiles based on the attributes defined on the tileset element. Later versions may add support for adding multiple images to a single tileset, as is possible in Tiled Java.

Can contain: data (since 0.9.0)

type Layer

type Layer struct {
	XMLName xml.Name `json:"-"`

	Type string

	// <layer>
	Name    string  `xml:"name,attr"`    // name: The name of the layer.
	X       int64   `xml:"x,attr"`       // x: The x coordinate of the layer in tiles. Defaults to 0 and can no longer be changed in Tiled Qt.
	Y       int64   `xml:"y,attr"`       // y: The y coordinate of the layer in tiles. Defaults to 0 and can no longer be changed in Tiled Qt.
	Width   int64   `xml:"width,attr"`   // width: The width of the layer in tiles. Traditionally required, but as of Tiled Qt always the same as the map width.
	Height  int64   `xml:"height,attr"`  // height: The height of the layer in tiles. Traditionally required, but as of Tiled Qt always the same as the map height.
	Opacicy float64 `xml:"opacity,attr"` // opacity: The opacity of the layer as a value from 0 to 1. Defaults to 1.
	Visible bool    `xml:"visible,attr"` // visible: Whether the layer is shown (1) or hidden (0). Defaults to 1.

	Color string

	Properties Properties `xml:"properties>property"`

	Data    Data
	Objects []Object

	Image Image `xml:"image"`
}

<layer>, <objectgroup>, <imagelayer>

All <tileset> tags shall occur before the first <layer> tag so that parsers may rely on having the tilesets before needing to resolve tiles.

Can contain: properties, data

func (*Layer) ObjectsByPoint

func (layer *Layer) ObjectsByPoint(x, y float64) []*Object

XXX not return polyline TODO check rotation

func (*Layer) UnmarshalXML

func (layer *Layer) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error)

type Map

type Map struct {
	XMLName xml.Name `xml:"map"`

	Version     string `xml:"version,attr"`     // version: The TMX format version, generally 1.0.
	Orientation string `xml:"orientation,attr"` // orientation: Map orientation. Tiled supports "orthogonal", "isometric" and "staggered" (since 0.9) at the moment.
	Width       int    `xml:"width,attr"`       // width: The map width in tiles.
	Height      int    `xml:"height,attr"`      // height: The map height in tiles.
	TileWidth   int    `xml:"tilewidth,attr"`   // tilewidth: The width of a tile.
	TileHeight  int    `xml:"tileheight,attr"`  // tileheight: The height of a tile.
	// backgroundcolor: The background color of the map. (since 0.9, optional)
	BackgroundColor string `xml:"backgroundcolor,attr" json:"backgroundcolor,omitempty"`
	// renderorder: The order in which tiles on tile layers are rendered. Valid values are right-down (the default), right-up, left-down and left-up.
	// In all cases, the map is drawn row-by-row. (since 0.10, but only supported for orthogonal maps at the moment)
	RenderOrder string `xml:"renderorder,attr" json:"renderorder"`

	Properties Properties `xml:"properties>property" json:"properties,omitempty"`
	Tileset    []*Tileset `xml:"tileset" json:"tileset"`

	// layer, objectgroup, imagelayer
	Layers []Layer `xml:",any"`
}

<map>

The tilewidth and tileheight properties determine the general grid size of the map. The individual tiles may have different sizes. Larger tiles will extend at the top and right (anchored to the bottom left).

Can contain: properties, tileset, layer, objectgroup, imagelayer

func LoadTMX

func LoadTMX(fname string) (m Map, err error)

func (Map) LayerByName

func (m Map) LayerByName(name, t string) *Layer

func (Map) MarshalJSON

func (m Map) MarshalJSON() ([]byte, error)

func (*Map) Validation

func (m *Map) Validation() error

type Object

type Object struct {
	XMLName xml.Name `xml:"object" json:"-"`

	Name     string  `xml:"name,attr" json:"name"`                   // name: The name of the object. An arbitrary string.
	Type     string  `xml:"type,attr" json:"type,omitempty"`         // type: The type of the object. An arbitrary string.
	X        float64 `xml:"x,attr" json:"x"`                         // x: The x coordinate of the object in pixels.
	Y        float64 `xml:"y,attr" json:"y"`                         // y: The y coordinate of the object in pixels.
	Width    float64 `xml:"width,attr" json:"width,omitempty"`       // width: The width of the object in pixels (defaults to 0).
	Height   float64 `xml:"height,attr" json:"height,omitempty"`     // height: The height of the object in pixels (defaults to 0).
	Rotation float64 `xml:"rotation,attr" json:"rotation,omitempty"` // rotation: The rotation of the object in degrees clockwise (defaults to 0). (on git master)
	GID      int64   `xml:"gid,attr" json:"gid,omitempty"`           // gid: An reference to a tile (optional).
	Visible  bool    `xml:"visible,attr" json:"visible,omitempty"`   // TODO visible: Whether the object is shown (1) or hidden (0). Defaults to 1. (since 0.9.0)

	Properties Properties   `xml:"properties>property" json:"properties,omitempty"`
	Ellipse    bool         `json:"ellipse,omitempty"`
	Polyline   []geom.Coord `json:"polyline,omitempty"`
	Polygon    []geom.Coord `json:"polygon,omitempty"`
}

<object>

Can contain: properties, ellipse (since 0.9.0), polygon, polyline, image

func (*Object) UnmarshalXML

func (obj *Object) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error)

type Properties

type Properties []Property

func (Properties) MarshalJSON

func (list Properties) MarshalJSON() ([]byte, error)

type Property

type Property struct {
	XMLName xml.Name `xml:"property" json:"-"`

	Name  string `xml:"name,attr"`
	Value string `xml:"value,attr"`
}

type Terrain

type Terrain struct {
	XMLName xml.Name `xml:"terrain" json:"-"`

	Name       string     `xml:"name,attr" json:"name"` // name: The name of the terrain type.
	Tile       int        `xml:"tile,attr" json:"tile"` // tile: The local tile-id of the tile that represents the terrain visually.
	Properties Properties `xml:"properties>property" json:"properties,omitempty"`
}

<terrain>

Can contain: properties

type Tile

type Tile struct {
	XMLName xml.Name `xml:"tile" json:"-"`

	Id          int64   `xml:"id,attr" json:"-"`      // id: The local tile ID within its tileset.
	Terrain     string  `xml:"terrain,attr" json:"-"` // terrain: 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.0)
	TerrainJSON []int64 `xml:"-" json:"terrain,omitempty"`
	Probability float32 `xml:"probability,attr" json:"probability,omitempty"` //probability: A percentage indicating the probability that this tile is chosen when it competes with others while editing with the terrain tool. (optional) (since 0.9.0)

	Properties Properties `xml:"properties>property" json:"properties,omitempty"`
	IImage     Image      `xml:"image" json:"-"`
	Image      `xml:"-"`
}

<tile>

Can contain: properties, image (since 0.9.0)

type TileOffset

type TileOffset struct {
	XMLName xml.Name `xml:"tileoffset" json:"-"`

	X int `xml:"x,attr" json:"x"` // x: Horizontal offset in pixels
	Y int `xml:"y,attr" json:"y"` // y: Vertical offset in pixels (positive is down)
}

<tileoffset>

This element is used to specify an offset in pixels, to be applied when drawing a tile from the related tileset. When not present, no offset is applied.

type Tileset

type Tileset struct {
	XMLName xml.Name `xml:"tileset" json:"-"`

	FirstGID int `xml:"firstgid,attr" json:"firstgid"` // firstgid: The first global tile ID of this tileset (this global ID maps to the first tile in this tileset).
	// source: If this tileset is stored in an external TSX (Tile Set XML) file, this attribute refers to that file. That TSX file has the same structure as the attribute as described here.
	// (There is the firstgid attribute missing and this source attribute is also not there. These two attributes are kept in the TMX map, since they are map specific.)
	Source       string     `xml:"source,attr" json:"source,omitempty"`
	Name         string     `xml:"name,attr" json:"name"`             // name: The name of this tileset.
	TileWidth    int        `xml:"tilewidth,attr" json:"tilewidth"`   // tilewidth: The (maximum) width of the tiles in this tileset.
	TileHeight   int        `xml:"tileheight,attr" json:"tileheight"` // tileheight: The (maximum) height of the tiles in this tileset.
	Spacing      int        `xml:"spacing,attr" json:"spacing"`       // spacing: The spacing in pixels between the tiles in this tileset (applies to the tileset image).
	Margin       int        `xml:"margin,attr" json:"margin"`         // margin: The margin around the tiles in this tileset (applies to the tileset image).
	TileOffset   TileOffset `xml:"tileoffset" json:"tileoffset"`
	Properties   Properties `xml:"properties>property" json:"properties,omitempty"`
	IImage       Image      `xml:"image" json:"-"`
	Image        `xml:"-"`
	TerrainTypes []*Terrain       `xml:"terraintypes>terrain" json:"terrains,omitempty"`
	Tiles        []*Tile          `xml:"tile" json:"-"`
	TilesJSON    map[string]*Tile `xml:"-" json:"tiles"`
}

<tileset>

Can contain: tileoffset (since 0.8.0), properties (since 0.8.0), image, terraintypes (since 0.9.0), tile

func LoadTSX

func LoadTSX(fname string) (ts *Tileset, err error)

func (Tileset) MarshalJSON

func (set Tileset) MarshalJSON() ([]byte, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL