ConsoleTrack.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 "ConsoleTrack.h"
  10. //////////////////////////////////////////////////////////////////////////
  11. void CConsoleTrack::SerializeKey(IConsoleKey& key, XmlNodeRef& keyNode, bool bLoading)
  12. {
  13. if (bLoading)
  14. {
  15. const char* str;
  16. str = keyNode->getAttr("command");
  17. key.command = str;
  18. }
  19. else
  20. {
  21. if (!key.command.empty())
  22. {
  23. keyNode->setAttr("command", key.command.c_str());
  24. }
  25. }
  26. }
  27. //////////////////////////////////////////////////////////////////////////
  28. void CConsoleTrack::GetKeyInfo(int key, const char*& description, float& duration)
  29. {
  30. assert(key >= 0 && key < (int)m_keys.size());
  31. CheckValid();
  32. description = 0;
  33. duration = 0;
  34. if (!m_keys[key].command.empty())
  35. {
  36. description = m_keys[key].command.c_str();
  37. }
  38. }
  39. //////////////////////////////////////////////////////////////////////////
  40. static bool ConsoleTrackVersionConverter(
  41. AZ::SerializeContext& serializeContext,
  42. AZ::SerializeContext::DataElementNode& rootElement)
  43. {
  44. if (rootElement.GetVersion() < 3)
  45. {
  46. rootElement.AddElement(serializeContext, "BaseClass1", azrtti_typeid<IAnimTrack>());
  47. }
  48. return true;
  49. }
  50. template<>
  51. inline void TAnimTrack<IConsoleKey>::Reflect(AZ::ReflectContext* context)
  52. {
  53. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  54. {
  55. serializeContext->Class<TAnimTrack<IConsoleKey>, IAnimTrack>()
  56. ->Version(3, &ConsoleTrackVersionConverter)
  57. ->Field("Flags", &TAnimTrack<IConsoleKey>::m_flags)
  58. ->Field("Range", &TAnimTrack<IConsoleKey>::m_timeRange)
  59. ->Field("ParamType", &TAnimTrack<IConsoleKey>::m_nParamType)
  60. ->Field("Keys", &TAnimTrack<IConsoleKey>::m_keys)
  61. ->Field("Id", &TAnimTrack<IConsoleKey>::m_id);
  62. }
  63. }
  64. //////////////////////////////////////////////////////////////////////////
  65. void CConsoleTrack::Reflect(AZ::ReflectContext* context)
  66. {
  67. TAnimTrack<IConsoleKey>::Reflect(context);
  68. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  69. {
  70. serializeContext->Class<CConsoleTrack, TAnimTrack<IConsoleKey> >()
  71. ->Version(1);
  72. }
  73. }