Files
o3de/Gems/Atom/RPI/Code/Tests/Common/AssetSystemStub.cpp
T
Mike Balfour 6c17c7bfb3 Add new API to convert absolute source paths to relative paths. (#930)
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.
2021-05-26 15:30:21 -05:00

131 lines
4.2 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.
*
*/
#include <Common/AssetSystemStub.h>
namespace UnitTest
{
void AssetSystemStub::Activate()
{
m_sourceInfoMap.clear();
BusConnect();
}
void AssetSystemStub::Deactivate()
{
m_sourceInfoMap.clear();
BusDisconnect();
}
void AssetSystemStub::RegisterSourceInfo(const char* sourcePath, const AZ::Data::AssetId& assetId)
{
AZ::Data::AssetInfo assetInfo;
assetInfo.m_assetId = assetId;
RegisterSourceInfo(sourcePath, assetInfo, "");
}
void AssetSystemStub::RegisterSourceInfo(const char* sourcePath, const AZ::Data::AssetInfo& assetInfo, const AZStd::string& watchFolder)
{
SourceInfo sourceInfo{ assetInfo , watchFolder };
// Because GetSourceInfoBySourcePath should always return 0 for the sub-id, since it's about the source file not product file.
sourceInfo.m_assetInfo.m_assetId.m_subId = 0;
m_sourceInfoMap.emplace(sourcePath, sourceInfo);
}
bool AssetSystemStub::GetSourceInfoBySourcePath(const char* sourcePath, AZ::Data::AssetInfo& assetInfo, AZStd::string& watchFolder)
{
auto iter = m_sourceInfoMap.find(sourcePath);
if (iter != m_sourceInfoMap.end())
{
assetInfo = iter->second.m_assetInfo;
watchFolder = iter->second.m_watchFolder;
return true;
}
return false;
}
const char* AssetSystemStub::GetAbsoluteDevGameFolderPath()
{
return nullptr;
}
const char* AssetSystemStub::GetAbsoluteDevRootFolderPath()
{
return nullptr;
}
bool AssetSystemStub::GetRelativeProductPathFromFullSourceOrProductPath([[maybe_unused]] const AZStd::string& fullPath, [[maybe_unused]] AZStd::string& relativeProductPath)
{
return false;
}
bool AssetSystemStub::GenerateRelativeSourcePath(
[[maybe_unused]] const AZStd::string& sourcePath, [[maybe_unused]] AZStd::string& relativePath,
[[maybe_unused]] AZStd::string& watchFolder)
{
return false;
}
bool AssetSystemStub::GetFullSourcePathFromRelativeProductPath(
[[maybe_unused]] const AZStd::string& relPath, [[maybe_unused]] AZStd::string& fullSourcePath)
{
return false;
}
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)
{
return false;
}
bool AssetSystemStub::GetSourceInfoBySourceUUID([[maybe_unused]] const AZ::Uuid& sourceUuid, [[maybe_unused]] AZ::Data::AssetInfo& assetInfo, [[maybe_unused]] AZStd::string& watchFolder)
{
return false;
}
bool AssetSystemStub::GetScanFolders([[maybe_unused]] AZStd::vector<AZStd::string>& scanFolders)
{
return false;
}
bool AssetSystemStub::GetAssetSafeFolders([[maybe_unused]] AZStd::vector<AZStd::string>& assetSafeFolders)
{
return false;
}
bool AssetSystemStub::IsAssetPlatformEnabled(const char* /*platform*/)
{
return false;
}
int AssetSystemStub::GetPendingAssetsForPlatform(const char* /*platform*/)
{
return 0;
}
bool AssetSystemStub::GetAssetsProducedBySourceUUID(const AZ::Uuid& sourceUuid, AZStd::vector<AZ::Data::AssetInfo>& productsAssetInfo)
{
productsAssetInfo.clear();
for (AZStd::pair<AZStd::string, SourceInfo> element : m_sourceInfoMap)
{
if (element.second.m_assetInfo.m_assetId.m_guid == sourceUuid)
{
productsAssetInfo.push_back(element.second.m_assetInfo);
}
}
return true;
}
}