mirror of
https://github.com/OMGeeky/pytiled_parser.git
synced 2025-12-26 17:02:28 +01:00
rf: rename TileLayerData to TileLayerGrid and use it for Chunks as well
This commit is contained in:
@@ -9,7 +9,7 @@ from typing import Dict, List, NamedTuple, Optional, Union
|
||||
import attr
|
||||
|
||||
# See: https://doc.mapeditor.org/en/stable/reference/tmx-map-format/#data
|
||||
TileLayerData = List[List[int]]
|
||||
TileLayerGrid = List[List[int]]
|
||||
|
||||
|
||||
class Color(NamedTuple):
|
||||
@@ -87,7 +87,7 @@ class Chunk:
|
||||
location: OrderedPair
|
||||
width: int
|
||||
height: int
|
||||
chunk_data: List[List[int]]
|
||||
chunk_data: TileLayerGrid
|
||||
|
||||
|
||||
@attr.s(auto_attribs=True)
|
||||
@@ -209,7 +209,7 @@ class Layer:
|
||||
properties: Optional[Properties]
|
||||
|
||||
|
||||
LayerData = Union[List[List[int]], List[Chunk]]
|
||||
LayerData = Union[TileLayerGrid, List[Chunk]]
|
||||
"""The tile data for one layer.
|
||||
|
||||
Either a 2 dimensional array of integers representing the global tile IDs
|
||||
|
||||
@@ -15,7 +15,7 @@ from pytiled_parser.utilities import parse_color
|
||||
|
||||
def _decode_base64_data(
|
||||
data_text: str, layer_width: int, compression: Optional[str] = None
|
||||
) -> objects.TileLayerData:
|
||||
) -> objects.TileLayerGrid:
|
||||
"""Decode base64 data.
|
||||
|
||||
Args:
|
||||
@@ -27,9 +27,9 @@ def _decode_base64_data(
|
||||
ValueError: If compression type is unsupported.
|
||||
|
||||
Returns:
|
||||
objects.TileLayerData: Tile grid.
|
||||
objects.TileLayerGrid: Tile grid.
|
||||
"""
|
||||
tile_grid: objects.TileLayerData = [[]]
|
||||
tile_grid: objects.TileLayerGrid = [[]]
|
||||
|
||||
unencoded_data = base64.b64decode(data_text)
|
||||
if compression == "zlib":
|
||||
@@ -62,14 +62,14 @@ def _decode_base64_data(
|
||||
return tile_grid
|
||||
|
||||
|
||||
def _decode_csv_data(data_text: str) -> objects.TileLayerData:
|
||||
def _decode_csv_data(data_text: str) -> objects.TileLayerGrid:
|
||||
"""Decodes csv encoded layer data.
|
||||
|
||||
Args:
|
||||
data_text (str): Data to be decoded.
|
||||
|
||||
Returns:
|
||||
objects.TileLayerData: Tile grid.
|
||||
objects.TileLayerGrid: Tile grid.
|
||||
"""
|
||||
tile_grid = []
|
||||
lines: List[str] = data_text.split("\n")
|
||||
@@ -86,7 +86,7 @@ def _decode_csv_data(data_text: str) -> objects.TileLayerData:
|
||||
return tile_grid
|
||||
|
||||
|
||||
TileLayerDecoder = Callable[[str, Optional[int], Optional[str]], objects.TileLayerData]
|
||||
TileLayerDecoder = Callable[[str, Optional[int], Optional[str]], objects.TileLayerGrid]
|
||||
|
||||
|
||||
def _get_tile_layer_decoder(
|
||||
@@ -120,7 +120,7 @@ def _decode_tile_layer_data(
|
||||
layer_width: int,
|
||||
encoding: str,
|
||||
compression: Optional[str] = None,
|
||||
) -> objects.TileLayerData:
|
||||
) -> objects.TileLayerGrid:
|
||||
"""Decodes tile layer data or chunk data.
|
||||
|
||||
See: https://doc.mapeditor.org/en/stable/reference/tmx-map-format/#tmx-data
|
||||
@@ -140,7 +140,7 @@ def _decode_tile_layer_data(
|
||||
AttributeError: No data in element.
|
||||
|
||||
Returns:
|
||||
objects.TileLayerData: Tile grid.
|
||||
objects.TileLayerGrid: Tile grid.
|
||||
"""
|
||||
supported_encodings = ["base64", "csv"]
|
||||
if encoding not in supported_encodings:
|
||||
|
||||
Reference in New Issue
Block a user