3
0

hydra_AtomEditorComponents_PostFxShapeWeightModifierAdded.py 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. """
  2. Copyright (c) Contributors to the Open 3D Engine Project.
  3. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. SPDX-License-Identifier: Apache-2.0 OR MIT
  5. """
  6. class Tests:
  7. postfx_shape_weight_creation = (
  8. "PostFx Shape Weight Modifier Entity successfully created",
  9. "P0: PostFx Shape Weight Modifier Entity failed to be created")
  10. postfx_shape_weight_component = (
  11. "Entity has a PostFx Shape Weight Modifier component",
  12. "P0: Entity failed to find PostFx Shape Weight Modifier component")
  13. postfx_shape_weight_component_removed = (
  14. "PostFx Shape Weight Modifier component removed",
  15. "P0: PostFx Shape Weight Modifier component failed to be removed")
  16. postfx_shape_weight_disabled = (
  17. "PostFx Shape Weight Modifier component disabled",
  18. "P0: PostFx Shape Weight Modifier component was not disabled.")
  19. postfx_layer_component = (
  20. "Entity has a PostFX Layer component",
  21. "P0: Entity did not have an PostFX Layer component")
  22. tube_shape_component = (
  23. "Entity has a Tube Shape component",
  24. "P0: Entity did not have a Tube Shape component")
  25. postfx_shape_weight_enabled = (
  26. "PostFx Shape Weight Modifier component enabled",
  27. "P0: PostFx Shape Weight Modifier component was not enabled.")
  28. enter_game_mode = (
  29. "Entered game mode",
  30. "P0: Failed to enter game mode")
  31. exit_game_mode = (
  32. "Exited game mode",
  33. "P0: Couldn't exit game mode")
  34. is_visible = (
  35. "Entity is visible",
  36. "P0: Entity was not visible")
  37. is_hidden = (
  38. "Entity is hidden",
  39. "P0: Entity was not hidden")
  40. entity_deleted = (
  41. "Entity deleted",
  42. "P0: Entity was not deleted")
  43. deletion_undo = (
  44. "UNDO deletion success",
  45. "P0: UNDO deletion failed")
  46. deletion_redo = (
  47. "REDO deletion success",
  48. "P0: REDO deletion failed")
  49. fall_off = (
  50. "'Fall-off Distance' property set",
  51. "P1: 'Fall-off Distance' property failed value set."
  52. )
  53. def AtomEditorComponents_postfx_shape_weight_AddedToEntity():
  54. """
  55. Summary:
  56. Tests the PostFx Shape Weight Modifier component can be added to an entity and has the expected functionality.
  57. Test setup:
  58. - Wait for Editor idle loop.
  59. - Open the "Base" level.
  60. Expected Behavior:
  61. The component can be added, used in game mode, hidden/shown, deleted, and has accurate required components.
  62. Creation and deletion undo/redo should also work.
  63. Test Steps:
  64. 1) Create a PostFx Shape Weight Modifier entity with no components.
  65. 2) Add a PostFx Shape Weight Modifier component to PostFx Shape Weight Modifier entity.
  66. 3) Remove PostFX Shape Weight Modifier component.
  67. 4) UNDO component removal.
  68. 5) Verify PostFx Shape Weight Modifier component not enabled.
  69. 6) Add PostFX Layer component since it is required by the PostFx Shape Weight Modifier component.
  70. 7) Verify PostFx Shape Weight Modifier component is NOT enabled since it also requires a shape.
  71. 8) Add a required shape looping over a list and checking if it enables PostFX Shape Weight Modifier.
  72. 9) Undo to remove each added shape and verify PostFX Shape Weight Modifier is not enabled.
  73. 10) Verify PostFx Shape Weight Modifier component is enabled by adding Spline and Tube Shape component.
  74. 11) Set 'Fall-off Distance' property
  75. 12) Enter/Exit game mode.
  76. 13) Test IsHidden.
  77. 14) Test IsVisible.
  78. 15) Delete PostFx Shape Weight Modifier entity.
  79. 16) UNDO deletion.
  80. 17) REDO deletion.
  81. 18) Look for errors.
  82. :return: None
  83. """
  84. import azlmbr.legacy.general as general
  85. from editor_python_test_tools.editor_entity_utils import EditorEntity
  86. from editor_python_test_tools.utils import Report, Tracer, TestHelper
  87. from Atom.atom_utils.atom_constants import AtomComponentProperties
  88. with Tracer() as error_tracer:
  89. # Test setup begins.
  90. # Setup: Wait for Editor idle loop before executing Python hydra scripts then open "Base" level.
  91. TestHelper.init_idle()
  92. TestHelper.open_level("Graphics", "base_empty")
  93. # Test steps begin.
  94. # 1. Create a PostFx Shape Weight Modifier entity with no components.
  95. postfx_shape_weight_entity = EditorEntity.create_editor_entity(AtomComponentProperties.postfx_shape())
  96. Report.critical_result(Tests.postfx_shape_weight_creation, postfx_shape_weight_entity.exists())
  97. # 2. Add a PostFx Shape Weight Modifier component to PostFx Shape Weight Modifier entity.
  98. postfx_shape_weight_component = postfx_shape_weight_entity.add_component(AtomComponentProperties.postfx_shape())
  99. Report.critical_result(
  100. Tests.postfx_shape_weight_component,
  101. postfx_shape_weight_entity.has_component(AtomComponentProperties.postfx_shape()))
  102. # 3. Remove PostFX Shape Weight Modifier component.
  103. postfx_shape_weight_component.remove()
  104. general.idle_wait_frames(1)
  105. Report.critical_result(
  106. Tests.postfx_shape_weight_component_removed,
  107. not postfx_shape_weight_entity.has_component(AtomComponentProperties.postfx_shape()))
  108. # 4. UNDO component removal.
  109. general.undo()
  110. general.idle_wait_frames(1)
  111. Report.critical_result(
  112. Tests.postfx_shape_weight_component,
  113. postfx_shape_weight_entity.has_component(AtomComponentProperties.postfx_shape()))
  114. # 5. Verify PostFx Shape Weight Modifier component not enabled.
  115. Report.result(Tests.postfx_shape_weight_disabled, not postfx_shape_weight_component.is_enabled())
  116. # 6. Add PostFX Layer component since it is required by the PostFx Shape Weight Modifier component.
  117. postfx_shape_weight_entity.add_component(AtomComponentProperties.postfx_layer())
  118. Report.result(
  119. Tests.postfx_layer_component,
  120. postfx_shape_weight_entity.has_component(AtomComponentProperties.postfx_layer()))
  121. # 7. Verify PostFx Shape Weight Modifier component is NOT enabled since it also requires a shape.
  122. Report.result(Tests.postfx_shape_weight_disabled, not postfx_shape_weight_component.is_enabled())
  123. # 8. Add a required shape looping over a list and checking if it enables PostFX Shape Weight Modifier.
  124. for shape in AtomComponentProperties.postfx_shape('shapes'):
  125. postfx_shape_weight_entity.add_component(shape)
  126. test_shape = (
  127. f"Entity has a {shape} component",
  128. f"Entity did not have a {shape} component")
  129. Report.result(test_shape, postfx_shape_weight_entity.has_component(shape))
  130. # Check if required shape allows PostFX Shape Weight Modifier to be enabled
  131. Report.result(Tests.postfx_shape_weight_enabled, postfx_shape_weight_component.is_enabled())
  132. # 9. Undo to remove each added shape and verify PostFX Shape Weight Modifier is not enabled.
  133. general.undo()
  134. TestHelper.wait_for_condition(lambda: not postfx_shape_weight_entity.has_component(shape), 1.0)
  135. Report.result(Tests.postfx_shape_weight_disabled, not postfx_shape_weight_component.is_enabled())
  136. # 10. Verify PostFx Shape Weight Modifier component is enabled by adding Spline and Tube Shape component.
  137. postfx_shape_weight_entity.add_components(['Spline', 'Tube Shape'])
  138. Report.result(Tests.tube_shape_component, postfx_shape_weight_entity.has_component('Tube Shape'))
  139. Report.result(Tests.postfx_shape_weight_enabled, postfx_shape_weight_component.is_enabled())
  140. # 11. Set 'Fall-off Distance' property
  141. postfx_shape_weight_component.set_component_property_value(
  142. AtomComponentProperties.postfx_shape('Fall-off Distance'), 100.0)
  143. Report.result(
  144. Tests.fall_off,
  145. postfx_shape_weight_component.get_component_property_value(
  146. AtomComponentProperties.postfx_shape('Fall-off Distance')) == 100.0)
  147. # 12. Enter/Exit game mode.
  148. TestHelper.enter_game_mode(Tests.enter_game_mode)
  149. general.idle_wait_frames(1)
  150. TestHelper.exit_game_mode(Tests.exit_game_mode)
  151. # 13. Test IsHidden.
  152. postfx_shape_weight_entity.set_visibility_state(False)
  153. Report.result(Tests.is_hidden, postfx_shape_weight_entity.is_hidden() is True)
  154. # 14. Test IsVisible.
  155. postfx_shape_weight_entity.set_visibility_state(True)
  156. general.idle_wait_frames(1)
  157. Report.result(Tests.is_visible, postfx_shape_weight_entity.is_visible() is True)
  158. # 15. Delete PostFx Shape Weight Modifier entity.
  159. postfx_shape_weight_entity.delete()
  160. Report.result(Tests.entity_deleted, not postfx_shape_weight_entity.exists())
  161. # 16. UNDO deletion.
  162. general.undo()
  163. general.idle_wait_frames(1)
  164. Report.result(Tests.deletion_undo, postfx_shape_weight_entity.exists())
  165. # 17. REDO deletion.
  166. general.redo()
  167. general.idle_wait_frames(1)
  168. Report.result(Tests.deletion_redo, not postfx_shape_weight_entity.exists())
  169. # 18. Look for errors or asserts.
  170. TestHelper.wait_for_condition(lambda: error_tracer.has_errors or error_tracer.has_asserts, 1.0)
  171. for error_info in error_tracer.errors:
  172. Report.info(f"Error: {error_info.filename} {error_info.function} | {error_info.message}")
  173. for assert_info in error_tracer.asserts:
  174. Report.info(f"Assert: {assert_info.filename} {assert_info.function} | {assert_info.message}")
  175. if __name__ == "__main__":
  176. from editor_python_test_tools.utils import Report
  177. Report.start_test(AtomEditorComponents_postfx_shape_weight_AddedToEntity)