tilemap-parser 3.1.0__tar.gz → 3.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {tilemap_parser-3.1.0 → tilemap_parser-3.1.2}/PKG-INFO +1 -1
- {tilemap_parser-3.1.0 → tilemap_parser-3.1.2}/pyproject.toml +1 -1
- {tilemap_parser-3.1.0 → tilemap_parser-3.1.2}/src/tilemap_parser/parser/collision.py +4 -4
- {tilemap_parser-3.1.0 → tilemap_parser-3.1.2}/src/tilemap_parser/parser/map_parse.py +2 -0
- {tilemap_parser-3.1.0 → tilemap_parser-3.1.2}/src/tilemap_parser/runtime/map_loader.py +4 -0
- {tilemap_parser-3.1.0 → tilemap_parser-3.1.2}/src/tilemap_parser/runtime/renderer.py +15 -7
- {tilemap_parser-3.1.0 → tilemap_parser-3.1.2}/src/tilemap_parser/runtime/tile_collision.py +253 -95
- {tilemap_parser-3.1.0 → tilemap_parser-3.1.2}/src/tilemap_parser.egg-info/PKG-INFO +1 -1
- {tilemap_parser-3.1.0 → tilemap_parser-3.1.2}/src/tilemap_parser.egg-info/SOURCES.txt +2 -0
- tilemap_parser-3.1.2/tests/test_map_loader.py +122 -0
- tilemap_parser-3.1.2/tests/test_render_scale.py +424 -0
- {tilemap_parser-3.1.0 → tilemap_parser-3.1.2}/LICENSE +0 -0
- {tilemap_parser-3.1.0 → tilemap_parser-3.1.2}/README.md +0 -0
- {tilemap_parser-3.1.0 → tilemap_parser-3.1.2}/setup.cfg +0 -0
- {tilemap_parser-3.1.0 → tilemap_parser-3.1.2}/src/tilemap_parser/__init__.py +0 -0
- {tilemap_parser-3.1.0 → tilemap_parser-3.1.2}/src/tilemap_parser/parser/__init__.py +0 -0
- {tilemap_parser-3.1.0 → tilemap_parser-3.1.2}/src/tilemap_parser/parser/animation.py +0 -0
- {tilemap_parser-3.1.0 → tilemap_parser-3.1.2}/src/tilemap_parser/parser/collision_loader.py +0 -0
- {tilemap_parser-3.1.0 → tilemap_parser-3.1.2}/src/tilemap_parser/runtime/__init__.py +0 -0
- {tilemap_parser-3.1.0 → tilemap_parser-3.1.2}/src/tilemap_parser/runtime/animation_player.py +0 -0
- {tilemap_parser-3.1.0 → tilemap_parser-3.1.2}/src/tilemap_parser/runtime/collision_cache.py +0 -0
- {tilemap_parser-3.1.0 → tilemap_parser-3.1.2}/src/tilemap_parser/runtime/object_collision.py +0 -0
- {tilemap_parser-3.1.0 → tilemap_parser-3.1.2}/src/tilemap_parser/utils/__init__.py +0 -0
- {tilemap_parser-3.1.0 → tilemap_parser-3.1.2}/src/tilemap_parser/utils/geometry.py +0 -0
- {tilemap_parser-3.1.0 → tilemap_parser-3.1.2}/src/tilemap_parser.egg-info/dependency_links.txt +0 -0
- {tilemap_parser-3.1.0 → tilemap_parser-3.1.2}/src/tilemap_parser.egg-info/requires.txt +0 -0
- {tilemap_parser-3.1.0 → tilemap_parser-3.1.2}/src/tilemap_parser.egg-info/top_level.txt +0 -0
- {tilemap_parser-3.1.0 → tilemap_parser-3.1.2}/tests/test_collision.py +0 -0
- {tilemap_parser-3.1.0 → tilemap_parser-3.1.2}/tests/test_geometry.py +0 -0
- {tilemap_parser-3.1.0 → tilemap_parser-3.1.2}/tests/test_object_collision.py +0 -0
- {tilemap_parser-3.1.0 → tilemap_parser-3.1.2}/tests/test_tile_collision.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tilemap-parser
|
|
3
|
-
Version: 3.1.
|
|
3
|
+
Version: 3.1.2
|
|
4
4
|
Summary: Standalone parser/loader for tilemap-editor JSON maps, sprite animations, and collision detection runtime.
|
|
5
5
|
Author: tilemap parser contributors
|
|
6
6
|
License: GNU GENERAL PUBLIC LICENSE
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "tilemap-parser"
|
|
7
|
-
version = "3.1.
|
|
7
|
+
version = "3.1.2"
|
|
8
8
|
description = "Standalone parser/loader for tilemap-editor JSON maps, sprite animations, and collision detection runtime."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -29,9 +29,9 @@ class CollisionPolygon:
|
|
|
29
29
|
vertices: List[Point]
|
|
30
30
|
one_way: bool = False
|
|
31
31
|
|
|
32
|
-
def transform(self, tile_x: float, tile_y: float) -> "CollisionPolygon":
|
|
32
|
+
def transform(self, tile_x: float, tile_y: float, scale: float = 1.0) -> "CollisionPolygon":
|
|
33
33
|
"""Transform polygon to world space coordinates"""
|
|
34
|
-
world_vertices = [(tile_x + vx, tile_y + vy) for vx, vy in self.vertices]
|
|
34
|
+
world_vertices = [(tile_x + vx * scale, tile_y + vy * scale) for vx, vy in self.vertices]
|
|
35
35
|
return CollisionPolygon(vertices=world_vertices, one_way=self.one_way)
|
|
36
36
|
|
|
37
37
|
def is_valid(self) -> bool:
|
|
@@ -69,13 +69,13 @@ class TilesetCollision:
|
|
|
69
69
|
return tile_data is not None and tile_data.has_collision()
|
|
70
70
|
|
|
71
71
|
def get_world_shapes(
|
|
72
|
-
self, tile_id: int, tile_x: float, tile_y: float
|
|
72
|
+
self, tile_id: int, tile_x: float, tile_y: float, scale: float = 1.0
|
|
73
73
|
) -> List[CollisionPolygon]:
|
|
74
74
|
"""Get collision shapes transformed to world space"""
|
|
75
75
|
tile_data = self.get_tile_collision(tile_id)
|
|
76
76
|
if not tile_data:
|
|
77
77
|
return []
|
|
78
|
-
return [shape.transform(tile_x, tile_y) for shape in tile_data.shapes]
|
|
78
|
+
return [shape.transform(tile_x, tile_y, scale) for shape in tile_data.shapes]
|
|
79
79
|
|
|
80
80
|
|
|
81
81
|
@dataclass
|
|
@@ -170,6 +170,7 @@ class ParsedMeta:
|
|
|
170
170
|
zoom_level: float
|
|
171
171
|
scroll: Point
|
|
172
172
|
version: str
|
|
173
|
+
render_scale: float = 1.0
|
|
173
174
|
|
|
174
175
|
|
|
175
176
|
@dataclass
|
|
@@ -394,6 +395,7 @@ def parse_map_dict(root: JsonDict) -> ParsedMap:
|
|
|
394
395
|
zoom_level=_coerce_float(meta_obj.get("zoom_level", 1.0), "meta.zoom_level"),
|
|
395
396
|
scroll=_parse_point_field(meta_obj.get("scroll"), "meta.scroll", default="0;0"),
|
|
396
397
|
version=_require_str(meta_obj.get("version", "1.1"), "meta.version"),
|
|
398
|
+
render_scale=_coerce_float(meta_obj.get("render_scale", 1.0), "meta.render_scale"),
|
|
397
399
|
)
|
|
398
400
|
|
|
399
401
|
data_obj = _require_dict(root.get("data"), "data")
|
|
@@ -114,6 +114,10 @@ class TilemapData:
|
|
|
114
114
|
def map_size(self) -> Tuple[int, int]:
|
|
115
115
|
return self.parsed.meta.map_size
|
|
116
116
|
|
|
117
|
+
@property
|
|
118
|
+
def render_scale(self) -> float:
|
|
119
|
+
return self.parsed.meta.render_scale
|
|
120
|
+
|
|
117
121
|
def get_raw(self) -> dict:
|
|
118
122
|
return deepcopy(self.parsed.raw)
|
|
119
123
|
|
|
@@ -3,7 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
from dataclasses import dataclass
|
|
4
4
|
from typing import Dict, Optional, Tuple, Union
|
|
5
5
|
|
|
6
|
-
from pygame import Rect, Surface
|
|
6
|
+
from pygame import Rect, Surface, transform
|
|
7
7
|
|
|
8
8
|
from .map_loader import TilemapData
|
|
9
9
|
|
|
@@ -29,6 +29,11 @@ class TileLayerRenderer:
|
|
|
29
29
|
)
|
|
30
30
|
self._variant_cache: Dict[Tuple[int, int], Optional[Surface]] = {}
|
|
31
31
|
self._tile_w, self._tile_h = data.tile_size
|
|
32
|
+
self._rs = data.render_scale
|
|
33
|
+
if self._rs <= 0:
|
|
34
|
+
raise ValueError(f"render_scale must be positive, got {self._rs}")
|
|
35
|
+
self._eff_w = int(self._tile_w * self._rs)
|
|
36
|
+
self._eff_h = int(self._tile_h * self._rs)
|
|
32
37
|
|
|
33
38
|
def get_layer_dict(self) -> Dict[int, object]:
|
|
34
39
|
return dict(self.tile_layers)
|
|
@@ -36,9 +41,12 @@ class TileLayerRenderer:
|
|
|
36
41
|
def _get_cached_variant(self, ttype: int, variant: int) -> Optional[Surface]:
|
|
37
42
|
key = (ttype, variant)
|
|
38
43
|
if key not in self._variant_cache:
|
|
39
|
-
|
|
44
|
+
cell = self.data.get_tile_surface(
|
|
40
45
|
ttype, variant, copy_surface=True
|
|
41
46
|
)
|
|
47
|
+
if cell is not None and self._rs != 1.0:
|
|
48
|
+
cell = transform.scale(cell, (self._eff_w, self._eff_h))
|
|
49
|
+
self._variant_cache[key] = cell
|
|
42
50
|
return self._variant_cache[key]
|
|
43
51
|
|
|
44
52
|
def warm_cache(self) -> None:
|
|
@@ -61,10 +69,10 @@ class TileLayerRenderer:
|
|
|
61
69
|
else:
|
|
62
70
|
viewport = Rect(0, 0, viewport_size[0], viewport_size[1])
|
|
63
71
|
|
|
64
|
-
min_x = int(cam_x // self.
|
|
65
|
-
max_x = int((cam_x + viewport.width) // self.
|
|
66
|
-
min_y = int(cam_y // self.
|
|
67
|
-
max_y = int((cam_y + viewport.height) // self.
|
|
72
|
+
min_x = int(cam_x // self._eff_w) - 1
|
|
73
|
+
max_x = int((cam_x + viewport.width) // self._eff_w) + 1
|
|
74
|
+
min_y = int(cam_y // self._eff_h) - 1
|
|
75
|
+
max_y = int((cam_y + viewport.height) // self._eff_h) + 1
|
|
68
76
|
|
|
69
77
|
drawn = 0
|
|
70
78
|
skipped = 0
|
|
@@ -86,7 +94,7 @@ class TileLayerRenderer:
|
|
|
86
94
|
if cell is None:
|
|
87
95
|
skipped += 1
|
|
88
96
|
continue
|
|
89
|
-
target.blit(cell, (x * self.
|
|
97
|
+
target.blit(cell, (x * self._eff_w - cam_x, y * self._eff_h - cam_y))
|
|
90
98
|
drawn += 1
|
|
91
99
|
|
|
92
100
|
return LayerRenderStats(
|