Config_wwise.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 <Config_wwise.h>
  9. #include <AzCore/Component/ComponentApplicationBus.h>
  10. #include <AzCore/IO/Path/Path.h>
  11. #include <AzCore/Serialization/Json/JsonSerialization.h>
  12. #include <AzCore/Serialization/Json/JsonUtils.h>
  13. #include <AzCore/Serialization/SerializeContext.h>
  14. // For AZ_Printf statements...
  15. #define WWISE_CONFIG_WINDOW "WwiseConfig"
  16. namespace Audio::Wwise
  17. {
  18. static AZStd::string_view s_configuredBanksPath = DefaultBanksPath;
  19. const AZStd::string_view GetBanksRootPath()
  20. {
  21. return s_configuredBanksPath;
  22. }
  23. void SetBanksRootPath(const AZStd::string_view path)
  24. {
  25. s_configuredBanksPath = path;
  26. }
  27. // static
  28. void ConfigurationSettings::Reflect(AZ::ReflectContext* context)
  29. {
  30. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  31. {
  32. serializeContext->Class<PlatformMapping>()
  33. ->Version(2)
  34. ->Field("assetPlatform", &PlatformMapping::m_assetPlatform)
  35. ->Field("altAssetPlatform", &PlatformMapping::m_altAssetPlatform)
  36. ->Field("enginePlatform", &PlatformMapping::m_enginePlatform)
  37. ->Field("wwisePlatform", &PlatformMapping::m_wwisePlatform)
  38. ->Field("bankSubPath", &PlatformMapping::m_bankSubPath)
  39. ;
  40. serializeContext->Class<ConfigurationSettings>()
  41. ->Version(1)
  42. ->Field("platformMaps", &ConfigurationSettings::m_platformMappings)
  43. ;
  44. }
  45. }
  46. bool ConfigurationSettings::Load(const AZStd::string& filePath)
  47. {
  48. AZ::IO::Path fileIoPath(filePath);
  49. auto outcome = AZ::JsonSerializationUtils::ReadJsonFile(fileIoPath.Native());
  50. if (!outcome)
  51. {
  52. AZ_Printf(WWISE_CONFIG_WINDOW, "ERROR: %s\n", outcome.GetError().c_str());
  53. return false;
  54. }
  55. m_platformMappings.clear();
  56. AZ::JsonDeserializerSettings deserializeSettings;
  57. AZ::ComponentApplicationBus::BroadcastResult(deserializeSettings.m_serializeContext, &AZ::ComponentApplicationBus::Events::GetSerializeContext);
  58. auto result = AZ::JsonSerialization::Load(*this, outcome.GetValue(), deserializeSettings);
  59. if (result.GetProcessing() != AZ::JsonSerializationResult::Processing::Completed)
  60. {
  61. AZ_Printf(WWISE_CONFIG_WINDOW, "ERROR: Deserializing Json file '%s'\n", filePath.c_str());
  62. return false;
  63. }
  64. AZ_Printf(WWISE_CONFIG_WINDOW, "Loaded '%s' successfully.\n", filePath.c_str());
  65. return true;
  66. }
  67. bool ConfigurationSettings::Save(const AZStd::string& filePath)
  68. {
  69. AZ::JsonSerializerSettings serializeSettings;
  70. AZ::ComponentApplicationBus::BroadcastResult(serializeSettings.m_serializeContext, &AZ::ComponentApplicationBus::Events::GetSerializeContext);
  71. rapidjson::Document jsonDoc;
  72. auto result = AZ::JsonSerialization::Store(jsonDoc, jsonDoc.GetAllocator(), *this, serializeSettings);
  73. if (result.GetProcessing() != AZ::JsonSerializationResult::Processing::Completed)
  74. {
  75. AZ_Printf(WWISE_CONFIG_WINDOW, "ERROR: Serializing Json file '%s'\n", filePath.c_str());
  76. return false;
  77. }
  78. auto outcome = AZ::JsonSerializationUtils::WriteJsonFile(jsonDoc, filePath);
  79. if (!outcome)
  80. {
  81. AZ_Printf(WWISE_CONFIG_WINDOW, "ERROR: %s\n", outcome.GetError().c_str());
  82. return false;
  83. }
  84. AZ_Printf(WWISE_CONFIG_WINDOW, "Saved '%s' successfully.\n", filePath.c_str());
  85. return true;
  86. }
  87. } // namespace Audio::Wwise