tilemap-parser 1.1.0__tar.gz → 2.0.0__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-1.1.0/src/tilemap_parser.egg-info → tilemap_parser-2.0.0}/PKG-INFO +1 -1
- {tilemap_parser-1.1.0 → tilemap_parser-2.0.0}/pyproject.toml +2 -1
- {tilemap_parser-1.1.0 → tilemap_parser-2.0.0}/src/tilemap_parser/collision.py +70 -36
- tilemap_parser-2.0.0/src/tilemap_parser/collision_runner.py +918 -0
- {tilemap_parser-1.1.0 → tilemap_parser-2.0.0/src/tilemap_parser.egg-info}/PKG-INFO +1 -1
- {tilemap_parser-1.1.0 → tilemap_parser-2.0.0}/src/tilemap_parser.egg-info/SOURCES.txt +2 -1
- tilemap_parser-2.0.0/tests/test_collision.py +387 -0
- tilemap_parser-1.1.0/src/tilemap_parser/collision_runner.py +0 -580
- {tilemap_parser-1.1.0 → tilemap_parser-2.0.0}/LICENSE +0 -0
- {tilemap_parser-1.1.0 → tilemap_parser-2.0.0}/README.md +0 -0
- {tilemap_parser-1.1.0 → tilemap_parser-2.0.0}/setup.cfg +0 -0
- {tilemap_parser-1.1.0 → tilemap_parser-2.0.0}/src/tilemap_parser/__init__.py +0 -0
- {tilemap_parser-1.1.0 → tilemap_parser-2.0.0}/src/tilemap_parser/animation.py +0 -0
- {tilemap_parser-1.1.0 → tilemap_parser-2.0.0}/src/tilemap_parser/map_loader.py +0 -0
- {tilemap_parser-1.1.0 → tilemap_parser-2.0.0}/src/tilemap_parser/map_parse.py +0 -0
- {tilemap_parser-1.1.0 → tilemap_parser-2.0.0}/src/tilemap_parser/renderer.py +0 -0
- {tilemap_parser-1.1.0 → tilemap_parser-2.0.0}/src/tilemap_parser.egg-info/dependency_links.txt +0 -0
- {tilemap_parser-1.1.0 → tilemap_parser-2.0.0}/src/tilemap_parser.egg-info/requires.txt +0 -0
- {tilemap_parser-1.1.0 → tilemap_parser-2.0.0}/src/tilemap_parser.egg-info/top_level.txt +0 -0
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "tilemap-parser"
|
|
7
|
-
version = "
|
|
7
|
+
version = "2.0.0"
|
|
8
8
|
description = "Standalone parser/loader for tilemap-editor JSON maps and sprite animation JSON."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -26,4 +26,5 @@ include-package-data = false
|
|
|
26
26
|
[tool.setuptools.packages.find]
|
|
27
27
|
where = ["src"]
|
|
28
28
|
include = ["tilemap_parser*"]
|
|
29
|
+
exclude = ["webdocs*", "tests*"]
|
|
29
30
|
namespaces = false
|
|
@@ -217,22 +217,24 @@ def parse_character_collision(data: JsonDict) -> CharacterCollision:
|
|
|
217
217
|
|
|
218
218
|
|
|
219
219
|
def load_tileset_collision(
|
|
220
|
-
|
|
220
|
+
collision_path: Union[str, Path],
|
|
221
221
|
) -> Optional[TilesetCollision]:
|
|
222
222
|
"""
|
|
223
|
-
Load tileset collision data from file.
|
|
223
|
+
Load tileset collision data from a collision JSON file.
|
|
224
|
+
|
|
225
|
+
The editor stores tileset collision files at:
|
|
226
|
+
<data_root>/collision/<tileset_stem>.collision.json
|
|
224
227
|
|
|
225
228
|
Args:
|
|
226
|
-
|
|
229
|
+
collision_path: Direct path to the .collision.json file.
|
|
227
230
|
|
|
228
231
|
Returns:
|
|
229
|
-
TilesetCollision object or None if
|
|
232
|
+
TilesetCollision object, or None if the file does not exist.
|
|
230
233
|
|
|
231
234
|
Raises:
|
|
232
|
-
CollisionParseError: If
|
|
235
|
+
CollisionParseError: If the file exists but cannot be parsed.
|
|
233
236
|
"""
|
|
234
|
-
|
|
235
|
-
collision_path = tileset_path.with_suffix(".collision.json")
|
|
237
|
+
collision_path = Path(collision_path)
|
|
236
238
|
|
|
237
239
|
if not collision_path.exists():
|
|
238
240
|
return None
|
|
@@ -241,27 +243,29 @@ def load_tileset_collision(
|
|
|
241
243
|
with open(collision_path, "r", encoding="utf-8") as f:
|
|
242
244
|
data = json.load(f)
|
|
243
245
|
return parse_tileset_collision(data)
|
|
244
|
-
except (OSError, json.JSONDecodeError) as e:
|
|
246
|
+
except (OSError, UnicodeDecodeError, json.JSONDecodeError) as e:
|
|
245
247
|
raise CollisionParseError(f"Cannot load {collision_path}: {e}") from e
|
|
246
248
|
|
|
247
249
|
|
|
248
250
|
def load_character_collision(
|
|
249
|
-
|
|
251
|
+
collision_path: Union[str, Path],
|
|
250
252
|
) -> Optional[CharacterCollision]:
|
|
251
253
|
"""
|
|
252
|
-
Load character collision data from file.
|
|
254
|
+
Load character collision data from a collision JSON file.
|
|
255
|
+
|
|
256
|
+
The editor stores character collision files at:
|
|
257
|
+
<data_root>/character_collision/<character_name>.collision.json
|
|
253
258
|
|
|
254
259
|
Args:
|
|
255
|
-
|
|
260
|
+
collision_path: Direct path to the .collision.json file.
|
|
256
261
|
|
|
257
262
|
Returns:
|
|
258
|
-
CharacterCollision object or None if
|
|
263
|
+
CharacterCollision object, or None if the file does not exist.
|
|
259
264
|
|
|
260
265
|
Raises:
|
|
261
|
-
CollisionParseError: If
|
|
266
|
+
CollisionParseError: If the file exists but cannot be parsed.
|
|
262
267
|
"""
|
|
263
|
-
|
|
264
|
-
collision_path = sprite_path.with_suffix(".collision.json")
|
|
268
|
+
collision_path = Path(collision_path)
|
|
265
269
|
|
|
266
270
|
if not collision_path.exists():
|
|
267
271
|
return None
|
|
@@ -270,7 +274,7 @@ def load_character_collision(
|
|
|
270
274
|
with open(collision_path, "r", encoding="utf-8") as f:
|
|
271
275
|
data = json.load(f)
|
|
272
276
|
return parse_character_collision(data)
|
|
273
|
-
except (OSError, json.JSONDecodeError) as e:
|
|
277
|
+
except (OSError, UnicodeDecodeError, json.JSONDecodeError) as e:
|
|
274
278
|
raise CollisionParseError(f"Cannot load {collision_path}: {e}") from e
|
|
275
279
|
|
|
276
280
|
|
|
@@ -280,6 +284,12 @@ class CollisionCache:
|
|
|
280
284
|
|
|
281
285
|
Caches parsed collision data to avoid repeated file I/O and parsing.
|
|
282
286
|
Useful for runtime performance in game engines.
|
|
287
|
+
|
|
288
|
+
All methods accept the direct path to the .collision.json file.
|
|
289
|
+
|
|
290
|
+
Typical paths produced by the editor:
|
|
291
|
+
Tileset: <data_root>/collision/<stem>.collision.json
|
|
292
|
+
Character: <data_root>/character_collision/<name>.collision.json
|
|
283
293
|
"""
|
|
284
294
|
|
|
285
295
|
def __init__(self):
|
|
@@ -287,24 +297,32 @@ class CollisionCache:
|
|
|
287
297
|
self._character_cache: Dict[str, Optional[CharacterCollision]] = {}
|
|
288
298
|
|
|
289
299
|
def get_tileset_collision(
|
|
290
|
-
self,
|
|
300
|
+
self, collision_path: Union[str, Path]
|
|
291
301
|
) -> Optional[TilesetCollision]:
|
|
292
|
-
"""Get tileset collision data (cached)
|
|
293
|
-
|
|
302
|
+
"""Get tileset collision data (cached).
|
|
303
|
+
|
|
304
|
+
Args:
|
|
305
|
+
collision_path: Direct path to the .collision.json file.
|
|
306
|
+
"""
|
|
307
|
+
key = str(Path(collision_path).resolve())
|
|
294
308
|
|
|
295
309
|
if key not in self._tileset_cache:
|
|
296
|
-
self._tileset_cache[key] = load_tileset_collision(
|
|
310
|
+
self._tileset_cache[key] = load_tileset_collision(collision_path)
|
|
297
311
|
|
|
298
312
|
return self._tileset_cache[key]
|
|
299
313
|
|
|
300
314
|
def get_character_collision(
|
|
301
|
-
self,
|
|
315
|
+
self, collision_path: Union[str, Path]
|
|
302
316
|
) -> Optional[CharacterCollision]:
|
|
303
|
-
"""Get character collision data (cached)
|
|
304
|
-
|
|
317
|
+
"""Get character collision data (cached).
|
|
318
|
+
|
|
319
|
+
Args:
|
|
320
|
+
collision_path: Direct path to the .collision.json file.
|
|
321
|
+
"""
|
|
322
|
+
key = str(Path(collision_path).resolve())
|
|
305
323
|
|
|
306
324
|
if key not in self._character_cache:
|
|
307
|
-
self._character_cache[key] = load_character_collision(
|
|
325
|
+
self._character_cache[key] = load_character_collision(collision_path)
|
|
308
326
|
|
|
309
327
|
return self._character_cache[key]
|
|
310
328
|
|
|
@@ -313,30 +331,46 @@ class CollisionCache:
|
|
|
313
331
|
self._tileset_cache.clear()
|
|
314
332
|
self._character_cache.clear()
|
|
315
333
|
|
|
316
|
-
def preload_tileset(self,
|
|
317
|
-
"""Preload tileset collision data into cache
|
|
318
|
-
|
|
334
|
+
def preload_tileset(self, collision_path: Union[str, Path]):
|
|
335
|
+
"""Preload tileset collision data into cache.
|
|
336
|
+
|
|
337
|
+
Args:
|
|
338
|
+
collision_path: Direct path to the .collision.json file.
|
|
339
|
+
"""
|
|
340
|
+
self.get_tileset_collision(collision_path)
|
|
319
341
|
|
|
320
|
-
def preload_character(self,
|
|
321
|
-
"""Preload character collision data into cache
|
|
322
|
-
|
|
342
|
+
def preload_character(self, collision_path: Union[str, Path]):
|
|
343
|
+
"""Preload character collision data into cache.
|
|
344
|
+
|
|
345
|
+
Args:
|
|
346
|
+
collision_path: Direct path to the .collision.json file.
|
|
347
|
+
"""
|
|
348
|
+
self.get_character_collision(collision_path)
|
|
323
349
|
|
|
324
350
|
|
|
325
351
|
_global_cache = CollisionCache()
|
|
326
352
|
|
|
327
353
|
|
|
328
354
|
def get_cached_tileset_collision(
|
|
329
|
-
|
|
355
|
+
collision_path: Union[str, Path],
|
|
330
356
|
) -> Optional[TilesetCollision]:
|
|
331
|
-
"""Get tileset collision using global cache
|
|
332
|
-
|
|
357
|
+
"""Get tileset collision using global cache.
|
|
358
|
+
|
|
359
|
+
Args:
|
|
360
|
+
collision_path: Direct path to the .collision.json file.
|
|
361
|
+
"""
|
|
362
|
+
return _global_cache.get_tileset_collision(collision_path)
|
|
333
363
|
|
|
334
364
|
|
|
335
365
|
def get_cached_character_collision(
|
|
336
|
-
|
|
366
|
+
collision_path: Union[str, Path],
|
|
337
367
|
) -> Optional[CharacterCollision]:
|
|
338
|
-
"""Get character collision using global cache
|
|
339
|
-
|
|
368
|
+
"""Get character collision using global cache.
|
|
369
|
+
|
|
370
|
+
Args:
|
|
371
|
+
collision_path: Direct path to the .collision.json file.
|
|
372
|
+
"""
|
|
373
|
+
return _global_cache.get_character_collision(collision_path)
|
|
340
374
|
|
|
341
375
|
|
|
342
376
|
def clear_collision_cache():
|