6c17c7bfb3
There are already APIs for getting a relative product path from an absolute source path, or getting a relative source path for an *existing* source file, but there were no APIs for getting a relative source path for a *new* source file. Prefabs will need this ability to be able to correctly generate a relative source path inside the prefab file before the file has been saved. The logic for relative source paths is a little bit tricky because the paths are relative to the watch folders, and the watch folders can be nested, with different priorities to explain which should take precedence. The input paths can also include specifiers like "." and "..", which need to be reconciled before creating the final correct relative path. The included unit tests test all of the tricky edge cases that I was able to identify.
117 lines
6.9 KiB
C++
117 lines
6.9 KiB
C++
/*
|
|
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
* its licensors.
|
|
*
|
|
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
* distribution (the "License"). All use of this software is governed by the License,
|
|
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
*
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AzCore/Component/TickBus.h>
|
|
#include <AzCore/Outcome/Outcome.h>
|
|
#include <AzCore/Component/Component.h>
|
|
#include <AzFramework/Network/SocketConnection.h>
|
|
#include <AzToolsFramework/API/EditorAssetSystemAPI.h>
|
|
#include <AzToolsFramework/ToolsComponents/ToolsAssetCatalogBus.h>
|
|
|
|
namespace AzToolsFramework
|
|
{
|
|
namespace AssetSystem
|
|
{
|
|
/**
|
|
* A tools level component for interacting with the asset processor
|
|
*
|
|
* Currently used to translate between full and relative asset paths,
|
|
* and to query information about asset processor jobs
|
|
*/
|
|
class AssetSystemComponent
|
|
: public AZ::Component
|
|
, private AzToolsFramework::AssetSystemRequestBus::Handler
|
|
, private AzToolsFramework::AssetSystemJobRequestBus::Handler
|
|
, private AzToolsFramework::AssetSystemBus::Handler
|
|
, private AzToolsFramework::ToolsAssetSystemBus::Handler
|
|
, private AZ::SystemTickBus::Handler
|
|
{
|
|
public:
|
|
AZ_COMPONENT(AssetSystemComponent, "{B1352D59-945B-446A-A7E1-B2D3EB717C6D}")
|
|
|
|
AssetSystemComponent() = default;
|
|
virtual ~AssetSystemComponent() = default;
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
// AZ::Component overrides
|
|
void Init() override {}
|
|
void Activate() override;
|
|
void Deactivate() override;
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
static void Reflect(AZ::ReflectContext* context);
|
|
static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
|
|
static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
|
|
static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
|
|
|
|
private:
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
// AzToolsFramework::AssetSystemRequestBus::Handler overrides
|
|
bool GetAbsoluteAssetDatabaseLocation(AZStd::string& result) override;
|
|
const char* GetAbsoluteDevGameFolderPath() override;
|
|
const char* GetAbsoluteDevRootFolderPath() override;
|
|
bool GetRelativeProductPathFromFullSourceOrProductPath(const AZStd::string& fullPath, AZStd::string& outputPath) override;
|
|
bool GenerateRelativeSourcePath(
|
|
const AZStd::string& sourcePath, AZStd::string& outputPath, AZStd::string& watchFolder) override;
|
|
bool GetFullSourcePathFromRelativeProductPath(const AZStd::string& relPath, AZStd::string& fullPath) override;
|
|
bool GetAssetInfoById(const AZ::Data::AssetId& assetId, const AZ::Data::AssetType& assetType, const AZStd::string& platformName, AZ::Data::AssetInfo& assetInfo, AZStd::string& rootFilePath) override;
|
|
bool GetSourceInfoBySourcePath(const char* sourcePath, AZ::Data::AssetInfo& assetInfo, AZStd::string& watchFolder) override;
|
|
bool GetSourceInfoBySourceUUID(const AZ::Uuid& sourceUuid, AZ::Data::AssetInfo& assetInfo, AZStd::string& watchFolder) override;
|
|
bool GetScanFolders(AZStd::vector<AZStd::string>& scanFolders) override;
|
|
bool GetAssetSafeFolders(AZStd::vector<AZStd::string>& assetSafeFolders) override;
|
|
bool IsAssetPlatformEnabled(const char* platform) override;
|
|
int GetPendingAssetsForPlatform(const char* platform) override;
|
|
bool GetAssetsProducedBySourceUUID(const AZ::Uuid& sourceUuid, AZStd::vector<AZ::Data::AssetInfo>& productsAssetInfo) override;
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
// AzToolsFramework::AssetSystemJobRequest::Bus::Handler overrides
|
|
virtual AZ::Outcome<AssetSystem::JobInfoContainer> GetAssetJobsInfo(const AZStd::string& path, const bool escalateJobs) override;
|
|
virtual AZ::Outcome<JobInfoContainer> GetAssetJobsInfoByAssetID(const AZ::Data::AssetId& assetId, const bool escalateJobs, bool requireFencing) override;
|
|
virtual AZ::Outcome<JobInfoContainer> GetAssetJobsInfoByJobKey(const AZStd::string& jobKey, const bool escalateJobs) override;
|
|
virtual AZ::Outcome<JobStatus> GetAssetJobsStatusByJobKey(const AZStd::string& jobKey, const bool escalateJobs) override;
|
|
virtual AZ::Outcome<AZStd::string> GetJobLog(AZ::u64 jobrunkey) override;
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
// AzToolsFramework::::AssetSystemBus::Handler overrides
|
|
void SourceFileChanged(AZStd::string relativePath, AZStd::string scanFolder, AZ::Uuid sourceUUID) override;
|
|
void SourceFileRemoved(AZStd::string relativePath, AZStd::string scanFolder, AZ::Uuid sourceUUID) override;
|
|
void SourceFileFailed(AZStd::string relativePath, AZStd::string scanFolder, AZ::Uuid sourceUUID) override;
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
// AzToolsFramework::ToolsAssetSystemBus::Handler overrides
|
|
void RegisterSourceAssetType(const AZ::Data::AssetType& assetType, const char* assetFileFilter) override;
|
|
void UnregisterSourceAssetType(const AZ::Data::AssetType& assetType) override;
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
// SystemTickBus::Handler overrides
|
|
void OnSystemTick() override;
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
AzFramework::SocketConnection::TMessageCallbackHandle m_cbHandle = 0;
|
|
AzFramework::SocketConnection::TMessageCallbackHandle m_showAssetBrowserCBHandle = 0;
|
|
AzFramework::SocketConnection::TMessageCallbackHandle m_wantShowAssetBrowserCBHandle = 0;
|
|
|
|
AZStd::unordered_map<AZStd::string, AZStd::string> m_assetSourceRelativePathToFullPathCache;
|
|
};
|
|
|
|
|
|
} // namespace AssetSystem
|
|
} // namespace AzToolsFramework
|
|
|