mirror of
https://github.com/OMGeeky/pytiled_parser.git
synced 2025-12-28 23:27:23 +01:00
rf: define the tile layer data type
This commit is contained in:
@@ -12,10 +12,13 @@ from typing import Callable, Dict, List, Optional, Tuple, Union
|
||||
import pytiled_parser.objects as objects
|
||||
from pytiled_parser.utilities import parse_color
|
||||
|
||||
# See: https://doc.mapeditor.org/en/stable/reference/tmx-map-format/#data
|
||||
TileLayerData = List[List[int]]
|
||||
|
||||
|
||||
def _decode_base64_data(
|
||||
data_text: str, layer_width: int, compression: Optional[str] = None
|
||||
) -> List[List[int]]:
|
||||
) -> TileLayerData:
|
||||
"""Decode base64 data.
|
||||
|
||||
Args:
|
||||
@@ -27,9 +30,9 @@ def _decode_base64_data(
|
||||
ValueError: If compression type is unsupported.
|
||||
|
||||
Returns:
|
||||
:List[List[int]]: Tile grid.
|
||||
TileLayerData: Tile grid.
|
||||
"""
|
||||
tile_grid: List[List[int]] = [[]]
|
||||
tile_grid: TileLayerData = [[]]
|
||||
|
||||
unencoded_data = base64.b64decode(data_text)
|
||||
if compression == "zlib":
|
||||
@@ -62,14 +65,14 @@ def _decode_base64_data(
|
||||
return tile_grid
|
||||
|
||||
|
||||
def _decode_csv_data(data_text: str) -> List[List[int]]:
|
||||
def _decode_csv_data(data_text: str) -> TileLayerData:
|
||||
"""Decodes csv encoded layer data.
|
||||
|
||||
Args:
|
||||
data_text (str): Data to be decoded.
|
||||
|
||||
Returns:
|
||||
List[List[int]]: Tile grid.
|
||||
TileLayerData: Tile grid.
|
||||
"""
|
||||
tile_grid = []
|
||||
lines: List[str] = data_text.split("\n")
|
||||
@@ -86,12 +89,21 @@ def _decode_csv_data(data_text: str) -> List[List[int]]:
|
||||
return tile_grid
|
||||
|
||||
|
||||
TileLayerDecoder = Callable[[str, Optional[int], Optional[str]], TileLayerData]
|
||||
|
||||
|
||||
def _get_tile_layer_decoder(
|
||||
encoding: str, compression: Optional[str] = None
|
||||
) -> TileLayerDecoder:
|
||||
pass
|
||||
|
||||
|
||||
def _decode_tile_layer_data(
|
||||
element: etree.Element,
|
||||
layer_width: int,
|
||||
encoding: str,
|
||||
compression: Optional[str] = None,
|
||||
) -> List[List[int]]:
|
||||
) -> TileLayerData:
|
||||
"""Decodes tile layer data or chunk data.
|
||||
|
||||
See: https://doc.mapeditor.org/en/stable/reference/tmx-map-format/#tmx-data
|
||||
@@ -111,7 +123,7 @@ def _decode_tile_layer_data(
|
||||
AttributeError: No data in element.
|
||||
|
||||
Returns:
|
||||
List[List[int]]: Tile grid.
|
||||
TileLayerData: Tile grid.
|
||||
"""
|
||||
supported_encodings = ["base64", "csv"]
|
||||
if encoding not in supported_encodings:
|
||||
|
||||
Reference in New Issue
Block a user