浏览代码

Simplified logic for finding absolute path from a given source relative path

Signed-off-by: Chris Galvan <[email protected]>
Chris Galvan 3 年之前
父节点
当前提交
0cd6d8f92e

+ 0 - 2
Code/Framework/AzCore/AzCore/Serialization/EditContextConstants.inl

@@ -136,8 +136,6 @@ namespace AZ
             const static AZ::Crc32 ShowProductAssetFileName = AZ_CRC("ShowProductAssetFileName");
             const static AZ::Crc32 ShowProductAssetFileName = AZ_CRC("ShowProductAssetFileName");
             //! Regular expression pattern filter for source files
             //! Regular expression pattern filter for source files
             const static AZ::Crc32 SourceAssetFilterPattern = AZ_CRC_CE("SourceAssetFilterPattern");
             const static AZ::Crc32 SourceAssetFilterPattern = AZ_CRC_CE("SourceAssetFilterPattern");
-            //! Extension for a product asset to search for
-            const static AZ::Crc32 ProductAssetExtension = AZ_CRC_CE("ProductAssetExtension");
 
 
             //! Component icon attributes
             //! Component icon attributes
             const static AZ::Crc32 Icon = AZ_CRC("Icon", 0x659429db);
             const static AZ::Crc32 Icon = AZ_CRC("Icon", 0x659429db);

+ 9 - 15
Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/PropertyFilePathCtrl.cpp

@@ -26,22 +26,21 @@ AZ_POP_DISABLE_WARNING
 
 
 namespace AzToolsFramework
 namespace AzToolsFramework
 {
 {
-    AZ::IO::Path GetAbsolutePathFromRelativePath(const AZ::IO::Path& relativePath, const AZStd::string& productExtension)
+    AZ::IO::Path GetAbsolutePathFromRelativePath(const AZ::IO::Path& relativePath)
     {
     {
-        // The GetFullSourcePathFromRelativeProductPath API only works on product paths,
-        // so we need to append the product extension to try and find it
-        AZStd::string productRelativePath = relativePath.Native() + productExtension;
-
-        AZStd::string fullPath;
+        // First check if this source relative path already exists and is in an asset safe folder
+        AZ::Data::AssetInfo info;
+        AZStd::string watchFolder;
         bool fullPathIsValid = false;
         bool fullPathIsValid = false;
-        AssetSystemRequestBus::BroadcastResult(
-            fullPathIsValid, &AssetSystemRequestBus::Events::GetFullSourcePathFromRelativeProductPath, productRelativePath, fullPath);
+        AzToolsFramework::AssetSystemRequestBus::BroadcastResult(
+            fullPathIsValid, &AzToolsFramework::AssetSystemRequestBus::Events::GetSourceInfoBySourcePath, relativePath.c_str(), info,
+            watchFolder);
 
 
         // The full source path asset exists on disk, so use that as
         // The full source path asset exists on disk, so use that as
         // the pre-selected file when the user opens the file picker dialog
         // the pre-selected file when the user opens the file picker dialog
         if (fullPathIsValid)
         if (fullPathIsValid)
         {
         {
-            return fullPath;
+            return AZ::IO::Path(watchFolder) / relativePath;
         }
         }
         // GetFullSourcePathFromRelativeProductPath failed so the file doesn't exist on disk yet
         // GetFullSourcePathFromRelativeProductPath failed so the file doesn't exist on disk yet
         // So we need to find it by searching in the asset safe folders
         // So we need to find it by searching in the asset safe folders
@@ -129,11 +128,6 @@ namespace AzToolsFramework
         m_filter = filter;
         m_filter = filter;
     }
     }
 
 
-    void PropertyFilePathCtrl::SetProductExtension(AZStd::string extension)
-    {
-        m_productExtension = AZStd::move(extension);
-    }
-
     void PropertyFilePathCtrl::SetDefaultFileName(AZ::IO::Path fileName)
     void PropertyFilePathCtrl::SetDefaultFileName(AZ::IO::Path fileName)
     {
     {
         m_defaultFileName = AZStd::move(fileName);
         m_defaultFileName = AZStd::move(fileName);
@@ -178,7 +172,7 @@ namespace AzToolsFramework
         // that is stored
         // that is stored
         else
         else
         {
         {
-            auto absolutePath = GetAbsolutePathFromRelativePath(m_currentFilePath, m_productExtension);
+            auto absolutePath = GetAbsolutePathFromRelativePath(m_currentFilePath);
             preselectedFilePath = QString::fromUtf8(absolutePath.c_str(), static_cast<int>(absolutePath.Native().size()));
             preselectedFilePath = QString::fromUtf8(absolutePath.c_str(), static_cast<int>(absolutePath.Native().size()));
         }
         }
 
 

+ 1 - 3
Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/PropertyFilePathCtrl.h

@@ -26,7 +26,7 @@ namespace AzQtComponents
 namespace AzToolsFramework
 namespace AzToolsFramework
 {
 {
     //! Helper method to retrieve an absolute path given a relative source path
     //! Helper method to retrieve an absolute path given a relative source path
-    AZ::IO::Path GetAbsolutePathFromRelativePath(const AZ::IO::Path& relativePath, const AZStd::string& productExtension);
+    AZ::IO::Path GetAbsolutePathFromRelativePath(const AZ::IO::Path& relativePath);
 
 
     //! A control for representing an AZ::IO::Path field with
     //! A control for representing an AZ::IO::Path field with
     //! a BrowseEdit whose popup button triggers a native
     //! a BrowseEdit whose popup button triggers a native
@@ -41,7 +41,6 @@ namespace AzToolsFramework
 
 
         const AZ::IO::Path& GetFilePath() const;
         const AZ::IO::Path& GetFilePath() const;
         void SetFilter(const QString& filter);
         void SetFilter(const QString& filter);
-        void SetProductExtension(AZStd::string extension);
         void SetDefaultFileName(AZ::IO::Path fileName);
         void SetDefaultFileName(AZ::IO::Path fileName);
 
 
     Q_SIGNALS:
     Q_SIGNALS:
@@ -54,7 +53,6 @@ namespace AzToolsFramework
         AzQtComponents::BrowseEdit* m_browseEdit = nullptr;
         AzQtComponents::BrowseEdit* m_browseEdit = nullptr;
         AZ::IO::Path m_currentFilePath;
         AZ::IO::Path m_currentFilePath;
         QString m_filter;
         QString m_filter;
-        AZStd::string m_productExtension;
         AZ::IO::Path m_defaultFileName;
         AZ::IO::Path m_defaultFileName;
 
 
         void OnOpenButtonClicked();
         void OnOpenButtonClicked();

+ 2 - 2
Gems/GradientSignal/Code/Source/Editor/EditorGradientBakerComponent.cpp

@@ -8,6 +8,7 @@
 
 
 #include "EditorGradientBakerComponent.h"
 #include "EditorGradientBakerComponent.h"
 
 
+#include <AzToolsFramework/API/EditorAssetSystemAPI.h>
 #include <AzToolsFramework/UI/PropertyEditor/PropertyFilePathCtrl.h>
 #include <AzToolsFramework/UI/PropertyEditor/PropertyFilePathCtrl.h>
 #include <GradientSignal/Ebuses/GradientPreviewRequestBus.h>
 #include <GradientSignal/Ebuses/GradientPreviewRequestBus.h>
 
 
@@ -77,7 +78,6 @@ namespace GradientSignal
                         AZ::Edit::UIHandlers::Default, &GradientBakerConfig::m_outputImagePath, "Output Path",
                         AZ::Edit::UIHandlers::Default, &GradientBakerConfig::m_outputImagePath, "Output Path",
                         "Output path to bake the image to.")
                         "Output path to bake the image to.")
                     ->Attribute(AZ::Edit::Attributes::SourceAssetFilterPattern, GetSupportedImagesFilter())
                     ->Attribute(AZ::Edit::Attributes::SourceAssetFilterPattern, GetSupportedImagesFilter())
-                    ->Attribute(AZ::Edit::Attributes::ProductAssetExtension, ".streamingimage")
                     ->Attribute(AZ::Edit::Attributes::DefaultAsset, "baked_output_gsi")
                     ->Attribute(AZ::Edit::Attributes::DefaultAsset, "baked_output_gsi")
                     ;
                     ;
             }
             }
@@ -217,7 +217,7 @@ namespace GradientSignal
         }
         }
 
 
         // Get the absolute path for our stored relative path
         // Get the absolute path for our stored relative path
-        AZ::IO::Path fullPathIO = AzToolsFramework::GetAbsolutePathFromRelativePath(m_configuration.m_outputImagePath, ".streamingimage");
+        AZ::IO::Path fullPathIO = AzToolsFramework::GetAbsolutePathFromRelativePath(m_configuration.m_outputImagePath);
 
 
         // Get the actual resolution of our image.  Note that this might be non-square, depending on how the window is sized.
         // Get the actual resolution of our image.  Note that this might be non-square, depending on how the window is sized.
         const int imageResolutionX = aznumeric_cast<int>(m_configuration.m_outputResolution.GetX());
         const int imageResolutionX = aznumeric_cast<int>(m_configuration.m_outputResolution.GetX());