3
0

AssetSystemStub.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 <Atom/Utils/TestUtils/AssetSystemStub.h>
  9. #include <AzFramework/StringFunc/StringFunc.h>
  10. namespace UnitTest
  11. {
  12. void AssetSystemStub::Activate()
  13. {
  14. m_sourcePath_sourceInfo_map.clear();
  15. m_sourceGuid_sourceInfo_map.clear();
  16. BusConnect();
  17. }
  18. void AssetSystemStub::Deactivate()
  19. {
  20. m_sourcePath_sourceInfo_map.clear();
  21. m_sourceGuid_sourceInfo_map.clear();
  22. BusDisconnect();
  23. }
  24. void AssetSystemStub::RegisterSourceInfo(const AZStd::string& sourcePath, const AZ::Data::AssetId& assetId)
  25. {
  26. AZ::Data::AssetInfo assetInfo;
  27. assetInfo.m_assetId = assetId;
  28. assetInfo.m_relativePath = sourcePath;
  29. RegisterSourceInfo(sourcePath, assetInfo, "");
  30. }
  31. void AssetSystemStub::RegisterSourceInfo(const AZStd::string& sourcePath, const AZ::Data::AssetInfo& assetInfo, const AZStd::string& watchFolder)
  32. {
  33. SourceInfo sourceInfo{ assetInfo, watchFolder };
  34. // Because GetSourceInfoBySourcePath should always return 0 for the sub-id, since it's about the source file not product file.
  35. sourceInfo.m_assetInfo.m_assetId.m_subId = 0;
  36. AZStd::string normalizedSourcePath = sourcePath;
  37. AzFramework::StringFunc::Path::Normalize(normalizedSourcePath);
  38. m_sourcePath_sourceInfo_map.emplace(normalizedSourcePath, sourceInfo);
  39. m_sourceGuid_sourceInfo_map.emplace(assetInfo.m_assetId.m_guid, sourceInfo);
  40. }
  41. void AssetSystemStub::RegisterScanFolder(const AZStd::string& scanFolderPath)
  42. {
  43. AZStd::string normalizedScanFolderPath = scanFolderPath;
  44. AzFramework::StringFunc::Path::Normalize(normalizedScanFolderPath);
  45. m_scanFolders.push_back(normalizedScanFolderPath);
  46. }
  47. bool AssetSystemStub::GetSourceInfoBySourcePath(const char* sourcePath, AZ::Data::AssetInfo& assetInfo, AZStd::string& watchFolder)
  48. {
  49. AZStd::string normalizedSourcePath = sourcePath;
  50. AzFramework::StringFunc::Path::Normalize(normalizedSourcePath);
  51. auto iter = m_sourcePath_sourceInfo_map.find(normalizedSourcePath);
  52. if (iter != m_sourcePath_sourceInfo_map.end())
  53. {
  54. assetInfo = iter->second.m_assetInfo;
  55. watchFolder = iter->second.m_watchFolder;
  56. return true;
  57. }
  58. return false;
  59. }
  60. bool AssetSystemStub::GetRelativeProductPathFromFullSourceOrProductPath([[maybe_unused]] const AZStd::string& fullPath, [[maybe_unused]] AZStd::string& relativeProductPath)
  61. {
  62. return false;
  63. }
  64. bool AssetSystemStub::GenerateRelativeSourcePath(
  65. [[maybe_unused]] const AZStd::string& sourcePath, [[maybe_unused]] AZStd::string& relativePath,
  66. [[maybe_unused]] AZStd::string& watchFolder)
  67. {
  68. AZStd::string normalizedSourcePath = sourcePath;
  69. AzFramework::StringFunc::Path::Normalize(normalizedSourcePath);
  70. auto iter = m_sourcePath_sourceInfo_map.find(normalizedSourcePath);
  71. if (iter != m_sourcePath_sourceInfo_map.end())
  72. {
  73. relativePath = iter->second.m_assetInfo.m_relativePath;
  74. watchFolder = iter->second.m_watchFolder;
  75. return true;
  76. }
  77. return false;
  78. }
  79. bool AssetSystemStub::GetFullSourcePathFromRelativeProductPath(
  80. [[maybe_unused]] const AZStd::string& relPath, [[maybe_unused]] AZStd::string& fullSourcePath)
  81. {
  82. return false;
  83. }
  84. bool AssetSystemStub::GetAssetInfoById([[maybe_unused]] const AZ::Data::AssetId& assetId, [[maybe_unused]] const AZ::Data::AssetType& assetType, [[maybe_unused]] const AZStd::string& platformName, [[maybe_unused]] AZ::Data::AssetInfo& assetInfo, [[maybe_unused]] AZStd::string& rootFilePath)
  85. {
  86. return false;
  87. }
  88. bool AssetSystemStub::GetSourceInfoBySourceUUID(const AZ::Uuid& sourceUuid, AZ::Data::AssetInfo& assetInfo, AZStd::string& watchFolder)
  89. {
  90. auto iter = m_sourceGuid_sourceInfo_map.find(sourceUuid);
  91. if (iter == m_sourceGuid_sourceInfo_map.end())
  92. {
  93. return false;
  94. }
  95. assetInfo = iter->second.m_assetInfo;
  96. watchFolder = iter->second.m_watchFolder;
  97. return true;
  98. }
  99. bool AssetSystemStub::GetScanFolders([[maybe_unused]] AZStd::vector<AZStd::string>& scanFolders)
  100. {
  101. scanFolders = m_scanFolders;
  102. return true;
  103. }
  104. bool AssetSystemStub::GetAssetSafeFolders([[maybe_unused]] AZStd::vector<AZStd::string>& assetSafeFolders)
  105. {
  106. assetSafeFolders = m_scanFolders;
  107. return true;
  108. }
  109. bool AssetSystemStub::IsAssetPlatformEnabled(const char* /*platform*/)
  110. {
  111. return false;
  112. }
  113. int AssetSystemStub::GetPendingAssetsForPlatform(const char* /*platform*/)
  114. {
  115. return 0;
  116. }
  117. bool AssetSystemStub::GetAssetsProducedBySourceUUID(const AZ::Uuid& sourceUuid, AZStd::vector<AZ::Data::AssetInfo>& productsAssetInfo)
  118. {
  119. productsAssetInfo.clear();
  120. for (AZStd::pair<AZStd::string, SourceInfo> element : m_sourcePath_sourceInfo_map)
  121. {
  122. if (element.second.m_assetInfo.m_assetId.m_guid == sourceUuid)
  123. {
  124. productsAssetInfo.push_back(element.second.m_assetInfo);
  125. }
  126. }
  127. return true;
  128. }
  129. }