From 2bcb1caeeabffcdd15591565a43303fc19b54cc9 Mon Sep 17 00:00:00 2001 From: Benjamin Kirkbride Date: Thu, 20 Aug 2020 18:25:17 -0400 Subject: [PATCH 1/8] docs(README): update readme --- README.md | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f28d626..74e3a0a 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,7 @@ # PyTiled Parser -PyTiled Parser is a Python Library for parsing -[Tiled Map Editor](https://www.mapeditor.org/) (`.tmx`) files used to generate -maps and levels for 2D top-down or side-scrolling games. +PyTiled Parser is a Python Library for parsing JSON formatted +[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. PyTiled Parser is not tied to any particular graphics library, and can be used with [Arcade](http://arcade.academy), @@ -10,7 +9,7 @@ with [Arcade](http://arcade.academy), [Pygame](https://www.pygame.org/news), etc. * Documentation available at: https://pytiled-parser.readthedocs.io/ -* GitHub project at: https://github.com/pvcraven/pytiled_parser +* GitHub project at: https://github.com/Beefy-Swain/pytiled_parser * PiPy: https://pypi.org/project/pytiled-parser/ The [Arcade](http://arcade.academy) library has @@ -19,4 +18,10 @@ integrate PyTiled with that 2D libary, and [example code](http://arcade.academy/examples/index.html#tmx-files-tiled-map-editor) showing its use. Original module by [Beefy-Swain](https://github.com/Beefy-Swain). -Contributions from [pvcraven](https://github.com/pvcraven). +Significant contributions from [pvcraven](https://github.com/pvcraven) and [Cleptomania](https://github.com/Cleptomania). + +## Developement +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]"`. + +### Testing +Run `pytest --cov=pytiled_parser` to run the test harness and report coverage. From 2cfe2e9a467f727f536e286f3d7a63d429a61a0f Mon Sep 17 00:00:00 2001 From: Benjamin Kirkbride Date: Thu, 20 Aug 2020 18:29:36 -0400 Subject: [PATCH 2/8] chore: switch to using module-define version number https://stackoverflow.com/a/16084844/1342874 --- pytiled_parser/version.py | 3 +++ setup.cfg | 1 - setup.py | 4 +++- 3 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 pytiled_parser/version.py diff --git a/pytiled_parser/version.py b/pytiled_parser/version.py new file mode 100644 index 0000000..6f9d281 --- /dev/null +++ b/pytiled_parser/version.py @@ -0,0 +1,3 @@ +"""pytiled_parser version""" + +__version__ = "1.0.0" diff --git a/setup.cfg b/setup.cfg index 6c87d5f..878d5e9 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,7 +1,6 @@ [metadata] name = pytiled_parser description = PongWall Server Prototype -version = 0.9.1 author = Benjamin Kirkbride author-email = BenjaminKirkbride@gmail.com license = MIT diff --git a/setup.py b/setup.py index 0496ea4..4414b8b 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,6 @@ # pylint: disable-all +# type: ignore from setuptools import setup -setup() +exec(open("yourpackage/version.py").read()) +setup(version=__version__) From d101783f283364715c98d4e8d64fed02eb2b346c Mon Sep 17 00:00:00 2001 From: Benjamin Kirkbride Date: Thu, 20 Aug 2020 18:29:59 -0400 Subject: [PATCH 3/8] chore(setup.cfg): update --- setup.cfg | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/setup.cfg b/setup.cfg index 878d5e9..89a2ebb 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,8 +1,6 @@ [metadata] name = pytiled_parser -description = PongWall Server Prototype -author = Benjamin Kirkbride -author-email = BenjaminKirkbride@gmail.com +description = A library for parsing JSON formatted Tiled Map Editor maps and tilesets. license = MIT license-file = LICENSE url = https://github.com/Beefy-Swain/pytiled_parser From c95b2bd8d3c1ee0b6252aad12a9479f9cfd809e6 Mon Sep 17 00:00:00 2001 From: Benjamin Kirkbride Date: Thu, 20 Aug 2020 18:32:25 -0400 Subject: [PATCH 4/8] docs(pytiled_parser): update description --- README.md | 2 +- pytiled_parser/__init__.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 74e3a0a..9f459c2 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # PyTiled Parser PyTiled Parser is a Python Library for parsing JSON formatted -[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. +[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. PyTiled Parser is not tied to any particular graphics library, and can be used with [Arcade](http://arcade.academy), diff --git a/pytiled_parser/__init__.py b/pytiled_parser/__init__.py index 3ce0b53..3620319 100644 --- a/pytiled_parser/__init__.py +++ b/pytiled_parser/__init__.py @@ -1,4 +1,13 @@ -"""Parse Tiled Maps and Tilesets""" +"""Parse Tiled Maps and Tilesets + +See: https://www.mapeditor.org/ + +This library is for parsing JSON formatted Tiled Map Editormaps 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. + +PyTiled Parser is not tied to any particular graphics library or game engine. +""" # pylint: disable=too-few-public-methods @@ -7,3 +16,4 @@ from .layer import Layer from .properties import Properties from .tiled_map import Map from .tileset import Tileset +from .version import __version__ From 2b5799fa8e1e6437744ec3ba129cadf02c874dd8 Mon Sep 17 00:00:00 2001 From: Benjamin Kirkbride Date: Thu, 20 Aug 2020 18:33:05 -0400 Subject: [PATCH 5/8] docs(common_types): removed redundant "multiple" --- pytiled_parser/common_types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytiled_parser/common_types.py b/pytiled_parser/common_types.py index 924685b..c560bdb 100644 --- a/pytiled_parser/common_types.py +++ b/pytiled_parser/common_types.py @@ -1,4 +1,4 @@ -"""Module containing types that are common to multiple other modules.""" +"""Module containing types that are common to other modules.""" # pylint: disable=too-few-public-methods From 0de74fc9eb78714ee5f1f66dd1ab5dfa9836faeb Mon Sep 17 00:00:00 2001 From: Benjamin Kirkbride Date: Thu, 20 Aug 2020 18:33:57 -0400 Subject: [PATCH 6/8] docs(common_types.size): clarify unit --- pytiled_parser/common_types.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pytiled_parser/common_types.py b/pytiled_parser/common_types.py index c560bdb..c26c5a1 100644 --- a/pytiled_parser/common_types.py +++ b/pytiled_parser/common_types.py @@ -18,8 +18,8 @@ class Size(NamedTuple): """Size NamedTuple. Attributes: - width: The width of the object. - height: The height of the object. + width: The width of the object in pixels. + height: The height of the object in pixels. """ width: float From c98f16dcefeb281f8f9be05d9ef36b46c3b3a2c5 Mon Sep 17 00:00:00 2001 From: Benjamin Kirkbride Date: Thu, 20 Aug 2020 18:56:26 -0400 Subject: [PATCH 7/8] docs(layer): add module docstring --- pytiled_parser/layer.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pytiled_parser/layer.py b/pytiled_parser/layer.py index fcf057e..16eaf4d 100644 --- a/pytiled_parser/layer.py +++ b/pytiled_parser/layer.py @@ -1,3 +1,11 @@ +"""This module handles parsing all types of layers. + +See: + - https://doc.mapeditor.org/en/stable/reference/json-map-format/#layer + - https://doc.mapeditor.org/en/stable/manual/layers/ + - https://doc.mapeditor.org/en/stable/manual/editing-tile-layers/ +""" + # pylint: disable=too-few-public-methods import base64 From d6bdf7b68462b53c97604e1e7003c52355c02626 Mon Sep 17 00:00:00 2001 From: Benjamin Kirkbride Date: Thu, 20 Aug 2020 19:32:53 -0400 Subject: [PATCH 8/8] docs(layer): update docstrings --- pytiled_parser/layer.py | 83 ++++++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 35 deletions(-) diff --git a/pytiled_parser/layer.py b/pytiled_parser/layer.py index 16eaf4d..aca7377 100644 --- a/pytiled_parser/layer.py +++ b/pytiled_parser/layer.py @@ -25,25 +25,21 @@ from .common_types import Color, OrderedPair, Size @attr.s(auto_attribs=True, kw_only=True) class Layer: - # FIXME:this docstring appears to be innacurate """Class that all layers inherit from. - Args: - id: Unique ID of the layer. Each layer that added to a map gets a unique id. - Even if a layer is deleted, no layer ever gets the same ID. + See: https://doc.mapeditor.org/en/stable/reference/json-map-format/#layer + + Attributes: name: The name of the layer object. - tiled_objects: List of tiled_objects in the layer. - offset: Rendering offset of the layer object in pixels. opacity: Decimal value between 0 and 1 to determine opacity. 1 is completely opaque, 0 is completely transparent. + visible: If the layer is visible in the Tiled Editor. (Do not use for games) + coordinates: Where layer content starts in tiles. (For infinite maps) + id: Unique ID of the layer. Each layer that added to a map gets a unique id. + Even if a layer is deleted, no layer ever gets the same ID. + size: Ordered pair of size of map in tiles. + offset: Rendering offset of the layer object in pixels. properties: Properties for the layer. - color: The color used to display the objects in this group. - draworder: Whether the objects are drawn according to the order of the object - elements in the object group element ('manual'), or sorted by their - y-coordinate ('topdown'). Defaults to 'topdown'. - See: - https://doc.mapeditor.org/en/stable/manual/objects/#changing-stacking-order - for more info. """ name: str @@ -65,7 +61,7 @@ TileLayerGrid = List[List[int]] class Chunk: """Chunk object for infinite maps. - See: https://doc.mapeditor.org/en/stable/reference/tmx-map-format/#chunk + See: https://doc.mapeditor.org/en/stable/reference/json-map-format/#chunk Attributes: coordinates: Location of chunk in tiles. @@ -78,26 +74,26 @@ class Chunk: data: List[int] -LayerData = Union[TileLayerGrid, List[Chunk]] # The tile data for one layer. # # Either a 2 dimensional array of integers representing the global tile IDs # for a TileLayerGrid, or a list of chunks for an infinite map layer. +LayerData = Union[TileLayerGrid, List[Chunk]] @attr.s(auto_attribs=True, kw_only=True) class TileLayer(Layer): - # FIXME:this docstring appears to be innacurate """Tile map layer containing tiles. - See: https://doc.mapeditor.org/en/stable/reference/json-map-format/#layer + See: + https://doc.mapeditor.org/en/stable/reference/json-map-format/#tile-layer-example - Args: - size: The width of the layer in tiles. The same as the map width unless map is - infitite. + Attributes: + chunks: list of chunks (infinite maps) data: Either an 2 dimensional array of integers representing the global tile IDs for the map layer, or a list of chunks for an infinite map. """ + chunks: Optional[List[Chunk]] = None data: Optional[List[int]] = None @@ -108,11 +104,12 @@ class ObjectLayer(Layer): The object group is in fact a map layer, and is hence called "object layer" in Tiled. - See: https://doc.mapeditor.org/en/stable/reference/tmx-map-format/#objectgroup - Args: + + See: + https://doc.mapeditor.org/en/stable/reference/json-map-format/#object-layer-example + + Attributes: tiled_objects: List of tiled_objects in the layer. - offset: Rendering offset of the layer object in pixels. - color: The color used to display the objects in this group. FIXME: editor only? draworder: Whether the objects are drawn according to the order of the object elements in the object group element ('manual'), or sorted by their y-coordinate ('topdown'). Defaults to 'topdown'. See: @@ -142,20 +139,26 @@ class ImageLayer(Layer): @attr.s(auto_attribs=True, kw_only=True) class LayerGroup(Layer): - """Layer Group. - A LayerGroup can be thought of as a layer that contains layers - (potentially including other LayerGroups). + """A layer that contains layers (potentially including other LayerGroups). + Offset and opacity recursively affect child layers. - See: https://doc.mapeditor.org/en/stable/reference/tmx-map-format/#group + + See: + - https://doc.mapeditor.org/en/stable/reference/json-map-format/#layer + - https://doc.mapeditor.org/en/stable/manual/layers/#group-layers + Attributes: - Layers: Layers in group. + Layers: list of layers contained in the group. """ layers: Optional[List[Layer]] class RawChunk(TypedDict): - """ The keys and their types that appear in a Chunk JSON Object.""" + """ The keys and their types that appear in a Chunk JSON Object. + + See: https://doc.mapeditor.org/en/stable/reference/json-map-format/#chunk + """ data: Union[List[int], str] height: int @@ -165,7 +168,10 @@ class RawChunk(TypedDict): class RawLayer(TypedDict): - """ The keys and their types that appear in a Layer JSON Object.""" + """ The keys and their types that appear in a Layer JSON Object. + + See: https://doc.mapeditor.org/en/stable/reference/json-map-format/#layer + """ chunks: List[RawChunk] compression: str @@ -193,7 +199,7 @@ class RawLayer(TypedDict): def _decode_tile_layer_data(data: str, compression: str) -> List[int]: - """Decode Base64 Encoded Tile Data. Supports gzip and zlib compression. + """Decode Base64 Encoded tile data. Optionally supports gzip and zlib compression. Args: data: The base64 encoded data @@ -231,12 +237,14 @@ def _decode_tile_layer_data(data: str, compression: str) -> List[int]: def _cast_chunk( - raw_chunk: RawChunk, encoding: str = None, compression: str = None + raw_chunk: RawChunk, encoding: Optional[str] = None, compression: str = None ) -> Chunk: """ Cast the raw_chunk to a Chunk. Args: raw_chunk: RawChunk to be casted to a Chunk + encoding: Encoding type. ("base64" or None) + compression: Either zlib, gzip, or empty. If empty no decompression is done. Returns: Chunk: The Chunk created from the raw_chunk @@ -257,7 +265,10 @@ def _cast_chunk( def _get_common_attributes(raw_layer: RawLayer) -> Layer: - """ Create a Layer containing all the attributes common to all layers + """ Create a Layer containing all the attributes common to all layers. + + This is to create the stub Layer object that can then be used to create the actual + specific sub-classes of Layer. Args: raw_layer: Raw Tiled object get common attributes from @@ -404,7 +415,9 @@ def _get_caster(type_: str) -> Callable[[RawLayer], Layer]: def cast(raw_layer: RawLayer) -> Layer: - """ Cast the raw Tiled layer into a pytiled_parser type + """ Cast a raw Tiled layer into a pytiled_parser type. + + This function will determine the type of layer and cast accordingly. Args: raw_layer: Raw layer to be cast.