Skip to content

Commit 11bdc89

Browse files
authored
Merge pull request #58 from pythonarcade/development
Version 2.1.0
2 parents ba959de + fe75327 commit 11bdc89

File tree

147 files changed

+2149
-1122
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

147 files changed

+2149
-1122
lines changed

.readthedocs.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
version: 2
2+
3+
build:
4+
os: ubuntu-20.04
5+
tools:
6+
python: "3.10"
7+
8+
sphinx:
9+
configuration: docs/conf.py
10+
11+
formats:
12+
- pdf
13+
14+
python:
15+
install:
16+
- method: pip
17+
path: .
18+
extra_requirements:
19+
- docs

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

7+
## [2.1.0] - 2022-08-02
8+
9+
This is largely a compatibility update to work with the latest version of Tiled. This version represents the first version of pytiled-parser that is compatible with the formats from Tiled 1.9. Previous versions do not work with maps or tilesets of either JSON or TMX formats from Tiled 1.9 or higher, if you need to use Tiled 1.9+ with an older version of Tiled, you will need to use Tiled's ability to save the map in compatibility mode.
10+
11+
This update does introduce a slight API breaking change, but is unlikely to really cause any problems. The `type` attribute has been removed from the `TiledObject` class as well as the `Tile` class. It has been replaced with the `class_` attribute. This is in keeping with following Tiled's own API as closely as possible. There shouldn't really be any functional difference here, in most cases it has just been re-named. For more information on this change, you can reference the [Tiled JSON format changelog](https://doc.mapeditor.org/en/stable/reference/json-map-format/#changelog).
12+
13+
It is important to note, that this update does not add support for new features introduced in Tiled 1.9(and in fact, we are still missing support for some features from 1.8). This update is primarily to ensure that maps using the base feature set we have had support for will continue to work with the same supported featureset on Tiled 1.9. Support for the new features is something we would like to achieve, but we did not want to hold back general compatibility for it.
14+
15+
Outside of that, all other changes are to the internal parsers and do not effect usage/implementation of pytiled-parser.
16+
717
## [2.0.1] - 2021-12-21
818

919
Someone, not naming any names, forgot to put `__init__.py` files in some packages, and caused imports to break when installed via a `.whl` and not an editable source install. This just fixes that problem.

README.md

Lines changed: 65 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,74 @@
1-
# PyTiled Parser
1+
# pytiled-parser
22

3-
PyTiled Parser is a Python Library for parsing JSON formatted
4-
[Tiled Map Editor](https://www.mapeditor.org/) maps and tilesets to be used as maps and levels for 2D top-down (orthogonal, hexogonal, or isometric) or side-scrolling games in a strictly typed fashion.
3+
PyTiled Parser is a Python Library for parsing [Tiled Map Editor](https://www.mapeditor.org/) maps and tilesets to be used as maps and levels for 2D top-down (orthogonal, hexogonal, or isometric) or side-scrolling games in a strictly typed fashion.
54

6-
PyTiled Parser is not tied to any particular graphics library, and can be used
7-
with [Arcade](http://arcade.academy),
8-
[Pyglet](https://pyglet.readthedocs.io/en/pyglet-1.3-maintenance/),
9-
[Pygame](https://www.pygame.org/news), etc.
5+
PyTiled Parser is not tied to any particular graphics library or game engine. It parses map files and returns arbitrary Python types(like `Path` objects for image files rather than a `Sprite` from any particular engine). This means it can be used to aide in implementing Tiled support into a wide variety of tools.
106

11-
* Documentation available at: https://pytiled-parser.readthedocs.io/
12-
* GitHub project at: https://github.com/Beefy-Swain/pytiled_parser
13-
* PiPy: https://pypi.org/project/pytiled-parser/
7+
- Documentation available at: https://pytiled-parser.readthedocs.io/
8+
- GitHub project at: https://github.com/pythonarcade/pytiled_parser
9+
- PyPi: https://pypi.org/project/pytiled-parser/
1410

15-
The [Arcade](http://arcade.academy) library has
16-
[supporting code](http://arcade.academy/arcade.html#module-arcade.tilemap) to
17-
integrate PyTiled with that 2D libary, and
18-
[example code](http://arcade.academy/examples/index.html#tmx-files-tiled-map-editor) showing its use.
11+
The [Arcade](https://api.arcade.academy) library has
12+
[supporting code](https://api.arcade.academy/en/latest/api/tilemap.html) to
13+
integrate PyTiled Parser and [example code](https://api.arcade.academy/en/latest/examples/index.html#using-tiled-map-editor-to-create-maps) showing its use.
1914

20-
Original module by [Beefy-Swain](https://github.com/Beefy-Swain).
21-
Significant contributions from [pvcraven](https://github.com/pvcraven) and [Cleptomania](https://github.com/Cleptomania).
15+
## Installation
16+
17+
Simply install with pip:
18+
19+
```
20+
pip install pytiled-parser
21+
```
22+
23+
## Loading a Map
24+
25+
**NOTE:** All map paths should ideally be `Path` objects from Python's `pathlib` module. However a string will work in many cases.
26+
27+
```python
28+
from pathlib import Path
29+
30+
import pytiled_parser
31+
32+
map_file = Path("assets/maps/my_map.tmx")
33+
my_map = pytiled_parser.parse_map(map_file)
34+
```
35+
36+
In order to fully understand the pytiled-parser API, it is suggested that you have a solid understanding of the [Tiled Map Editor](https://doc.mapeditor.org/en/stable/), and it's [JSON format](https://doc.mapeditor.org/en/stable/reference/json-map-format/). An effort was made to keep the API that pytiled-parser provides as close as possible with the JSON format directly. Only small variations are made at certain points for ease of use with integrating to a game or engine.
37+
38+
## Working With Layers
39+
40+
Layers are loaded as an ordered list of `Layer` objects within the map. They can be accessed via the `layers` attribute of a map. There has been debate about wether or not these should be loaded in as a Dictionary, with the keys being the name of the layer. The decision was ultimately made to leave them as a list, as there is no guarantee, and beyond that is considered acceptable use to have duplicate layer names in Tiled.
41+
42+
Thus the decision to allow duplicate layer names is up to the implementation, as an example, [Arcade](https://arcade.academy) does not allow duplicate layer names, as it re-roganizes layers into dictionaries based on the name.
2243

2344
## Development
24-
To develop pytiled parser, clone the repo, create a `venv` using a supported Python version, and activate it. Then install the package as well as all testing dependencies with the command `python -m pip install -e ".[tests]"`.
45+
46+
To develop pytiled parser, clone the repo, create a `venv` using a supported Python version, and activate it. Then install the package as well as all testing, linting, and formatting dependencies with the command `python -m pip install -e ".[dev]"`.
47+
48+
### Linting and Formatting
49+
50+
flake8, mypy, black, and isort should all be used during development. These should ideally all pass before committing. Some work is under way to have a pre-commit hook for these or do checks in CI.
2551

2652
### Testing
27-
Run `pytest --cov=pytiled_parser` to run the test harness and report coverage.
53+
54+
Run `pytest --cov=pytiled_parser` to run the test harness and report coverage.
55+
56+
### Docs
57+
58+
Install Docs dependencies with the command `python -m pip install ".[docs]"`
59+
60+
To serve the docs locally:
61+
62+
```
63+
mkdocs serve
64+
```
65+
66+
They can then be accessed on http://localhost:8000
67+
68+
## Credits
69+
70+
Original module created by [Benjamin Kirkbride](https://github.com/benjamin-kirkbride).
71+
72+
Currently maintained by [Cleptomania](https://github.com/cleptomania)
73+
74+
Special thanks for contributions from [pvcraven](https://github.com/pvcraven) and the contributors that create Tiled, without which this library wouldn't exist.

docs/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
# from the environment for the first two.
66
SPHINXOPTS ?=
77
SPHINXBUILD ?= sphinx-build
8-
SOURCEDIR = source
9-
BUILDDIR = build
8+
SOURCEDIR = .
9+
BUILDDIR = _build
1010

1111
# Put it first so that "make" without argument is like "make help".
1212
help:

docs/api/common_types.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.. _common_types_api:
2+
Common Types
3+
============
4+
5+
This module provides some common types used throughout PyTiled Parser. These are all just NamedTuple
6+
classes provided to make sets of data more clear. As such they can be subscripted like a normal tuple
7+
to get the same values, or you can reference them by name. The values shown here are in the order they
8+
will be in the final tuple.
9+
10+
11+
Color
12+
^^^^^
13+
14+
.. autoclass:: pytiled_parser.common_types.Color
15+
16+
OrderedPair
17+
^^^^^^^^^^^
18+
19+
.. autoclass:: pytiled_parser.common_types.OrderedPair
20+
21+
Size
22+
^^^^
23+
24+
.. autoclass:: pytiled_parser.common_types.Size

docs/api/index.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.. _api:
2+
API Reference
3+
=============
4+
5+
This page documents the Application Programming Interface (API) for the PyTiled Parser library.
6+
7+
Throughout the API documentation you will see links labeled both TMX Reference and JSON Reference.
8+
These links go to the official Tiled documentation for that specific type. Sometimes there is not a
9+
one to one mapping, so it may lead to the closest thing in the Tiled format.
10+
11+
At some points certain classes modules may have links to other parts of the Tiled documentation which
12+
cover some of the concepts surrounding that module and it's usage within Tiled.
13+
14+
.. toctree::
15+
:maxdepth: 1
16+
:caption: PyTiled Parser
17+
18+
parser
19+
common_types
20+
properties
21+
tileset
22+
layer
23+
objects
24+
map
25+
wang_set
26+
world

docs/api/layer.rst

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
.. _layer_api:
2+
Layer
3+
=====
4+
5+
This module provides classes for all layer types
6+
7+
There is the base Layer class, which TileLayer, ObjectLayer, ImageLayer,
8+
and LayerGroup all derive from. The base Layer class is never directly used,
9+
and serves only as an abstract base for common elements between all types.
10+
11+
For more information about Layers, see `Tiled's Manual <https://doc.mapeditor.org/en/stable/manual/layers/>`_
12+
13+
14+
Layer
15+
^^^^^
16+
17+
.. autoclass:: pytiled_parser.layer.Layer
18+
:members:
19+
20+
TileLayer
21+
^^^^^^^^^
22+
23+
.. autoclass:: pytiled_parser.layer.TileLayer
24+
:members:
25+
26+
Chunk
27+
^^^^^
28+
29+
.. autoclass:: pytiled_parser.layer.Chunk
30+
:members:
31+
32+
ObjectLayer
33+
^^^^^^^^^^^
34+
35+
.. autoclass:: pytiled_parser.layer.ObjectLayer
36+
:members:
37+
38+
ImageLayer
39+
^^^^^^^^^^
40+
41+
.. autoclass:: pytiled_parser.layer.ImageLayer
42+
:members:
43+
44+
LayerGroup
45+
^^^^^^^^^^
46+
47+
.. autoclass:: pytiled_parser.layer.LayerGroup
48+
:members:

docs/api/map.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.. _map_api:
2+
Map
3+
===
4+
5+
This module provides the primary TiledMap class which represents a single map from Tiled.
6+
7+
TiledMap
8+
^^^^^^^^
9+
10+
.. autoclass:: pytiled_parser.tiled_map.TiledMap

docs/api/objects.rst

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
.. _objects_api:
2+
Objects
3+
=======
4+
5+
This module provides classes for all of the Tiled Object types.
6+
7+
There is the base TiledObject class, which all of the actual object types inherit from.
8+
The base TiledObject class is never directly used, and serves only as an abstract base
9+
for common elements between all types.
10+
11+
Some objects have no extra attributes over the base class, they exist as different classes anyways
12+
to denote the type of object, so that an implementation can load it in accordingly. For example, an
13+
Ellipse and a Point have no differing attributes from the base class, but obviously need to be handled
14+
very differently.
15+
16+
For more information about objects, see `Tiled's Manual <https://doc.mapeditor.org/en/stable/manual/objects/>`_
17+
18+
Also see the `TMX Reference <https://doc.mapeditor.org/en/stable/reference/tmx-map-format/#object>`_
19+
and `JSON Reference <https://doc.mapeditor.org/en/stable/reference/json-map-format/#object>`_
20+
21+
TiledObject
22+
^^^^^^^^^^^
23+
24+
.. autoclass:: pytiled_parser.tiled_object.TiledObject
25+
26+
Ellipse
27+
^^^^^^^
28+
29+
.. autoclass:: pytiled_parser.tiled_object.Ellipse
30+
31+
Point
32+
^^^^^
33+
34+
.. autoclass:: pytiled_parser.tiled_object.Point
35+
36+
Polygon
37+
^^^^^^^
38+
39+
.. autoclass:: pytiled_parser.tiled_object.Polygon
40+
41+
Polyline
42+
^^^^^^^^
43+
44+
.. autoclass:: pytiled_parser.tiled_object.Polyline
45+
46+
Rectangle
47+
^^^^^^^^^
48+
49+
.. autoclass:: pytiled_parser.tiled_object.Rectangle
50+
51+
Text
52+
^^^^
53+
54+
.. autoclass:: pytiled_parser.tiled_object.Text
55+
56+
Tile
57+
^^^^
58+
59+
.. autoclass:: pytiled_parser.tiled_object.Tile

docs/api/parser.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.. _parser_api:
2+
Parser
3+
======
4+
5+
This module exposes the actual parsing functions. If you are creating an implementation, this is
6+
what you will actually pass a file to and receive back a PyTiled Parser Map or World class depending
7+
on what you're parsing.
8+
9+
pytiled_parser.parse_map
10+
^^^^^^^^^^^^^^^^^^^^^^^^
11+
12+
.. autofunction:: pytiled_parser.parse_map
13+
14+
pytiled_parser.parse_world
15+
^^^^^^^^^^^^^^^^^^^^^^^^^^
16+
17+
.. autofunction:: pytiled_parser.parse_world

docs/api/properties.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
.. _properties_api:
2+
Properties
3+
==========
4+
5+
This module provides some common types used throughout PyTiled Parser. These are all just NamedTuple
6+
classes provided to make sets of data more clear. As such they can be subscripted like a normal tuple
7+
to get the same values, or you can reference them by name. The values shown here are in the order they
8+
will be in the final tuple.
9+
10+
Properties do not have a special class or anything associated with them. They are simply type aliases for
11+
built-in Python types.
12+
13+
pytiled_parser.Property
14+
^^^^^^^^^^^^^^^^^^^^^^^
15+
16+
The ``pytiled_parser.Property`` type is a Union of the `float`, `str`, and `bool` built-in types, as well as
17+
`Path` class from pathlib, and the `pytiled_parser.Color` common type.
18+
19+
A property may be any one of these types.
20+
21+
pytiled_parser.Properties
22+
^^^^^^^^^^^^^^^^^^^^^^^^^
23+
24+
The ``pytiled_parser.Properties`` type is a Dictionary mapping of `str` to `pytiled_parser.Property` objects.
25+
26+
When the map is parsed, all properties will be loaded in as a Property, and stored in a Properties dictionary
27+
with the name being it's key in the dictionary.

0 commit comments

Comments
 (0)