ComponentUpdateListProperty_test_case.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. """
  2. All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
  3. its licensors.
  4. For complete copyright and license terms please see the LICENSE at the root of this
  5. distribution (the "License"). All use of this software is governed by the License,
  6. or, if provided, by the license below or the license accompanying this file. Do not
  7. remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. """
  10. import azlmbr.object as object
  11. import azlmbr.legacy.general as general
  12. import azlmbr.editor as editor
  13. import azlmbr.bus as bus
  14. import azlmbr.entity as entity
  15. import azlmbr.math as math
  16. import azlmbr.asset as asset
  17. def add_component_with_uuid(entityId, typeId):
  18. componentOutcome = editor.EditorComponentAPIBus(bus.Broadcast, 'AddComponentsOfType', entityId, [typeId])
  19. if (componentOutcome.IsSuccess()):
  20. return componentOutcome.GetValue()[0]
  21. def set_component_property(component, path, value):
  22. outcome = editor.EditorComponentAPIBus(bus.Broadcast, 'SetComponentProperty', component, path, value)
  23. return outcome.IsSuccess()
  24. def get_component_property(component, path):
  25. outcome = editor.EditorComponentAPIBus(bus.Broadcast, 'GetComponentProperty', component, path)
  26. if (outcome.IsSuccess()):
  27. return outcome.GetValue()
  28. return None
  29. try:
  30. # Open a level
  31. print ('Test started')
  32. general.open_level_no_prompt('auto_test')
  33. newEntityId = editor.ToolsApplicationRequestBus(bus.Broadcast, 'CreateNewEntity', entity.EntityId())
  34. editorDescriptorListComponentId = math.Uuid_CreateString('{3AF9BE58-6D2D-44FB-AB4D-CA1182F6C78F}', 0)
  35. descListComponent = add_component_with_uuid(newEntityId, editorDescriptorListComponentId)
  36. print ('descListComponent added')
  37. primitiveCubeId = asset.AssetCatalogRequestBus(bus.Broadcast, 'GetAssetIdByPath', 'objects/default/primitive_cube.cgf', math.Uuid(), False)
  38. primitiveSphereId = asset.AssetCatalogRequestBus(bus.Broadcast, 'GetAssetIdByPath', 'objects/default/primitive_sphere.cgf', math.Uuid(), False)
  39. primitiveCapsuleId = asset.AssetCatalogRequestBus(bus.Broadcast, 'GetAssetIdByPath', 'objects/default/primitive_capsule.cgf', math.Uuid(), False)
  40. primitivePlaneId = asset.AssetCatalogRequestBus(bus.Broadcast, 'GetAssetIdByPath', 'objects/default/primitive_plane.cgf', math.Uuid(), False)
  41. print ('fetched asset ids')
  42. # expand the list of veg descriptors to 4 elements
  43. descList = get_component_property(descListComponent, 'Configuration|Embedded Assets')
  44. print('Got the veg descriptor list')
  45. descElem = descList[0]
  46. descList.append(descElem)
  47. descList.append(descElem)
  48. descList.append(descElem)
  49. set_component_property(descListComponent, 'Configuration|Embedded Assets', descList)
  50. print('Set EditorDescriptorListComponent Embedded Assets as List')
  51. set_component_property(descListComponent, 'Configuration|Embedded Assets|[0]|Instance|Mesh Asset', primitiveCubeId)
  52. print('Set EditorDescriptorListComponent Embedded Assets 0 Descriptor Mesh Asset ID')
  53. set_component_property(descListComponent, 'Configuration|Embedded Assets|[1]|Instance|Mesh Asset', primitiveSphereId)
  54. print('Set EditorDescriptorListComponent Embedded Assets 1 Descriptor Mesh Asset ID')
  55. set_component_property(descListComponent, 'Configuration|Embedded Assets|[2]|Instance|Mesh Asset', primitiveCapsuleId)
  56. print('Set EditorDescriptorListComponent Embedded Assets 2 Descriptor Mesh Asset ID')
  57. set_component_property(descListComponent, 'Configuration|Embedded Assets|[3]|Instance|Mesh Asset', primitivePlaneId)
  58. print('Set EditorDescriptorListComponent Embedded Assets 3 Descriptor Mesh Asset ID')
  59. except:
  60. print ('Test failed.')
  61. finally:
  62. print ('Test done.')
  63. general.exit_no_prompt()