Editor_ComponentPropertyCommands_enum.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. import os, sys
  7. sys.path.append(os.path.dirname(__file__))
  8. from Editor_TestClass import BaseClass
  9. class Editor_ComponentPropertyCommands_enum(BaseClass):
  10. # Description:
  11. # Tests setting property values that are not 32 or 64 bit such as a u8
  12. @staticmethod
  13. def test():
  14. import azlmbr.bus as bus
  15. import azlmbr.editor as editor
  16. import azlmbr.entity as entity
  17. import azlmbr.math as math
  18. check_result = BaseClass.check_result
  19. def GetSetCompareTest(component, path, value):
  20. oldObj = editor.EditorComponentAPIBus(bus.Broadcast, 'GetComponentProperty', component, path)
  21. oldValue = None
  22. newValue = None
  23. if(oldObj.IsSuccess()):
  24. oldValue = oldObj.GetValue()
  25. oldValueCompared = editor.EditorComponentAPIBus(bus.Broadcast, 'CompareComponentProperty', component, path, oldValue)
  26. check_result("CompareComponentProperty - {}".format(path), oldValueCompared)
  27. editor.EditorComponentAPIBus(bus.Broadcast, 'SetComponentProperty', component, path, value)
  28. newObj = editor.EditorComponentAPIBus(bus.Broadcast, 'GetComponentProperty', component, path)
  29. if(newObj.IsSuccess()):
  30. newValue = newObj.GetValue()
  31. newValueCompared = editor.EditorComponentAPIBus(bus.Broadcast, 'CompareComponentProperty', component, path, newValue)
  32. isOldNewValueSame = editor.EditorComponentAPIBus(bus.Broadcast, 'CompareComponentProperty', component, path, oldValue)
  33. result = not(newValue == oldValue and newValueCompared and not isOldNewValueSame)
  34. check_result("GetSetCompareTest - {}".format(path), result)
  35. # Create new Entity
  36. entity_position = math.Vector3(125.0, 136.0, 32.0)
  37. entityId = editor.ToolsApplicationRequestBus(bus.Broadcast, 'CreateNewEntityAtPosition', entity_position, entity.EntityId())
  38. check_result("New entity with no parent created", entityId is not None)
  39. # create a vegetation layer with a box shape and distance filter
  40. typenameList = ["Vegetation Layer Spawner", "Vegetation Asset List", "Box Shape", "Vegetation Distance Between Filter"]
  41. typeIdsList = editor.EditorComponentAPIBus(bus.Broadcast, 'FindComponentTypeIdsByEntityType', typenameList, entity.EntityType().Game)
  42. addComponentsOutcome = editor.EditorComponentAPIBus(bus.Broadcast, 'AddComponentsOfType', entityId, typeIdsList)
  43. check_result("Components added to entity", addComponentsOutcome.IsSuccess())
  44. # fetch the Vegetation Distance Between Filter
  45. vegDistTypeIdList = editor.EditorComponentAPIBus(bus.Broadcast, 'FindComponentTypeIdsByEntityType', ["Vegetation Distance Between Filter"], entity.EntityType().Game)
  46. componentOutcome = editor.EditorComponentAPIBus(bus.Broadcast, 'GetComponentsOfType', entityId, vegDistTypeIdList[0])
  47. check_result('Found Vegetation Distance Between Filter', componentOutcome.IsSuccess())
  48. paths = editor.EditorComponentAPIBus(bus.Broadcast, 'BuildComponentPropertyList', componentOutcome.GetValue()[0])
  49. print(f'Paths = {paths}')
  50. # update the bound box type
  51. pathToBoundMode = "Bound Mode"
  52. GetSetCompareTest(componentOutcome.GetValue()[0], pathToBoundMode, 1)
  53. if __name__ == "__main__":
  54. tester = Editor_ComponentPropertyCommands_enum()
  55. tester.test_case(tester.test)