tmx_utils.py 870B

123456789101112131415161718192021222324252627282930313233
  1. # coding: utf-8
  2. import typing
  3. from tmx import TileMap
  4. from tmx import Layer
  5. from synergine2.exceptions import ConfigurationError
  6. from synergine2_xyz.map import TMXMap
  7. if typing.TYPE_CHECKING:
  8. from synergine2_xyz.physics import Matrixes
  9. def get_layer_by_name(map_: TileMap, layer_name: str) -> Layer:
  10. for layer in map_.layers:
  11. if layer.name == layer_name:
  12. return layer
  13. raise ConfigurationError('No layer named "{}" in map')
  14. def fill_matrix(
  15. tmx_map: TMXMap,
  16. matrixes: 'Matrixes',
  17. layer_name: str,
  18. matrix_name: str,
  19. properties: typing.List[str],
  20. ) -> None:
  21. for tile_xy, tile in tmx_map.tmx_layer_tiles[layer_name].items():
  22. x, y = map(int, tile_xy.split('.'))
  23. values = [tile.property(p_name) for p_name in properties]
  24. matrixes.update_matrix(matrix_name, value=tuple(values), x=x, y=y)