First version of the slice-to-prefab converter

It converts .slice and .ly files to .prefab files, but doesn't handle nested or complicated slices correctly yet.
This commit is contained in:
Mike Balfour
2021-05-14 11:18:15 -05:00
committed by GitHub
parent 5cc0cc9ee7
commit 77278a0329
9 changed files with 358 additions and 15 deletions
+22 -10
View File
@@ -209,30 +209,42 @@ namespace AZ::SerializeContextTools
return result;
}
bool Utilities::InspectSerializedFile(const AZStd::string& filePath, SerializeContext* sc, const ObjectStream::ClassReadyCB& classCallback)
bool Utilities::InspectSerializedFile(const char* filePath, SerializeContext* sc, const ObjectStream::ClassReadyCB& classCallback)
{
if (!AZ::IO::SystemFile::Exists(filePath.c_str()))
if (!AZ::IO::FileIOBase::GetInstance()->Exists(filePath))
{
AZ_Error("Verify", false, "Unable to open file '%s' as it doesn't exist.", filePath.c_str());
AZ_Error("Verify", false, "Unable to open file '%s' as it doesn't exist.", filePath);
return false;
}
u64 fileLength = AZ::IO::SystemFile::Length(filePath.c_str());
if (fileLength == 0)
AZ::IO::HandleType fileHandle;
auto openResult = AZ::IO::FileIOBase::GetInstance()->Open(filePath, AZ::IO::OpenMode::ModeRead, fileHandle);
if (!openResult)
{
AZ_Error("Verify", false, "File '%s' doesn't have content.", filePath.c_str());
AZ_Error("Verify", false, "File '%s' could not be opened.", filePath);
return false;
}
u64 fileLength = 0;
auto sizeResult = AZ::IO::FileIOBase::GetInstance()->Size(fileHandle, fileLength);
if (!sizeResult || (fileLength == 0))
{
AZ_Error("Verify", false, "File '%s' doesn't have content.", filePath);
return false;
}
AZStd::vector<u8> data;
data.resize_no_construct(fileLength);
u64 bytesRead = AZ::IO::SystemFile::Read(filePath.c_str(), data.data());
if (bytesRead != fileLength)
u64 bytesRead = 0;
auto readResult = AZ::IO::FileIOBase::GetInstance()->Read(fileHandle, data.data(), fileLength, true, &bytesRead);
if (!readResult || (bytesRead != fileLength))
{
AZ_Error("Verify", false, "Unable to read file '%s'.", filePath.c_str());
AZ_Error("Verify", false, "Unable to read file '%s'.", filePath);
return false;
}
AZ::IO::FileIOBase::GetInstance()->Close(fileHandle);
AZ::IO::MemoryStream stream(data.data(), fileLength);
ObjectStream::FilterDescriptor filter;
@@ -241,7 +253,7 @@ namespace AZ::SerializeContextTools
filter.m_assetCB = AZ::Data::AssetFilterNoAssetLoading;
if (!ObjectStream::LoadBlocking(&stream, *sc, classCallback, filter))
{
AZ_Printf("Verify", "Failed to deserialize '%s'\n", filePath.c_str());
AZ_Printf("Verify", "Failed to deserialize '%s'\n", filePath);
return false;
}
return true;