From d92276a766692f04d13ccef0fa742219ebe68d49 Mon Sep 17 00:00:00 2001 From: Benjamin Kirkbride Date: Sat, 6 Jun 2020 17:12:17 -0400 Subject: [PATCH] build out more of the map module --- pytiled_parser/map.py | 45 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/pytiled_parser/map.py b/pytiled_parser/map.py index 19343fc..7786394 100644 --- a/pytiled_parser/map.py +++ b/pytiled_parser/map.py @@ -4,11 +4,12 @@ from pathlib import Path from typing import Dict, List, NamedTuple, Optional, Union import attr +from typing_extensions import TypedDict from .common_types import Color, Size from .layer import Layer -from .properties import Properties -from .tileset import TileSet +from .properties import Properties, RawProperty +from .tileset import RawTileSet, TileSet TileSetDict = Dict[int, TileSet] @@ -71,5 +72,41 @@ class Map: properties: Optional[Properties] = None -def cast() -> Map: - pass +class _RawTiledMap(TypedDict): + """ The keys and their types that appear in a Tiled JSON Map. + + Keys: + compressionlevel: not documented - https://github.com/bjorn/tiled/issues/2815 + """ + + backgroundcolor: str + compressionlevel: int + height: int + hexsidelength: int + infinite: bool + layers: List[RawLayer] + nextlayerid: int + nextobjectid: int + orientation: str + properties: List[RawProperty] + renderorder: str + staggeraxis: str + staggerindex: str + tiledversion: str + tileheight: int + tilesets: List[RawTileSet] + tilewidth: int + type: str + version: str + width: int + + +def cast(raw_tiled_map: _RawTiledMap) -> Map: + """ Cast the raw Tiled map into a pytiled_parser type + + Args: + raw_tiled_map: Raw JSON Formatted Tiled Map to be cast. + + Returns: + TileSet: a properly typed TileSet. + """