New docs structure

This commit is contained in:
Darren Eberly
2022-07-07 00:24:52 -04:00
parent 62202b300b
commit c7d5f35bd0
26 changed files with 362 additions and 144 deletions

View File

@@ -1,8 +1,14 @@
version: 2
mkdocs:
configuration: mkdocs.yml
fail_on_warning: true
build:
os: ubuntu-20.04
tools:
python: "3.10"
sphinx:
configuration: docs/conf.py
formats:
- pdf
python:
install:

20
docs/Makefile Normal file
View File

@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#
# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build
# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
.PHONY: help Makefile
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

24
docs/api/common_types.rst Normal file
View File

@@ -0,0 +1,24 @@
.. _common_types_api:
Common Types
============
This module provides some common types used throughout PyTiled Parser. These are all just NamedTuple
classes provided to make sets of data more clear. As such they can be subscripted like a normal tuple
to get the same values, or you can reference them by name. The values shown here are in the order they
will be in the final tuple.
pytiled_parser.Color
^^^^^^^^^^^^^^^^^^^^
.. autoclass:: pytiled_parser.Color
pytiled_parser.OrderedPair
^^^^^^^^^^^^^^^^^^^^^^^^^^
.. autoclass:: pytiled_parser.OrderedPair
pytiled_parser.Size
^^^^^^^^^^^^^^^^^^^
.. autoclass:: pytiled_parser.Size

20
docs/api/index.rst Normal file
View File

@@ -0,0 +1,20 @@
.. _api:
API Reference
=============
This page documents the Application Programming Interface (API) for the PyTiled Parser library.
Throughout the API documentation you will see links labeled both TMX Reference and JSON Reference.
These links go to the official Tiled documentation for that specific type. Sometimes there is not a
one to one mapping, so it may lead to the closest thing in the Tiled format.
At some points certain classes modules may have links to other parts of the Tiled documentation which
cover some of the concepts surrounding that module and it's usage within Tiled.
.. toctree::
:maxdepth: 1
:caption: PyTiled Parser
common_types
properties
layer

48
docs/api/layer.rst Normal file
View File

@@ -0,0 +1,48 @@
.. _layer_api:
Layer
=====
This module provides classes for all layer types
There is the base Layer class, which TileLayer, ObjectLayer, ImageLayer,
and LayerGroup all derive from. The base Layer class is never directly used,
and serves only as an abstract base for common elements between all types.
For more information about Layers, see `Tiled's Manual <https://doc.mapeditor.org/en/stable/manual/layers/>`_
pytiled_parser.Layer
^^^^^^^^^^^^^^^^^^^^
.. autoclass:: pytiled_parser.Layer
:members:
pytiled_parser.TileLayer
^^^^^^^^^^^^^^^^^^^^^^^^
.. autoclass:: pytiled_parser.TileLayer
:members:
pytiled_parser.Chunk
^^^^^^^^^^^^^^^^^^^^
.. autoclass:: pytiled_parser.Chunk
:members:
pytiled_parser.ObjectLayer
^^^^^^^^^^^^^^^^^^^^^^^^^^
.. autoclass:: pytiled_parser.ObjectLayer
:members:
pytiled_parser.ImageLayer
^^^^^^^^^^^^^^^^^^^^^^^^^
.. autoclass:: pytiled_parser.ImageLayer
:members:
pytiled_parser.LayerGroup
^^^^^^^^^^^^^^^^^^^^^^^^^
.. autoclass:: pytiled_parser.LayerGroup
:members:

27
docs/api/properties.rst Normal file
View File

@@ -0,0 +1,27 @@
.. _properties_api:
Properties
==========
This module provides some common types used throughout PyTiled Parser. These are all just NamedTuple
classes provided to make sets of data more clear. As such they can be subscripted like a normal tuple
to get the same values, or you can reference them by name. The values shown here are in the order they
will be in the final tuple.
Properties do not have a special class or anything associated with them. They are simply type aliases for
built-in Python types.
pytiled_parser.Property
^^^^^^^^^^^^^^^^^^^^^^^
The ``pytiled_parser.Property`` type is a Union of the `float`, `str`, and `bool` built-in types, as well as
`Path` class from pathlib, and the `pytiled_parser.Color` common type.
A property may be any one of these types.
pytiled_parser.Properties
^^^^^^^^^^^^^^^^^^^^^^^^^
The ``pytiled_parser.Properties`` type is a Dictionary mapping of `str` to `pytiled_parser.Property` objects.
When the map is parsed, all properties will be loaded in as a Property, and stored in a Properties dictionary
with the name being it's key in the dictionary.

52
docs/conf.py Normal file
View File

@@ -0,0 +1,52 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
sys.path.insert(0, os.path.abspath(".."))
# -- Project information -----------------------------------------------------
project = "PyTiled Parser"
copyright = "2022, Benjamin Kirkbride, Darren Eberly"
author = "Benjamin Kirkbride, Darren Eberly"
# -- General configuration ---------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ["sphinx.ext.autodoc", "sphinx.ext.coverage", "sphinx.ext.napoleon"]
# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
# -- Options for HTML output -------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = "furo"
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ["_static"]

18
docs/guide/index.rst Normal file
View File

@@ -0,0 +1,18 @@
.. _api:
Programming Guide
=================
This section will guide you through the implementation details of using PyTiled Parser. This is not
an exact science, and will depend heavily on the library you are trying to integrate with. A lot of
the techniques here will show some general concepts and sort of pseudo code, as well as compare to the
`Arcade <https://api.arcade.academy/>`_ implementation as it is the most complete implementation of this
library to date.
Many liberties are taken when implementing with a game engine to suit that engines needs specifically. It
is a double edged sword of using Tiled, it is very flexible and can be implemented in a lot of different ways.
This comes at the cost of making a guide like this not as straight forward as it otherwise would be.
.. toctree::
:maxdepth: 1
map_loading

View File

@@ -0,0 +1,4 @@
Loading A Map
=============
Hello World

View File

@@ -1,7 +0,0 @@
# PyTiled Parser
PyTiled Parser is a Python Library for parsing maps made with the [Tiled Map Editor](https://www.mapeditor.org) for 2D games in a strictly typed fashion.
PyTiled Parser is not tied to any particular graphics library, and as such could be used with [Arcade](https://api.arcade.academy), [Pyglet](https://pyglet.readthedocs.io), [Pygame](https://www.pygame.org/news), or any other Python graphics library.
While we don't offer any direct integrations to other libraries/frameworks, [Arcade](https://api.arcade.academy) has full integration for PyTiled Parser out of the box, and would be a good resource to use as an example implementation.

42
docs/index.rst Normal file
View File

@@ -0,0 +1,42 @@
PyTiled Parser
==============
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 games in a strictly typed fashion.
PyTiled Parser is not tied to any particular graphics library or game engine. It parses map files and returns arbitrary
Python types(for example, ``Path`` objects for image files rather than a ``Sprite`` from a specific engine). This means
it can be used to aide in implementing Tiled support into a wide variety of tools.
* Documentation available at: https://pytiled-parser.readthedocs.io/
* GitHub Project: https://github.com/pythonarcade/pytiled_parser
* PyPi: https://pypi.org/project/pytiled-parser/
The `Arcade <https://api.arcade.academy/>`_ library has `supporting code <https://api.arcade.academy/en/latest/api/tilemap.html>`_
to integrate PyTiled Parser, as well as `example code <https://api.arcade.academy/en/latest/examples/index.html#using-tiled-map-editor-to-create-maps>`_
showing it's use.
Installation
^^^^^^^^^^^^
Simply install with pip::
pip install pytiled-parser
Quick Links
^^^^^^^^^^^
.. toctree::
:maxdepth: 1
guide/index
api/index
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

35
docs/make.bat Normal file
View File

@@ -0,0 +1,35 @@
@ECHO OFF
pushd %~dp0
REM Command file for Sphinx documentation
if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build
%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)
if "%1" == "" goto help
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end
:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
:end
popd

View File

@@ -1,3 +0,0 @@
# Common Types
::: pytiled_parser.common_types

View File

@@ -1 +0,0 @@
# Layer

View File

@@ -1,3 +0,0 @@
# Parser
::: pytiled_parser.parser

View File

@@ -1 +0,0 @@
# Properties

View File

@@ -1,3 +0,0 @@
# tiled_map
::: pytiled_parser.tiled_map

View File

@@ -1 +0,0 @@
# Tiled Object

View File

@@ -1 +0,0 @@
# TileSet

View File

@@ -1,5 +0,0 @@
# wang_set
::: pytiled_parser.wang_set
rendering:
members_order: source

View File

@@ -1,3 +0,0 @@
# Worlds
::: pytiled_parser.world

View File

@@ -1,44 +0,0 @@
site_name: PyTiled Parser
site_url: https://learn-arcade.dev/
repo_url: https://github.com/benjamin-kirkbride/pytiled_parser
repo_name: benjamin-kirkbride/pytiled_parser
theme:
features:
- search.suggest
name: material
palette:
- media: "(prefers-color-scheme: light)"
scheme: default
toggle:
icon: material/lightbulb-outline
name: Switch to dark mode
- media: "(prefers-color-scheme: dark)"
scheme: slate
primary: cyan
accent: pink
toggle:
icon: material/lightbulb
name: Switch to light mode
plugins:
- search
- mkdocstrings:
handlers:
python:
selection:
filters:
- "!^__"
- "!^_"
watch:
- pytiled_parser
nav:
- PyTiled Parser: index.md
- API Reference:
- reference/common_types.md
- reference/layer.md
- reference/parser.md
- reference/properties.md
- reference/tiled_map.md
- reference/tiled_object.md
- reference/tileset.md
- reference/wang_set.md
- reference/world.md

View File

@@ -13,9 +13,9 @@ PyTiled Parser is not tied to any particular graphics library or game engine.
from .common_types import Color, OrderedPair, Size
from .exception import UnknownFormat
from .layer import ImageLayer, Layer, LayerGroup, ObjectLayer, TileLayer
from .layer import Chunk, ImageLayer, Layer, LayerGroup, ObjectLayer, TileLayer
from .parser import parse_map
from .properties import Properties
from .properties import Properties, Property
from .tiled_map import TiledMap
from .tileset import Tile, Tileset
from .version import __version__

View File

@@ -8,13 +8,11 @@ from typing import NamedTuple
class Color(NamedTuple):
"""Represents an RGBA color value as a four value Tuple.
Attributes:
red: Red, between 1 and 255.
green: Green, between 1 and 255.
blue: Blue, between 1 and 255.
alpha: Alpha, between 1 and 255.
:param int red: Red value, between 0 and 255.
:param int green: Green value, between 0 and 255.
:param int blue: Blue value, between 0 and 255.
:param int alpha: Alpha value, between 0 and 255.
"""
red: int
green: int
blue: int
@@ -24,9 +22,8 @@ class Color(NamedTuple):
class Size(NamedTuple):
"""Represents a two dimensional size as a two value Tuple.
Attributes:
width: The width of the object in pixels.
height: The height of the object in pixels.
:param int width: The width of the object. Can be in either pixels or number of tiles.
:param int height: The height of the object. Can be in either pixels or number of tiles.
"""
width: float
@@ -36,9 +33,8 @@ class Size(NamedTuple):
class OrderedPair(NamedTuple):
"""Represents a two dimensional position as a two value Tuple.
Attributes:
x: X coordinate.
y: Y coordinate.
:param int x: X coordinate. Can be in either pixels or number of tiles.
:param int y: Y coordinate. Can be in either pixels or number of tiles.
"""
x: float

View File

@@ -19,27 +19,29 @@ from pytiled_parser.properties import Properties
from pytiled_parser.tiled_object import TiledObject
@attr.s(auto_attribs=True, kw_only=True)
@attr.s(repr=True, str=True, auto_attribs=True, kw_only=True)
class Layer:
"""Base class that all layer types inherit from. Includes common attributes between
the various types of layers.
the various types of layers. This class will never be returned directly by the parser.
It will always return one of the full layer types.
[TMX Reference](https://doc.mapeditor.org/en/stable/reference/tmx-map-format/#layer)
`TMX Reference <https://doc.mapeditor.org/en/stable/reference/tmx-map-format/#layer>`_
[JSON Reference](https://doc.mapeditor.org/en/stable/reference/json-map-format/#layer)
`JSON Reference <https://doc.mapeditor.org/en/stable/reference/json-map-format/#layer>`_
Attributes:
name: The name of the layer object.
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.
tint_color: Tint color that is multiplied with any graphics in this layer.
:param str name: The name of the layer object.
:param float opacity: Decimal value between 0 and 1 to determine opacity. 1 is completely
opaque, 0 is completely transparent. Defaults to 1.
:param bool visible: If the layer is visible in the Tiled Editor. Defaults to True
:param OrderedPair coordinates: Where layer content starts in tiles. Only used by infinite maps.
Defaults to (0, 0).
:param OrderedPair parallax_factor: Used to determine parallaxing speed of a layer. Defaults to (1, 1).
:param OrderedPair offset: Rendering offset of the layer object in pixels. Defaults to (0, 0).
:param Optional[int] id: Unique ID of the layer. Each layer that is added to a map gets a unique id.
Even if a layer is deleted, no layer ever gets the same ID.
:param Optional[Size] size: Ordered pair of size of map in tiles.
:param Optional[Properties] properties: Properties for the layer.
:param Optional[Color] tint_color: Tint color that is multiplied with any graphics in this layer.
"""
name: str
@@ -64,16 +66,15 @@ class Chunk:
"""Chunk object for infinite maps. Stores `data` like you would have in a normal
TileLayer but only for the area specified by `coordinates` and `size`.
[Infinite Maps Docs](https://doc.mapeditor.org/en/stable/manual/using-infinite-maps/)
`Infinite Maps Docs <https://doc.mapeditor.org/en/stable/manual/using-infinite-maps/>`_
[TMX Reference](https://doc.mapeditor.org/en/stable/reference/tmx-map-format/#chunk)
`TMX Reference <https://doc.mapeditor.org/en/stable/reference/tmx-map-format/#chunk>`_
[JSON Reference](https://doc.mapeditor.org/en/stable/reference/json-map-format/#chunk)
`JSON Reference <https://doc.mapeditor.org/en/stable/reference/json-map-format/#chunk>`_
Attributes:
coordinates: Location of chunk in tiles.
size: The size of the chunk in tiles.
data: The global tile IDs in chunky according to row.
:param OrderedPair coordinates: Location of chunk in tiles.
:param Size size: The size of the chunk in tiles.
:param List[List[int]] data: The global tile IDs in the chunk. A row-first two dimensional array.
"""
coordinates: OrderedPair
@@ -92,16 +93,15 @@ LayerData = Union[TileLayerGrid, List[Chunk]]
class TileLayer(Layer):
"""The base type of layer which stores tile data for an area of a map.
[Tiled Docs](https://doc.mapeditor.org/en/stable/manual/layers/#tile-layers)
`Tiled Docs <https://doc.mapeditor.org/en/stable/manual/layers/#tile-layers>`_
[TMX Reference](https://doc.mapeditor.org/en/stable/reference/tmx-map-format/#layer)
`TMX Reference <https://doc.mapeditor.org/en/stable/reference/tmx-map-format/#layer>`_
[JSON Reference](https://doc.mapeditor.org/en/stable/reference/json-map-format/#tile-layer-example)
`JSON Reference <https://doc.mapeditor.org/en/stable/reference/json-map-format/#tile-layer-example>`_
Attributes:
chunks: List of chunks (only populated for infinite maps)
data: A 2 dimensional array of integers representing the global tile
IDs for the map layer (only populated for non-infinite maps)
:param Optional[List[Chunk]] chunks: List of chunks (only populated for infinite maps)
:param Optional[List[List[int]] data: A two dimensional array of integers representing the global
tile IDs for the layer (only populaed for non-infinite maps)
"""
chunks: Optional[List[Chunk]] = None
@@ -112,19 +112,18 @@ class TileLayer(Layer):
class ObjectLayer(Layer):
"""A Layer type which stores a list of Tiled Objects
[Tiled Docs](https://doc.mapeditor.org/en/stable/manual/layers/#object-layers)
`Tiled Docs <https://doc.mapeditor.org/en/stable/manual/layers/#object-layers>`_
[TMX Reference](https://doc.mapeditor.org/en/stable/reference/tmx-map-format/#objectgroup)
`TMX Reference <https://doc.mapeditor.org/en/stable/reference/tmx-map-format/#objectgroup>`_
[JSON Reference](https://doc.mapeditor.org/en/stable/reference/json-map-format/#object-layer-example)
`JSON Reference <https://doc.mapeditor.org/en/stable/reference/json-map-format/#object-layer-example>`_
Attributes:
tiled_objects: List of tiled_objects in the layer.
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.
:param List[TiledOjbect] tiled_objects: List of tiled_objects in the layer.
:param Optional[str] 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.
"""
tiled_objects: List[TiledObject]
@@ -134,17 +133,16 @@ class ObjectLayer(Layer):
@attr.s(auto_attribs=True, kw_only=True)
class ImageLayer(Layer):
"""Map layer containing a single image
"""A layer type which stores a single image
[Tiled Docs](https://doc.mapeditor.org/en/stable/manual/layers/#image-layers)
`Tiled Docs <https://doc.mapeditor.org/en/stable/manual/layers/#image-layers>`_
[TMX Reference](https://doc.mapeditor.org/en/stable/reference/tmx-map-format/#imagelayer)
`TMX Reference <https://doc.mapeditor.org/en/stable/reference/tmx-map-format/#imagelayer>`_
[JSON Reference](https://doc.mapeditor.org/en/stable/reference/json-map-format/#layer)
`JSON Reference <https://doc.mapeditor.org/en/stable/reference/json-map-format/#layer>`_
Attributes:
image: The image used by this layer.
transparent_color: Color that is to be made transparent on this layer.
:param Path image: The image used by this layer.
:param Optional[Color] transparent_color: Color that is to be made transparent on this layer.
"""
image: Path
@@ -159,14 +157,13 @@ class LayerGroup(Layer):
parsing by pytiled_parser, and is up to the implementation how to handle recursive effects of
LayerGroups
[Tiled Docs](https://doc.mapeditor.org/en/stable/manual/layers/#group-layers)
`Tiled Docs <https://doc.mapeditor.org/en/stable/manual/layers/#group-layers>`_
[TMX Reference](https://doc.mapeditor.org/en/stable/reference/tmx-map-format/#group)
`TMX Reference <https://doc.mapeditor.org/en/stable/reference/tmx-map-format/#group>`_
[JSON Reference](https://doc.mapeditor.org/en/stable/reference/json-map-format/#layer)
`JSON Reference <https://doc.mapeditor.org/en/stable/reference/json-map-format/#layer>`_
Attributes:
Layers: list of layers contained in the group.
:param Optional[List[Layer]] layers: list of layers contained in the group.
"""
layers: Optional[List[Layer]]

View File

@@ -52,9 +52,10 @@ build =
pep517
docs =
mkdocs
mkdocs-material
mkdocstrings
sphinx
sphinx-sitemap
myst-parser
furo
[bdist_wheel]
universal=0