Editor_ComponentPropertyCommands_containers.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. def check_result(result, msg):
  7. from editor_python_test_tools.utils import Report
  8. if not result:
  9. Report.result(msg, False)
  10. raise Exception(msg + " : FAILED")
  11. def Editor_ComponentPropertyCommands_containers():
  12. # Description:
  13. # Tests component properties that are containers
  14. from editor_python_test_tools.utils import Report
  15. from editor_python_test_tools.utils import TestHelper
  16. import azlmbr.bus as bus
  17. import azlmbr.editor as editor
  18. import azlmbr.legacy.general
  19. import azlmbr.entity as entity
  20. import azlmbr.surface_data
  21. import azlmbr.globals
  22. # Required for automated tests
  23. TestHelper.init_idle()
  24. # Open the test level
  25. TestHelper.open_level(directory="", level="Base")
  26. azlmbr.legacy.general.idle_wait_frames(1)
  27. def is_container(pte, path):
  28. return pte.is_container(path)
  29. def get_container_count(pte, path):
  30. outcome = pte.get_container_count(path)
  31. if(outcome.IsSuccess()):
  32. return outcome.GetValue()
  33. return False
  34. def reset_container(pte, path):
  35. outcome = pte.reset_container(path)
  36. if(outcome.IsSuccess()):
  37. return outcome.GetValue()
  38. return False
  39. def add_container_item(pte, path, key, item):
  40. outcome = pte.add_container_item(path, key, item)
  41. if(outcome.IsSuccess()):
  42. return outcome.GetValue()
  43. return False
  44. def remove_container_item(pte, path, key):
  45. outcome = pte.remove_container_item(path, key)
  46. if(outcome.IsSuccess()):
  47. return outcome.GetValue()
  48. return False
  49. def update_container_item(pte, path, key, value):
  50. outcome = pte.update_container_item(path, key, value)
  51. if(outcome.IsSuccess()):
  52. return outcome.GetValue()
  53. return False
  54. def get_container_item(pte, path, key):
  55. outcome = pte.get_container_item(path, key)
  56. if(outcome.IsSuccess()):
  57. return outcome.GetValue()
  58. return False
  59. # Create new Entity
  60. entityId = editor.ToolsApplicationRequestBus(bus.Broadcast, 'CreateNewEntity', entity.EntityId())
  61. check_result(entityId, "New entity with no parent created")
  62. tagOne = azlmbr.surface_data.SurfaceTag()
  63. tagOne.SetTag('one')
  64. tagTwo = azlmbr.surface_data.SurfaceTag()
  65. tagTwo.SetTag('two')
  66. tagThree = azlmbr.surface_data.SurfaceTag()
  67. tagThree.SetTag('three')
  68. tagFour = azlmbr.surface_data.SurfaceTag()
  69. tagFour.SetTag('four')
  70. # create a component with a TagSurface container
  71. typeIdsList = [azlmbr.globals.property.GradientSurfaceDataComponentTypeId]
  72. componentOutcome = editor.EditorComponentAPIBus(bus.Broadcast, 'AddComponentsOfType', entityId, typeIdsList)
  73. check_result(componentOutcome.IsSuccess(), 'AddComponentsOfType')
  74. components = componentOutcome.GetValue()
  75. tagList = components[0]
  76. pteOutcome = editor.EditorComponentAPIBus(bus.Broadcast, 'BuildComponentPropertyTreeEditor', tagList)
  77. #check_result(pteOutcome.IsSuccess(), 'BuildComponentPropertyTreeEditor')
  78. #pte = pteOutcome.GetValue()
  79. ## Test BuildComponentPropertyList
  80. #paths = pte.build_paths_list()
  81. #print(f'Paths {paths}')
  82. #tagListPropertyPath = 'm_template|Extended Tags'
  83. #check_result(is_container(pte, tagListPropertyPath), 'Has a container')
  84. #check_result(get_container_count(pte, tagListPropertyPath) == 0, 'Has zero items')
  85. #check_result(add_container_item(pte, tagListPropertyPath, 0, tagOne), 'Add an item 0')
  86. #check_result(get_container_count(pte, tagListPropertyPath) == 1, 'Has one item 0')
  87. #check_result(add_container_item(pte, tagListPropertyPath, 1, tagOne), 'Add an item 1')
  88. #check_result(add_container_item(pte, tagListPropertyPath, 2, tagTwo), 'Add an item 2')
  89. #check_result(add_container_item(pte, tagListPropertyPath, 3, tagThree), 'Add an item 3')
  90. #check_result(get_container_count(pte, tagListPropertyPath) == 4, 'Has four items')
  91. #check_result(update_container_item(pte, tagListPropertyPath, 2, tagFour), 'Updated an item')
  92. #itemTag = get_container_item(pte, tagListPropertyPath, 2)
  93. #check_result (itemTag.Equal(tagFour), 'itemTag equals tagFour')
  94. #check_result(remove_container_item(pte, tagListPropertyPath, 0), 'Removed one item 0')
  95. #check_result(remove_container_item(pte, tagListPropertyPath, 0), 'Removed one item 1')
  96. #check_result(get_container_count(pte, tagListPropertyPath) == 2, 'Has two items')
  97. #check_result(reset_container(pte, tagListPropertyPath), 'Reset items')
  98. #check_result(get_container_count(pte, tagListPropertyPath) == 0, 'Has cleared the items')
  99. # all tests worked
  100. Report.result("Editor_ComponentPropertyCommands_containers ran", True)
  101. if __name__ == "__main__":
  102. from editor_python_test_tools.utils import Report
  103. Report.start_test(Editor_ComponentPropertyCommands_containers)