test_tmx.py 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # coding: utf-8
  2. from xml.etree import ElementTree
  3. from synergine2_cocos2d.middleware import MapLoader
  4. from synergine2_xyz.map import TMXMap
  5. from synergine2_xyz.physics import Matrixes
  6. from synergine2_xyz.tmx_utils import fill_matrix
  7. from tests import BaseTest
  8. class TestVisibilityMatrix(BaseTest):
  9. def test_tmx_to_matrix(self):
  10. tmx_map = TMXMap('tests/fixtures/map_001.tmx')
  11. matrixes = Matrixes()
  12. assert 5 == tmx_map.width
  13. assert 5 == tmx_map.height
  14. matrixes.initialize_empty_matrix(
  15. 'visibility',
  16. matrix_height=5,
  17. matrix_width=5,
  18. value_structure=['height', 'opacity'],
  19. )
  20. assert [
  21. [(0.0, 0.0), (0.0, 0.0), (0.0, 0.0), (0.0, 0.0), (0.0, 0.0), ],
  22. [(0.0, 0.0), (0.0, 0.0), (0.0, 0.0), (0.0, 0.0), (0.0, 0.0), ],
  23. [(0.0, 0.0), (0.0, 0.0), (0.0, 0.0), (0.0, 0.0), (0.0, 0.0), ],
  24. [(0.0, 0.0), (0.0, 0.0), (0.0, 0.0), (0.0, 0.0), (0.0, 0.0), ],
  25. [(0.0, 0.0), (0.0, 0.0), (0.0, 0.0), (0.0, 0.0), (0.0, 0.0), ],
  26. ] == matrixes.get_matrix('visibility')
  27. fill_matrix(tmx_map, matrixes, 'terrain', 'visibility', ['height', 'opacity'])
  28. assert [
  29. [(0.0, 0.0), (0.0, 0.0), (0.0, 0.0), (0.0, 0.0), (0.0, 0.0), ],
  30. [(0.0, 0.0), (2.0, 100.0), (2.0, 100.0), (2.0, 100.0), (0.0, 0.0), ],
  31. [(0.0, 0.0), (2.0, 100.0), (0.0, 0.0), (2.0, 100.0), (0.0, 0.0), ],
  32. [(0.0, 0.0), (2.0, 100.0), (2.0, 100.0), (2.0, 100.0), (0.0, 0.0), ],
  33. [(0.0, 0.0), (0.0, 0.0), (0.0, 0.0), (0.0, 0.0), (0.0, 0.0), ],
  34. ] == matrixes.get_matrix('visibility')
  35. class TestLoadMap(BaseTest):
  36. def test_get_sanitized_map_content(self):
  37. loader = MapLoader()
  38. tree = ElementTree.parse('tests/fixtures/light.tmx')
  39. map_element = tree.getroot()
  40. map_content = loader.get_sanitized_map_content(
  41. map_element,
  42. 'tests/fixtures/light.tmx',
  43. )
  44. assert '<tileset firstgid="1" source="/tmp/' in map_content
  45. def test_get_sanitized_tileset_content(self):
  46. loader = MapLoader()
  47. tileset_content = loader.get_sanitized_tileset_content(
  48. 'tests/fixtures/terrain.tsx',
  49. )
  50. assert 'source="tests/fixtures/terrain.png"' in