ScriptCanvasAssetHelpers.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 <Editor/Assets/ScriptCanvasAssetHelpers.h>
  9. #include <ScriptCanvas/Bus/EditorScriptCanvasBus.h>
  10. namespace ScriptCanvasEditor
  11. {
  12. namespace AssetHelpers
  13. {
  14. // Simplified function to trace messages
  15. void PrintInfo(const char* format, ...)
  16. {
  17. // TODO: Turn into something nice with enable_if
  18. static bool s_enabled = false;
  19. if (s_enabled)
  20. {
  21. char sBuffer[1024];
  22. va_list ArgList;
  23. va_start(ArgList, format);
  24. azvsnprintf(sBuffer, sizeof(sBuffer), format, ArgList);
  25. sBuffer[sizeof(sBuffer) - 1] = '\0';
  26. va_end(ArgList);
  27. AZ_TracePrintf("Script Canvas", "%s\n", sBuffer);
  28. }
  29. }
  30. // Given the full path to the asset, attempt to get the AssetInfo
  31. bool GetSourceInfo(AZStd::string_view fullPath, AZ::Data::AssetInfo& outAssetInfo)
  32. {
  33. AZStd::string watchFolder;
  34. AZ::Data::AssetInfo catalogAssetInfo;
  35. bool sourceInfoFound{};
  36. AzToolsFramework::AssetSystemRequestBus::BroadcastResult(sourceInfoFound, &AzToolsFramework::AssetSystemRequestBus::Events::GetSourceInfoBySourcePath, fullPath.data(), catalogAssetInfo, watchFolder);
  37. if (sourceInfoFound)
  38. {
  39. outAssetInfo = catalogAssetInfo;
  40. return true;
  41. }
  42. return false;
  43. }
  44. AZ::Data::AssetInfo GetSourceInfo(const AZStd::string& sourceFilePath, AZStd::string& watchFolder)
  45. {
  46. AZ::Data::AssetInfo assetInfo;
  47. AzToolsFramework::AssetSystemRequestBus::Broadcast(&AzToolsFramework::AssetSystemRequestBus::Events::GetSourceInfoBySourcePath, sourceFilePath.c_str(), assetInfo, watchFolder);
  48. return assetInfo;
  49. }
  50. AZ::Data::AssetInfo GetSourceInfoByProductId(AZ::Data::AssetId assetId, AZ::Data::AssetType assetType)
  51. {
  52. AzToolsFramework::AssetSystemRequestBus::Events* assetSystem = AzToolsFramework::AssetSystemRequestBus::FindFirstHandler();
  53. if (assetSystem == nullptr)
  54. {
  55. return AZ::Data::AssetInfo();
  56. }
  57. AZStd::string watchFolder;
  58. AZ::Data::AssetInfo assetInfo;
  59. const AZStd::string platformName = ""; // Empty for default
  60. if (!assetSystem->GetAssetInfoById(assetId, assetType, platformName, assetInfo, watchFolder))
  61. {
  62. return AZ::Data::AssetInfo();
  63. }
  64. return assetInfo;
  65. }
  66. void DumpAssetInfo(AZ::Data::AssetId assetId, [[maybe_unused]] const char* extra)
  67. {
  68. static bool s_enabled = false;
  69. if (!s_enabled)
  70. {
  71. return;
  72. }
  73. AZ::Data::AssetInfo assetInfo = GetSourceInfoByProductId(assetId, {});
  74. if (assetInfo.m_assetId.IsValid())
  75. {
  76. AZ_TracePrintf("Script Canvas", "-------------------------------------\n");
  77. AZ_TracePrintf("Script Canvas", "AssetId: %s", AssetIdToString(assetId).c_str());
  78. AZ_TracePrintf("Script Canvas", AZStd::string::format("AssetType: %s", assetInfo.m_assetType.ToString<AZStd::string>().c_str()).c_str());
  79. AZ_TracePrintf("Script Canvas", AZStd::string::format("RelativePath: %s", assetInfo.m_relativePath.c_str()).c_str());
  80. AZ_TracePrintf("Script Canvas", AZStd::string::format("Size in Byes: %llu", assetInfo.m_sizeBytes).c_str());
  81. AZ_TracePrintf("Script Canvas", AZStd::string::format("%s\n", extra).c_str());
  82. AZ_TracePrintf("Script Canvas", "-------------------------------------\n");
  83. }
  84. else
  85. {
  86. AZ_TracePrintf("Script Canvas", "Cannot DumpAssetInfo for Asset with ID: %s\n", AssetIdToString(assetId).c_str());
  87. }
  88. }
  89. bool IsValidSourceFile(const AZStd::string& filePath, [[maybe_unused]] ScriptCanvas::ScriptCanvasId scriptCanvasId)
  90. {
  91. return AZ::StringFunc::EndsWith(filePath, ScriptCanvasEditor::SourceDescription::GetFileExtension(), false);
  92. }
  93. }
  94. }