|
1 | | -# PyTiled Parser |
| 1 | +# pytiled-parser |
2 | 2 |
|
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. |
5 | 4 |
|
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. |
10 | 6 |
|
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/ |
14 | 10 |
|
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. |
19 | 14 |
|
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. |
22 | 43 |
|
23 | 44 | ## 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. |
25 | 51 |
|
26 | 52 | ### 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. |
0 commit comments