mirror of
https://github.com/OMGeeky/pytiled_parser.git
synced 2025-12-26 17:02:28 +01:00
Ran black formatting
This commit is contained in:
@@ -14,6 +14,7 @@ class Color(NamedTuple):
|
||||
blue: Blue value, between 0 and 255.
|
||||
alpha: Alpha value, between 0 and 255.
|
||||
"""
|
||||
|
||||
red: int
|
||||
green: int
|
||||
blue: int
|
||||
|
||||
@@ -32,12 +32,13 @@ def parse_map(file: Path) -> TiledMap:
|
||||
"This message could also mean your map file is invalid or corrupted."
|
||||
)
|
||||
|
||||
|
||||
def parse_world(file: Path) -> World:
|
||||
"""Parse the raw world file into a pytiled_parser type
|
||||
|
||||
Args:
|
||||
file: Path to the world file
|
||||
|
||||
|
||||
Returns:
|
||||
World: A parsed and typed World
|
||||
"""
|
||||
|
||||
@@ -34,19 +34,16 @@ from pytiled_parser.util import parse_color
|
||||
# development purposes it should only be installed when specifically manually
|
||||
# testing for zstd things.
|
||||
zstd_spec = importlib.util.find_spec("zstd")
|
||||
if zstd_spec: # pragma: no cover
|
||||
if zstd_spec: # pragma: no cover
|
||||
import zstd
|
||||
else:
|
||||
zstd = None
|
||||
|
||||
|
||||
RawChunk = TypedDict("RawChunk", {
|
||||
"data": Union[List[int], str],
|
||||
"height": int,
|
||||
"width": int,
|
||||
"x": int,
|
||||
"y": int
|
||||
})
|
||||
RawChunk = TypedDict(
|
||||
"RawChunk",
|
||||
{"data": Union[List[int], str], "height": int, "width": int, "x": int, "y": int},
|
||||
)
|
||||
RawChunk.__doc__ = """
|
||||
The keys and their types that appear in a Tiled JSON Chunk Object.
|
||||
|
||||
@@ -54,36 +51,38 @@ RawChunk.__doc__ = """
|
||||
"""
|
||||
|
||||
|
||||
|
||||
RawLayer = TypedDict("RawLayer", {
|
||||
"chunks": List[RawChunk],
|
||||
"compression": str,
|
||||
"data": Union[List[int], str],
|
||||
"draworder": str,
|
||||
"encoding": str,
|
||||
"height": int,
|
||||
"id": int,
|
||||
"image": str,
|
||||
"layers": List[Any],
|
||||
"name": str,
|
||||
"objects": List[RawObject],
|
||||
"offsetx": float,
|
||||
"offsety": float,
|
||||
"parallaxx": float,
|
||||
"parallaxy": float,
|
||||
"opacity": float,
|
||||
"properties": List[RawProperty],
|
||||
"startx": int,
|
||||
"starty": int,
|
||||
"tintcolor": str,
|
||||
"transparentcolor": str,
|
||||
"class": str,
|
||||
"type": str,
|
||||
"visible": bool,
|
||||
"width": int,
|
||||
"x": int,
|
||||
"y": int
|
||||
})
|
||||
RawLayer = TypedDict(
|
||||
"RawLayer",
|
||||
{
|
||||
"chunks": List[RawChunk],
|
||||
"compression": str,
|
||||
"data": Union[List[int], str],
|
||||
"draworder": str,
|
||||
"encoding": str,
|
||||
"height": int,
|
||||
"id": int,
|
||||
"image": str,
|
||||
"layers": List[Any],
|
||||
"name": str,
|
||||
"objects": List[RawObject],
|
||||
"offsetx": float,
|
||||
"offsety": float,
|
||||
"parallaxx": float,
|
||||
"parallaxy": float,
|
||||
"opacity": float,
|
||||
"properties": List[RawProperty],
|
||||
"startx": int,
|
||||
"starty": int,
|
||||
"tintcolor": str,
|
||||
"transparentcolor": str,
|
||||
"class": str,
|
||||
"type": str,
|
||||
"visible": bool,
|
||||
"width": int,
|
||||
"x": int,
|
||||
"y": int,
|
||||
},
|
||||
)
|
||||
RawLayer.__doc__ = """
|
||||
The keys and their types that appear in a Tiled JSON Layer Object.
|
||||
|
||||
@@ -141,7 +140,7 @@ def _decode_tile_layer_data(
|
||||
"To install use 'pip install pytiled-parser[zstd]'"
|
||||
)
|
||||
# See above note at top of module about zstd tests
|
||||
elif compression == "zstd": # pragma: no cover
|
||||
elif compression == "zstd": # pragma: no cover
|
||||
unzipped_data = zstd.decompress(unencoded_data)
|
||||
else:
|
||||
unzipped_data = unencoded_data
|
||||
|
||||
@@ -22,20 +22,23 @@ from pytiled_parser.tiled_object import (
|
||||
)
|
||||
from pytiled_parser.util import load_object_template, parse_color
|
||||
|
||||
RawText = TypedDict("RawText", {
|
||||
"text": str,
|
||||
"color": str,
|
||||
"fontfamily": str,
|
||||
"pixelsize": float, # this is `font_size` in Text
|
||||
"bold": bool,
|
||||
"italic": bool,
|
||||
"strikeout": bool,
|
||||
"underline": bool,
|
||||
"kerning": bool,
|
||||
"halign": str,
|
||||
"valign": str,
|
||||
"wrap": bool
|
||||
})
|
||||
RawText = TypedDict(
|
||||
"RawText",
|
||||
{
|
||||
"text": str,
|
||||
"color": str,
|
||||
"fontfamily": str,
|
||||
"pixelsize": float, # this is `font_size` in Text
|
||||
"bold": bool,
|
||||
"italic": bool,
|
||||
"strikeout": bool,
|
||||
"underline": bool,
|
||||
"kerning": bool,
|
||||
"halign": str,
|
||||
"valign": str,
|
||||
"wrap": bool,
|
||||
},
|
||||
)
|
||||
RawText.__doc__ = """
|
||||
The keys and their types that appear in a Tiled JSON Text Object.
|
||||
|
||||
@@ -43,26 +46,29 @@ RawText.__doc__ = """
|
||||
"""
|
||||
|
||||
|
||||
RawObject = TypedDict("RawObject", {
|
||||
"id": int,
|
||||
"gid": int,
|
||||
"template": str,
|
||||
"x": float,
|
||||
"y": float,
|
||||
"width": float,
|
||||
"height": float,
|
||||
"rotation": float,
|
||||
"visible": bool,
|
||||
"name": str,
|
||||
"class": str,
|
||||
"type": str,
|
||||
"properties": List[RawProperty],
|
||||
"ellipse": bool,
|
||||
"point": bool,
|
||||
"polygon": List[Dict[str, float]],
|
||||
"polyline": List[Dict[str, float]],
|
||||
"text": RawText
|
||||
})
|
||||
RawObject = TypedDict(
|
||||
"RawObject",
|
||||
{
|
||||
"id": int,
|
||||
"gid": int,
|
||||
"template": str,
|
||||
"x": float,
|
||||
"y": float,
|
||||
"width": float,
|
||||
"height": float,
|
||||
"rotation": float,
|
||||
"visible": bool,
|
||||
"name": str,
|
||||
"class": str,
|
||||
"type": str,
|
||||
"properties": List[RawProperty],
|
||||
"ellipse": bool,
|
||||
"point": bool,
|
||||
"polygon": List[Dict[str, float]],
|
||||
"polyline": List[Dict[str, float]],
|
||||
"text": RawText,
|
||||
},
|
||||
)
|
||||
RawObject.__doc__ = """
|
||||
The keys and their types that appear in a Tiled JSON Object.
|
||||
|
||||
@@ -266,7 +272,7 @@ def _get_parser(raw_object: RawObject) -> Callable[[RawObject], TiledObject]:
|
||||
# there are tests for Tile objects, but for some reason the coverage
|
||||
# isn't picking up this if statement(though it does pickup the _parse_tile)
|
||||
# function so who knows
|
||||
if raw_object.get("gid"): # pragma: no cover
|
||||
if raw_object.get("gid"): # pragma: no cover
|
||||
# Only tile objects have the `gid` key
|
||||
return _parse_tile
|
||||
|
||||
|
||||
@@ -13,88 +13,82 @@ from pytiled_parser.parsers.json.wang_set import parse as parse_wangset
|
||||
from pytiled_parser.tileset import Frame, Grid, Tile, Tileset, Transformations
|
||||
from pytiled_parser.util import parse_color
|
||||
|
||||
RawFrame = TypedDict("RawFrame", {
|
||||
"duration": int,
|
||||
"tileid": int
|
||||
})
|
||||
RawFrame = TypedDict("RawFrame", {"duration": int, "tileid": int})
|
||||
RawFrame.__doc__ = """
|
||||
The keys and their types that appear in a Frame JSON Object.
|
||||
"""
|
||||
|
||||
|
||||
RawTileOffset = TypedDict("RawTileOffset", {
|
||||
"x": int,
|
||||
"y": int
|
||||
})
|
||||
RawTileOffset = TypedDict("RawTileOffset", {"x": int, "y": int})
|
||||
RawTileOffset.__doc__ = """
|
||||
The keys and their types that appear in a TileOffset JSON Object.
|
||||
"""
|
||||
|
||||
|
||||
RawTransformations = TypedDict("RawTransformations", {
|
||||
"hflip": bool,
|
||||
"vflip": bool,
|
||||
"rotate": bool,
|
||||
"preferuntransformed": bool
|
||||
})
|
||||
RawTransformations = TypedDict(
|
||||
"RawTransformations",
|
||||
{"hflip": bool, "vflip": bool, "rotate": bool, "preferuntransformed": bool},
|
||||
)
|
||||
RawTransformations.__doc__ = """
|
||||
The keys and their types that appear in a Transformations JSON Object.
|
||||
"""
|
||||
|
||||
|
||||
RawTile = TypedDict("RawTile", {
|
||||
"animation": List[RawFrame],
|
||||
"class": str,
|
||||
"id": int,
|
||||
"image": str,
|
||||
"imageheight": int,
|
||||
"imagewidth": int,
|
||||
"opacity": float,
|
||||
"type": str,
|
||||
"properties": List[RawProperty],
|
||||
"objectgroup": RawLayer,
|
||||
})
|
||||
RawTile = TypedDict(
|
||||
"RawTile",
|
||||
{
|
||||
"animation": List[RawFrame],
|
||||
"class": str,
|
||||
"id": int,
|
||||
"image": str,
|
||||
"imageheight": int,
|
||||
"imagewidth": int,
|
||||
"opacity": float,
|
||||
"type": str,
|
||||
"properties": List[RawProperty],
|
||||
"objectgroup": RawLayer,
|
||||
},
|
||||
)
|
||||
RawTile.__docs__ = """
|
||||
The keys and their types that appear in a Tile JSON Object.
|
||||
"""
|
||||
|
||||
|
||||
RawGrid = TypedDict("RawGrid", {
|
||||
"height": int,
|
||||
"width": int,
|
||||
"orientation": str
|
||||
})
|
||||
RawGrid = TypedDict("RawGrid", {"height": int, "width": int, "orientation": str})
|
||||
RawGrid.__doc__ = """
|
||||
The keys and their types that appear in a Grid JSON Object.
|
||||
"""
|
||||
|
||||
|
||||
RawTileSet = TypedDict("RawTileSet", {
|
||||
"backgroundcolor": str,
|
||||
"class": str,
|
||||
"columns": int,
|
||||
"firstgid": int,
|
||||
"grid": RawGrid,
|
||||
"image": str,
|
||||
"imageheight": int,
|
||||
"imagewidth": int,
|
||||
"margin": int,
|
||||
"name": str,
|
||||
"properties": List[RawProperty],
|
||||
"objectalignment": str,
|
||||
"source": str,
|
||||
"spacing": int,
|
||||
"tilecount": int,
|
||||
"tiledversion": str,
|
||||
"tileheight": int,
|
||||
"tileoffset": RawTileOffset,
|
||||
"tiles": List[RawTile],
|
||||
"tilewidth": int,
|
||||
"transparentcolor": str,
|
||||
"transformations": RawTransformations,
|
||||
"version": Union[str, float],
|
||||
"wangsets": List[RawWangSet]
|
||||
})
|
||||
RawTileSet = TypedDict(
|
||||
"RawTileSet",
|
||||
{
|
||||
"backgroundcolor": str,
|
||||
"class": str,
|
||||
"columns": int,
|
||||
"firstgid": int,
|
||||
"grid": RawGrid,
|
||||
"image": str,
|
||||
"imageheight": int,
|
||||
"imagewidth": int,
|
||||
"margin": int,
|
||||
"name": str,
|
||||
"properties": List[RawProperty],
|
||||
"objectalignment": str,
|
||||
"source": str,
|
||||
"spacing": int,
|
||||
"tilecount": int,
|
||||
"tiledversion": str,
|
||||
"tileheight": int,
|
||||
"tileoffset": RawTileOffset,
|
||||
"tiles": List[RawTile],
|
||||
"tilewidth": int,
|
||||
"transparentcolor": str,
|
||||
"transformations": RawTransformations,
|
||||
"version": Union[str, float],
|
||||
"wangsets": List[RawWangSet],
|
||||
},
|
||||
)
|
||||
RawTileSet.__doc__ = """
|
||||
The keys and their types that appear in a TileSet JSON Object.
|
||||
"""
|
||||
@@ -193,12 +187,12 @@ def _parse_tile(raw_tile: RawTile, external_path: Optional[Path] = None) -> Tile
|
||||
|
||||
# These are ignored from coverage because there does not exist a scenario where
|
||||
# image is set, but these aren't, so the branches will never fully be hit.
|
||||
# However, leaving these checks in place is nice to prevent fatal errors on
|
||||
# However, leaving these checks in place is nice to prevent fatal errors on
|
||||
# a manually edited map that has an "incorrect" but not "unusable" structure
|
||||
if raw_tile.get("imagewidth") is not None: # pragma: no cover
|
||||
if raw_tile.get("imagewidth") is not None: # pragma: no cover
|
||||
tile.image_width = raw_tile["imagewidth"]
|
||||
|
||||
if raw_tile.get("imageheight") is not None: # pragma: no cover
|
||||
if raw_tile.get("imageheight") is not None: # pragma: no cover
|
||||
tile.image_height = raw_tile["imageheight"]
|
||||
|
||||
if raw_tile.get("type") is not None:
|
||||
@@ -242,7 +236,7 @@ def parse(
|
||||
# to keep old versions in the test data and not update them with the
|
||||
# rest so I'm excluding this from coverage. In reality it's probably
|
||||
# not needed. Tiled hasn't been using floats for the version for a long time
|
||||
if isinstance(raw_tileset["version"], float): # pragma: no cover
|
||||
if isinstance(raw_tileset["version"], float): # pragma: no cover
|
||||
tileset.version = str(raw_tileset["version"])
|
||||
else:
|
||||
tileset.version = raw_tileset["version"]
|
||||
@@ -260,10 +254,10 @@ def parse(
|
||||
|
||||
# See above note about imagewidth and imageheight on parse_tile function
|
||||
# for an explanation on why these are ignored
|
||||
if raw_tileset.get("imagewidth") is not None: # pragma: no cover
|
||||
if raw_tileset.get("imagewidth") is not None: # pragma: no cover
|
||||
tileset.image_width = raw_tileset["imagewidth"]
|
||||
|
||||
if raw_tileset.get("imageheight") is not None: # pragma: no cover
|
||||
if raw_tileset.get("imageheight") is not None: # pragma: no cover
|
||||
tileset.image_height = raw_tileset["imageheight"]
|
||||
|
||||
if raw_tileset.get("objectalignment") is not None:
|
||||
|
||||
@@ -7,39 +7,48 @@ from pytiled_parser.parsers.json.properties import parse as parse_properties
|
||||
from pytiled_parser.util import parse_color
|
||||
from pytiled_parser.wang_set import WangColor, WangSet, WangTile
|
||||
|
||||
RawWangTile = TypedDict("RawWangTile", {
|
||||
"tileid": int,
|
||||
# Tiled stores these IDs as a list represented like so:
|
||||
# [top, top_right, right, bottom_right, bottom, bottom_left, left, top_left]
|
||||
"wangid": List[int]
|
||||
})
|
||||
RawWangTile = TypedDict(
|
||||
"RawWangTile",
|
||||
{
|
||||
"tileid": int,
|
||||
# Tiled stores these IDs as a list represented like so:
|
||||
# [top, top_right, right, bottom_right, bottom, bottom_left, left, top_left]
|
||||
"wangid": List[int],
|
||||
},
|
||||
)
|
||||
RawWangTile.__doc__ = """
|
||||
The keys and their types that appear in a Wang Tile JSON Object.
|
||||
"""
|
||||
|
||||
|
||||
RawWangColor = TypedDict("RawWangColor", {
|
||||
"color": str,
|
||||
"class": str,
|
||||
"name": str,
|
||||
"probability": float,
|
||||
"tile": int,
|
||||
"properties": List[RawProperty]
|
||||
})
|
||||
RawWangColor = TypedDict(
|
||||
"RawWangColor",
|
||||
{
|
||||
"color": str,
|
||||
"class": str,
|
||||
"name": str,
|
||||
"probability": float,
|
||||
"tile": int,
|
||||
"properties": List[RawProperty],
|
||||
},
|
||||
)
|
||||
RawWangColor.__doc__ = """
|
||||
The keys and their types that appear in a Wang Color JSON Object.
|
||||
"""
|
||||
|
||||
|
||||
RawWangSet = TypedDict("RawWangSet", {
|
||||
"colors": List[RawWangColor],
|
||||
"class": str,
|
||||
"name": str,
|
||||
"properties": List[RawProperty],
|
||||
"tile": int,
|
||||
"type": str,
|
||||
"wangtiles": List[RawWangTile]
|
||||
})
|
||||
RawWangSet = TypedDict(
|
||||
"RawWangSet",
|
||||
{
|
||||
"colors": List[RawWangColor],
|
||||
"class": str,
|
||||
"name": str,
|
||||
"properties": List[RawProperty],
|
||||
"tile": int,
|
||||
"type": str,
|
||||
"wangtiles": List[RawWangTile],
|
||||
},
|
||||
)
|
||||
RawWangSet.__doc__ = """
|
||||
The keys and their types that appear in a Wang Set JSON Object.
|
||||
"""
|
||||
|
||||
@@ -31,7 +31,7 @@ from pytiled_parser.util import parse_color
|
||||
# development purposes it should only be installed when specifically manually
|
||||
# testing for zstd things.
|
||||
zstd_spec = importlib.util.find_spec("zstd")
|
||||
if zstd_spec: # pragma: no cover
|
||||
if zstd_spec: # pragma: no cover
|
||||
import zstd
|
||||
else:
|
||||
zstd = None
|
||||
@@ -87,7 +87,7 @@ def _decode_tile_layer_data(
|
||||
"To install use 'pip install pytiled-parser[zstd]'"
|
||||
)
|
||||
# See above note at top of module about zstd tests
|
||||
elif compression == "zstd": # pragma: no cover
|
||||
elif compression == "zstd": # pragma: no cover
|
||||
unzipped_data = zstd.decompress(unencoded_data)
|
||||
else:
|
||||
unzipped_data = unencoded_data
|
||||
|
||||
@@ -41,6 +41,7 @@ class TiledObject:
|
||||
|
||||
properties: properties_.Properties = {}
|
||||
|
||||
|
||||
@attr.s()
|
||||
class Ellipse(TiledObject):
|
||||
"""Elipse shape defined by a point, width, height, and rotation.
|
||||
|
||||
Reference in New Issue
Block a user