SelectTrack.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <AzCore/Serialization/SerializeContext.h>
  9. #include "SelectTrack.h"
  10. #include "Maestro/Types/AnimValueType.h"
  11. //////////////////////////////////////////////////////////////////////////
  12. void CSelectTrack::SerializeKey(ISelectKey& key, XmlNodeRef& keyNode, bool bLoading)
  13. {
  14. if (bLoading)
  15. {
  16. const char* szSelection;
  17. szSelection = keyNode->getAttr("node");
  18. key.szSelection = szSelection;
  19. AZ::u64 id64;
  20. if (keyNode->getAttr("CameraAzEntityId", id64))
  21. {
  22. key.cameraAzEntityId = AZ::EntityId(id64);
  23. }
  24. keyNode->getAttr("BlendTime", key.fBlendTime);
  25. }
  26. else
  27. {
  28. keyNode->setAttr("node", key.szSelection.c_str());
  29. if (key.cameraAzEntityId.IsValid())
  30. {
  31. AZ::u64 id64 = static_cast<AZ::u64>(key.cameraAzEntityId);
  32. keyNode->setAttr("CameraAzEntityId", id64);
  33. }
  34. keyNode->setAttr("BlendTime", key.fBlendTime);
  35. }
  36. }
  37. //////////////////////////////////////////////////////////////////////////
  38. AnimValueType CSelectTrack::GetValueType()
  39. {
  40. return AnimValueType::Select;
  41. };
  42. //////////////////////////////////////////////////////////////////////////
  43. void CSelectTrack::GetKeyInfo(int key, const char*& description, float& duration)
  44. {
  45. assert(key >= 0 && key < (int)m_keys.size());
  46. CheckValid();
  47. description = 0;
  48. duration = m_keys[key].fDuration;
  49. if (!m_keys[key].szSelection.empty())
  50. {
  51. description = m_keys[key].szSelection.c_str();
  52. }
  53. }
  54. //////////////////////////////////////////////////////////////////////////
  55. static bool SelectTrackVersionConverter(
  56. AZ::SerializeContext& serializeContext,
  57. AZ::SerializeContext::DataElementNode& rootElement)
  58. {
  59. if (rootElement.GetVersion() < 3)
  60. {
  61. rootElement.AddElement(serializeContext, "BaseClass1", azrtti_typeid<IAnimTrack>());
  62. }
  63. return true;
  64. }
  65. template<>
  66. inline void TAnimTrack<ISelectKey>::Reflect(AZ::ReflectContext* context)
  67. {
  68. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  69. {
  70. serializeContext->Class<TAnimTrack<ISelectKey>, IAnimTrack>()
  71. ->Version(3, &SelectTrackVersionConverter)
  72. ->Field("Flags", &TAnimTrack<ISelectKey>::m_flags)
  73. ->Field("Range", &TAnimTrack<ISelectKey>::m_timeRange)
  74. ->Field("ParamType", &TAnimTrack<ISelectKey>::m_nParamType)
  75. ->Field("Keys", &TAnimTrack<ISelectKey>::m_keys)
  76. ->Field("Id", &TAnimTrack<ISelectKey>::m_id);
  77. }
  78. }
  79. //////////////////////////////////////////////////////////////////////////
  80. void CSelectTrack::Reflect(AZ::ReflectContext* context)
  81. {
  82. TAnimTrack<ISelectKey>::Reflect(context);
  83. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  84. {
  85. serializeContext->Class<CSelectTrack, TAnimTrack<ISelectKey>>()
  86. ->Version(1);
  87. }
  88. }