EditorCOmponent build pipeline WIP

Signed-off-by: chcurran <82187351+carlitosan@users.noreply.github.com>
This commit is contained in:
chcurran
2021-11-22 20:34:11 -08:00
parent 205b2c27ee
commit 24b3167d48
12 changed files with 233 additions and 160 deletions
@@ -22,18 +22,26 @@
#include <ScriptCanvas/Bus/ScriptCanvasBus.h>
#include <ScriptCanvas/Components/EditorGraph.h>
#include <ScriptCanvas/Core/SerializationListener.h>
#include <ScriptCanvas/Asset/RuntimeAsset.h>
namespace ScriptCanvasFileHandlingCpp
{
using namespace ScriptCanvas;
void AppendTabs(AZStd::string& result, size_t depth)
{
for (size_t i = 0; i < depth; ++i)
{
result += "\t";
}
}
void CollectNodes(const GraphData::NodeContainer& container, SerializationListeners& listeners)
void CollectNodes(const ScriptCanvas::GraphData::NodeContainer& container, ScriptCanvas::SerializationListeners& listeners)
{
for (auto& nodeEntity : container)
{
if (nodeEntity)
{
if (auto listener = azrtti_cast<SerializationListener*>(AZ::EntityUtils::FindFirstDerivedComponent<Node>(nodeEntity)))
if (auto listener = azrtti_cast<ScriptCanvas::SerializationListener*>
( AZ::EntityUtils::FindFirstDerivedComponent<ScriptCanvas::Node>(nodeEntity)))
{
listeners.push_back(listener);
}
@@ -44,6 +52,38 @@ namespace ScriptCanvasFileHandlingCpp
namespace ScriptCanvasEditor
{
EditorAssetTree* EditorAssetTree::ModRoot()
{
if (!m_parent)
{
return this;
}
return m_parent->ModRoot();
}
void EditorAssetTree::SetParent(EditorAssetTree& parent)
{
m_parent = &parent;
}
AZStd::string EditorAssetTree::ToString(size_t depth) const
{
AZStd::string result;
ScriptCanvasFileHandlingCpp::AppendTabs(result, depth);
result += m_asset.ToString();
depth += m_dependencies.empty() ? 0 : 1;
for (const auto& dependency : m_dependencies)
{
result += "\n";
ScriptCanvasFileHandlingCpp::AppendTabs(result, depth);
result += dependency.ToString(depth);
}
return result;
}
AZ::Outcome<void, AZStd::string> LoadDataFromJson
( ScriptCanvas::ScriptCanvasData& dataTarget
, AZStd::string_view source
@@ -87,6 +127,88 @@ namespace ScriptCanvasEditor
return AZ::Success();
}
AZ::Outcome<EditorAssetTree, AZStd::string> LoadEditorAssetTree(SourceHandle handle, EditorAssetTree* parent)
{
if (!CompleteDescriptionInPlace(handle))
{
return AZ::Failure(AZStd::string::format("LoadEditorAssetTree failed to describe graph from %s", handle.ToString().c_str()));
}
auto loadAssetOutcome = LoadFromFile(handle.Path().c_str());
if (!loadAssetOutcome.IsSuccess())
{
return AZ::Failure(AZStd::string::format("LoadEditorAssetTree failed to load graph from %s: %s"
, handle.ToString().c_str(), loadAssetOutcome.GetError().c_str()));
}
AZStd::vector<SourceHandle> dependentAssets;
auto filterCB = [&dependentAssets](const AZ::Data::AssetFilterInfo& filterInfo)->bool
{
if (filterInfo.m_assetType == azrtti_typeid<ScriptCanvas::SubgraphInterfaceAsset>()
|| filterInfo.m_assetType == azrtti_typeid<ScriptCanvasEditor::ScriptCanvasAsset>())
{
dependentAssets.push_back(SourceHandle(nullptr, filterInfo.m_assetId.m_guid, {}));
}
return true;
};
const auto subgraphInterfaceAssetTypeID = azrtti_typeid<AZ::Data::Asset<ScriptCanvas::SubgraphInterfaceAsset>>();
auto beginElementCB = [&subgraphInterfaceAssetTypeID, &dependentAssets]
( void* instance
, const AZ::SerializeContext::ClassData* classData
, const AZ::SerializeContext::ClassElement* classElement) -> bool
{
if (classElement)
{
// if we are a pointer, then we may be pointing to a derived type.
if (classElement->m_flags & AZ::SerializeContext::ClassElement::FLG_POINTER)
{
// if ptr is a pointer-to-pointer, cast its value to a void* (or const void*) and dereference to get to the actual object pointer.
instance = *(void**)(instance);
}
if (classData->m_typeId == subgraphInterfaceAssetTypeID)
{
auto id = reinterpret_cast<AZ::Data::Asset<ScriptCanvas::SubgraphInterfaceAsset>*>(instance)->GetId();
dependentAssets.push_back(SourceHandle(nullptr, id.m_guid, {}));
}
}
return true;
};
AZ::SerializeContext* serializeContext = nullptr;
AZ::ComponentApplicationBus::BroadcastResult(serializeContext, &AZ::ComponentApplicationRequests::GetSerializeContext);
serializeContext->EnumerateObject( handle.Get(), beginElementCB, nullptr, AZ::SerializeContext::ENUM_ACCESS_FOR_READ);
EditorAssetTree result;
for (auto& dependentAsset : dependentAssets)
{
auto loadDependentOutcome = LoadEditorAssetTree(dependentAsset, &result);
if (!loadDependentOutcome.IsSuccess())
{
return AZ::Failure(AZStd::string::format("LoadEditorAssetTree failed to load graph from %s: %s"
, dependentAsset.ToString().c_str(), loadDependentOutcome.GetError().c_str()));
}
result.m_dependencies.push_back(loadDependentOutcome.TakeValue());
}
if (parent)
{
result.SetParent(*parent);
}
result.m_asset = loadAssetOutcome.TakeValue();
return AZ::Success(result);
}
AZ::Outcome<ScriptCanvasEditor::SourceHandle, AZStd::string> LoadFromFile(AZStd::string_view path)
{
namespace JSRU = AZ::JsonSerializationUtils;
@@ -137,7 +259,7 @@ namespace ScriptCanvasEditor
graph->MarkOwnership(*scriptCanvasData);
}
return AZ::Success(ScriptCanvasEditor::SourceHandle(scriptCanvasData, {}, path));
return AZ::Success(ScriptCanvasEditor::SourceHandle(scriptCanvasData, path));
}
AZ::Outcome<void, AZStd::string> SaveToStream(const SourceHandle& source, AZ::IO::GenericStream& stream)