tmx

package module
v0.0.0-...-5410bc1 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2023 License: GPL-3.0 Imports: 11 Imported by: 3

README

Introduction

This is the fork of Salviati's go-tmx library, with additional JSON mappings.

Contributing

You are welcome to contribute to project development.

If you looking for things to do, contact maintainer(ds@isangeles.dev).

When you find something to do, create a new branch for your feature. After you finish, open a pull request to merge your changes with master branch.

Contact

License

Copyright (C) 2023 Dariusz Sikora <ds@isangeles.dev>, Utkan Güngördü <utkan@freeconsole.org>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.

Documentation

Overview

A Go library that reads Tiled's TMX files.

Index

Constants

View Source
const (
	GIDHorizontalFlip = 0x80000000
	GIDVerticalFlip   = 0x40000000
	GIDDiagonalFlip   = 0x20000000
	GIDFlip           = GIDHorizontalFlip | GIDVerticalFlip | GIDDiagonalFlip
	GIDMask           = 0x0fffffff
)

Variables

View Source
var (
	UnknownEncoding       = errors.New("tmx: invalid encoding scheme")
	UnknownCompression    = errors.New("tmx: invalid compression method")
	InvalidDecodedDataLen = errors.New("tmx: invalid decoded data length")
	InvalidGID            = errors.New("tmx: invalid GID")
	InvalidPointsField    = errors.New("tmx: invalid points string")
)
View Source
var (
	NilTile = &DecodedTile{Nil: true}
)

Functions

This section is empty.

Types

type Data

type Data struct {
	Encoding    string     `xml:"encoding,attr" json:"encoding"`
	Compression string     `xml:"compression,attr" json:"compression"`
	RawData     []byte     `xml:",innerxml" json:"innerxml"`
	DataTiles   []DataTile `xml:"tile" json:"tile"` // Only used when layer encoding is xml
}

type DataTile

type DataTile struct {
	GID GID `xml:"gid,attr"`
}

type DecodedTile

type DecodedTile struct {
	ID             ID
	Tileset        *Tileset
	HorizontalFlip bool
	VerticalFlip   bool
	DiagonalFlip   bool
	Nil            bool
}

func (*DecodedTile) IsNil

func (t *DecodedTile) IsNil() bool

type GID

type GID uint32 // A tile ID. Could be used for GID or ID.

type ID

type ID uint32

type Image

type Image struct {
	Source string `xml:"source,attr" json:"source"`
	Trans  string `xml:"trans,attr" json:"trans"`
	Width  int    `xml:"width,attr" json:"width"`
	Height int    `xml:"height,attr" json:"height"`
}

type Layer

type Layer struct {
	Name         string         `xml:"name,attr" json:"name"`
	Opacity      float32        `xml:"opacity,attr" json:"opacity"`
	Visible      bool           `xml:"visible,attr" json:"visible"`
	Properties   []Property     `xml:"properties>property" json:"properties"`
	Data         Data           `xml:"data" json:"data"`
	DecodedTiles []*DecodedTile `xml:"-" json:"-"` // This is the attiribute you'd like to use, not Data. Tile entry at (x,y) is obtained using l.DecodedTiles[y*map.Width+x].
	Tileset      *Tileset       `xml:"-" json:"-"` // This is only set when the layer uses a single tileset and NilLayer is false.
	Empty        bool           `xml:"-" json:"-"` // Set when all entries of the layer are NilTile
}

type Map

type Map struct {
	Version      string        `xml:"title,attr" json:"title"`
	Orientation  string        `xml:"orientation,attr" json:"orientation"`
	Width        int           `xml:"width,attr" json:"width"`
	Height       int           `xml:"height,attr" json:"height"`
	TileWidth    int           `xml:"tilewidth,attr" json:"tilewidth"`
	TileHeight   int           `xml:"tileheight,attr" json:"tileheight"`
	Properties   []Property    `xml:"properties>property" json:"properties"`
	Tilesets     []Tileset     `xml:"tileset" json:"tilesets"`
	Layers       []Layer       `xml:"layer" json:"layers"`
	ObjectGroups []ObjectGroup `xml:"objectgroup" json:"objectgroup"`
}

All structs have their fields exported, and you'll be on the safe side as long as treat them read-only (anyone want to write 100 getters?).

func Read

func Read(r io.Reader) (*Map, error)

func ReadFile

func ReadFile(filePath string) (*Map, error)

func (*Map) DecodeGID

func (m *Map) DecodeGID(gid GID) (*DecodedTile, error)

type Object

type Object struct {
	Name       string     `xml:"name,attr" json:"name"`
	Type       string     `xml:"type,attr" json:"type"`
	X          float64    `xml:"x,attr" json:"x"`
	Y          float64    `xml:"y,attr" json:"y"`
	Width      float64    `xml:"width,attr" json:"width"`
	Height     float64    `xml:"height,attr" json:"height"`
	GID        int        `xml:"gid,attr" json"gid"`
	Visible    bool       `xml:"visible,attr" json:"visible"`
	Polygons   []Polygon  `xml:"polygon" json:"polygon"`
	PolyLines  []PolyLine `xml:"polyline" json:"polyline"`
	Properties []Property `xml:"properties>property" json:"properties"`
}

type ObjectGroup

type ObjectGroup struct {
	Name       string     `xml:"name,attr" json:"name"`
	Color      string     `xml:"color,attr" json:"color"`
	Opacity    float32    `xml:"opacity,attr" json:"opacity"`
	Visible    bool       `xml:"visible,attr" json:"visible"`
	Properties []Property `xml:"properties>property" json:"properties"`
	Objects    []Object   `xml:"object" json:"object"`
}

type Point

type Point struct {
	X int
	Y int
}

type PolyLine

type PolyLine struct {
	Points string `xml:"points,attr" json:"points"`
}

func (*PolyLine) Decode

func (p *PolyLine) Decode() ([]Point, error)

type Polygon

type Polygon struct {
	Points string `xml:"points,attr" json:"points"`
}

func (*Polygon) Decode

func (p *Polygon) Decode() ([]Point, error)

type Property

type Property struct {
	Name  string `xml:"name,attr" json:"name"`
	Value string `xml:"value,attr" json:"value"`
}

type Tile

type Tile struct {
	ID    ID    `xml:"id,attr" json:"id"`
	Image Image `xml:"image" json:"image"`
}

type Tileset

type Tileset struct {
	FirstGID   GID        `xml:"firstgid,attr" json:"firstgid"`
	Source     string     `xml:"source,attr" json:"source"`
	Name       string     `xml:"name,attr" json:"name"`
	TileWidth  int        `xml:"tilewidth,attr" json:"tilewidth"`
	TileHeight int        `xml:"tileheight,attr" json:"tileheight"`
	Spacing    int        `xml:"spacing,attr" json:"spacing"`
	Margin     int        `xml:"margin,attr" json:"margin"`
	Properties []Property `xml:"properties>property" json:"properties"`
	Image      Image      `xml:"image" json:"image"`
	Tiles      []Tile     `xml:"tile" json:"tile"`
	Tilecount  int        `xml:"tilecount,attr" json:"tilecount"`
	Columns    int        `xml:"columns,attr" json:"colums"`
}

Directories

Path Synopsis
example
tmx2console
Converts a TMX file to files which can be loaded to GBA.
Converts a TMX file to files which can be loaded to GBA.

Jump to

Keyboard shortcuts

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