test_interiors.py 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. # coding: utf-8
  2. from synergine2_xyz.map import TMXMap
  3. from PIL import Image
  4. from opencombat.simulation.interior import InteriorManager
  5. def test_interior_zones__one_zone():
  6. map_ = TMXMap('tests/fixtures/one_interior.tmx')
  7. manager = InteriorManager(map_)
  8. interiors = manager.get_interiors()
  9. assert interiors
  10. assert isinstance(interiors, list)
  11. assert 1 == len(interiors)
  12. assert (1, 1) in interiors[0]
  13. assert (1, 2) in interiors[0]
  14. assert (1, 3) in interiors[0]
  15. assert (2, 1) in interiors[0]
  16. assert (2, 2) in interiors[0]
  17. assert (2, 3) in interiors[0]
  18. assert (3, 1) in interiors[0]
  19. assert (3, 2) in interiors[0]
  20. assert (3, 3) in interiors[0]
  21. assert 9 == len(interiors[0])
  22. def test_interior_zones__two_separated_zones():
  23. map_ = TMXMap('tests/fixtures/two_interiors.tmx')
  24. manager = InteriorManager(map_)
  25. interiors = sorted(manager.get_interiors())
  26. assert interiors
  27. assert isinstance(interiors, list)
  28. assert 2 == len(interiors)
  29. assert (0, 1) in interiors[0]
  30. assert (1, 1) in interiors[0]
  31. assert (0, 2) in interiors[0]
  32. assert (1, 2) in interiors[0]
  33. assert (0, 3) in interiors[0]
  34. assert (1, 3) in interiors[0]
  35. assert 6 == len(interiors[0])
  36. assert (3, 1) in interiors[1]
  37. assert (4, 1) in interiors[1]
  38. assert (3, 2) in interiors[1]
  39. assert (4, 2) in interiors[1]
  40. assert (3, 3) in interiors[1]
  41. assert (4, 3) in interiors[1]
  42. assert 6 == len(interiors[1])
  43. def test_interiors_zones__side_by_side_zones_with_separator():
  44. map_ = TMXMap('tests/fixtures/side_by_side_interiors.tmx')
  45. manager = InteriorManager(map_)
  46. interiors = sorted(manager.get_interiors())
  47. assert interiors
  48. assert isinstance(interiors, list)
  49. assert 2 == len(interiors)
  50. assert (0, 1) in interiors[0]
  51. assert (1, 1) in interiors[0]
  52. assert (0, 2) in interiors[0]
  53. assert (1, 2) in interiors[0]
  54. assert (0, 3) in interiors[0]
  55. assert (1, 3) in interiors[0]
  56. assert (2, 1) in interiors[0]
  57. assert (2, 2) in interiors[0]
  58. assert (2, 3) in interiors[0]
  59. assert 9 == len(interiors[0])
  60. assert (2, 1) in interiors[1]
  61. assert (2, 2) in interiors[1]
  62. assert (2, 3) in interiors[1]
  63. assert (3, 1) in interiors[1]
  64. assert (4, 1) in interiors[1]
  65. assert (3, 2) in interiors[1]
  66. assert (4, 2) in interiors[1]
  67. assert (3, 3) in interiors[1]
  68. assert (4, 3) in interiors[1]
  69. assert 9 == len(interiors[1])
  70. def test_interiors_zones__active_zones():
  71. # active zones are zone where someone is in
  72. map_ = TMXMap('tests/fixtures/two_interiors.tmx')
  73. manager = InteriorManager(map_)
  74. interiors = manager.get_interiors(where_positions=[(0, 1)])
  75. assert (0, 1) in interiors[0]
  76. assert (1, 1) in interiors[0]
  77. assert (0, 2) in interiors[0]
  78. assert (1, 2) in interiors[0]
  79. assert (0, 3) in interiors[0]
  80. assert (1, 3) in interiors[0]
  81. assert 6 == len(interiors[0])
  82. interiors = manager.get_interiors(where_positions=[(4, 2)])
  83. assert 1 == len(interiors)
  84. assert (3, 1) in interiors[0]
  85. assert (4, 1) in interiors[0]
  86. assert (3, 2) in interiors[0]
  87. assert (4, 2) in interiors[0]
  88. assert (3, 3) in interiors[0]
  89. assert (4, 3) in interiors[0]
  90. assert 6 == len(interiors[0])
  91. interiors = manager.get_interiors(where_positions=[(0, 1), (4, 2)])
  92. assert 2 == len(interiors)
  93. interiors = sorted(interiors)
  94. assert (0, 1) in interiors[0]
  95. assert (1, 1) in interiors[0]
  96. assert (0, 2) in interiors[0]
  97. assert (1, 2) in interiors[0]
  98. assert (0, 3) in interiors[0]
  99. assert (1, 3) in interiors[0]
  100. assert 6 == len(interiors[0])
  101. assert (3, 1) in interiors[1]
  102. assert (4, 1) in interiors[1]
  103. assert (3, 2) in interiors[1]
  104. assert (4, 2) in interiors[1]
  105. assert (3, 3) in interiors[1]
  106. assert (4, 3) in interiors[1]
  107. assert 6 == len(interiors[1])
  108. def test_interiors_zones__make_image_transparent__just_replace():
  109. map_ = TMXMap('tests/fixtures/one_interior.tmx')
  110. manager = InteriorManager(map_)
  111. interiors = manager.get_interiors()
  112. image = Image.open('tests/fixtures/white_40x40.png')
  113. after_image_bytes = Image.open('tests/fixtures/white_one_interior_40x40.png').tobytes()
  114. manager.update_image_for_interiors(image, interiors, 8, 8)
  115. assert after_image_bytes == image.tobytes()
  116. def test_interiors_zones__make_image_complex_transparent__just_replace():
  117. map_ = TMXMap('tests/fixtures/one_interior.tmx')
  118. manager = InteriorManager(map_)
  119. interiors = manager.get_interiors()
  120. image = Image.open('tests/fixtures/complex_40x40.png')
  121. after_image_bytes = Image.open('tests/fixtures/complex_one_interior_40x40.png').tobytes()
  122. manager.update_image_for_interiors(image, interiors, 8, 8)
  123. assert after_image_bytes == image.tobytes()
  124. def test_interiors_zones__make_image_corner_transparent__just_replace():
  125. map_ = TMXMap('tests/fixtures/corner_interior.tmx')
  126. manager = InteriorManager(map_)
  127. interiors = manager.get_interiors()
  128. image = Image.open('tests/fixtures/white_40x40.png')
  129. after_image_bytes = Image.open('tests/fixtures/white_corner_interior_40x40.png').tobytes()
  130. manager.update_image_for_interiors(image, interiors, 8, 8)
  131. assert after_image_bytes == image.tobytes()