Merge pull request #1657 from aws-lumberyard-dev/carlitosan/scriptcanvas/prefabs
Initial prefab integrationmain
commit
4c684b1a10
@ -0,0 +1,376 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <AzToolsFramework/API/EditorAssetSystemAPI.h>
|
||||||
|
#include <Builder/ScriptCanvasBuilder.h>
|
||||||
|
#include <Builder/ScriptCanvasBuilderWorker.h>
|
||||||
|
#include <ScriptCanvas/Assets/ScriptCanvasAsset.h>
|
||||||
|
#include <ScriptCanvas/Components/EditorGraphVariableManagerComponent.h>
|
||||||
|
#include <ScriptCanvas/Grammar/AbstractCodeModel.h>
|
||||||
|
|
||||||
|
namespace ScriptCanvasBuilderCpp
|
||||||
|
{
|
||||||
|
void AppendTabs(AZStd::string& result, size_t depth)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < depth; ++i)
|
||||||
|
{
|
||||||
|
result += "\t";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace ScriptCanvasBuilder
|
||||||
|
{
|
||||||
|
void BuildVariableOverrides::Clear()
|
||||||
|
{
|
||||||
|
m_source.Reset();
|
||||||
|
m_variables.clear();
|
||||||
|
m_entityIds.clear();
|
||||||
|
m_dependencies.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void BuildVariableOverrides::CopyPreviousOverriddenValues(const BuildVariableOverrides& source)
|
||||||
|
{
|
||||||
|
for (auto& overriddenValue : m_overrides)
|
||||||
|
{
|
||||||
|
auto iter = AZStd::find_if(source.m_overrides.begin(), source.m_overrides.end(), [&overriddenValue](const auto& candidate) { return candidate.GetVariableId() == overriddenValue.GetVariableId(); });
|
||||||
|
|
||||||
|
if (iter != source.m_overrides.end())
|
||||||
|
{
|
||||||
|
overriddenValue.DeepCopy(*iter);
|
||||||
|
overriddenValue.SetScriptInputControlVisibility(AZ::Edit::PropertyVisibility::Hide);
|
||||||
|
overriddenValue.SetAllowSignalOnChange(false);
|
||||||
|
// check that a name update is not necessary anymore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
// #functions2 provide an identifier for the node/variable in the source that caused the dependency. the root will not have one.
|
||||||
|
// the above will provide the data to handle the cases where only certain dependency nodes were removed
|
||||||
|
// until then we do a sanity check, if any part of the depenecies were altered, assume no overrides are valid.
|
||||||
|
if (m_dependencies.size() != source.m_dependencies.size())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (size_t index = 0; index != m_dependencies.size(); ++index)
|
||||||
|
{
|
||||||
|
if (m_dependencies[index].m_source != source.m_dependencies[index].m_source)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
for (size_t index = 0; index != m_dependencies.size(); ++index)
|
||||||
|
{
|
||||||
|
m_dependencies[index].CopyPreviousOverriddenValues(source.m_dependencies[index]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BuildVariableOverrides::IsEmpty() const
|
||||||
|
{
|
||||||
|
return m_variables.empty() && m_entityIds.empty() && m_dependencies.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
void BuildVariableOverrides::Reflect(AZ::ReflectContext* reflectContext)
|
||||||
|
{
|
||||||
|
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(reflectContext))
|
||||||
|
{
|
||||||
|
serializeContext->Class<BuildVariableOverrides>()
|
||||||
|
->Version(0)
|
||||||
|
->Field("source", &BuildVariableOverrides::m_source)
|
||||||
|
->Field("variables", &BuildVariableOverrides::m_variables)
|
||||||
|
->Field("entityId", &BuildVariableOverrides::m_entityIds)
|
||||||
|
->Field("overrides", &BuildVariableOverrides::m_overrides)
|
||||||
|
->Field("dependencies", &BuildVariableOverrides::m_dependencies)
|
||||||
|
;
|
||||||
|
|
||||||
|
if (auto editContext = serializeContext->GetEditContext())
|
||||||
|
{
|
||||||
|
editContext->Class< BuildVariableOverrides>("Variables", "Variables exposed by the attached Script Canvas Graph")
|
||||||
|
->ClassElement(AZ::Edit::ClassElements::Group, "Variable Fields")
|
||||||
|
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
|
||||||
|
->DataElement(AZ::Edit::UIHandlers::Default, &BuildVariableOverrides::m_overrides, "Variables", "Array of Variables within Script Canvas Graph")
|
||||||
|
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
|
||||||
|
->DataElement(AZ::Edit::UIHandlers::Default, &BuildVariableOverrides::m_dependencies, "Dependencies", "Variables in Dependencies of the Script Canvas Graph")
|
||||||
|
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// use this to initialize the new data, and make sure they have a editor graph variable for proper editor display
|
||||||
|
void BuildVariableOverrides::PopulateFromParsedResults(const ScriptCanvas::Grammar::ParsedRuntimeInputs& inputs, const ScriptCanvas::VariableData& variables)
|
||||||
|
{
|
||||||
|
for (auto& variable : inputs.m_variables)
|
||||||
|
{
|
||||||
|
auto graphVariable = variables.FindVariable(variable.first);
|
||||||
|
if (!graphVariable)
|
||||||
|
{
|
||||||
|
AZ_Error("ScriptCanvasBuilder", false, "Missing Variable from graph data that was just parsed");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_variables.push_back(*graphVariable);
|
||||||
|
auto& buildVariable = m_variables.back();
|
||||||
|
buildVariable.DeepCopy(*graphVariable); // in case of BCO, a new one needs to be created
|
||||||
|
|
||||||
|
// copy to override list for editor display
|
||||||
|
m_overrides.push_back(*graphVariable);
|
||||||
|
auto& overrideValue = m_overrides.back();
|
||||||
|
overrideValue.DeepCopy(*graphVariable);
|
||||||
|
overrideValue.SetScriptInputControlVisibility(AZ::Edit::PropertyVisibility::Hide);
|
||||||
|
overrideValue.SetAllowSignalOnChange(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto& entityId : inputs.m_entityIds)
|
||||||
|
{
|
||||||
|
m_entityIds.push_back(entityId);
|
||||||
|
|
||||||
|
if (!ScriptCanvas::Grammar::IsParserGeneratedId(entityId.first))
|
||||||
|
{
|
||||||
|
auto graphEntityId = variables.FindVariable(entityId.first);
|
||||||
|
if (!graphEntityId)
|
||||||
|
{
|
||||||
|
AZ_Error("ScriptCanvasBuilder", false, "Missing EntityId from graph data that was just parsed");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// copy to override list for editor display
|
||||||
|
if (graphEntityId->IsComponentProperty())
|
||||||
|
{
|
||||||
|
m_overrides.push_back(*graphEntityId);
|
||||||
|
auto& overrideValue = m_overrides.back();
|
||||||
|
overrideValue.SetScriptInputControlVisibility(AZ::Edit::PropertyVisibility::Hide);
|
||||||
|
overrideValue.SetAllowSignalOnChange(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
ScriptCanvasBuilderCpp::AppendTabs(result, depth);
|
||||||
|
result += m_asset.GetId().ToString<AZStd::string>();
|
||||||
|
result += m_asset.GetHint();
|
||||||
|
depth += m_dependencies.empty() ? 0 : 1;
|
||||||
|
|
||||||
|
for (const auto& dependency : m_dependencies)
|
||||||
|
{
|
||||||
|
result += "\n";
|
||||||
|
ScriptCanvasBuilderCpp::AppendTabs(result, depth);
|
||||||
|
result += dependency.ToString(depth);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
ScriptCanvas::RuntimeDataOverrides ConvertToRuntime(const BuildVariableOverrides& buildOverrides)
|
||||||
|
{
|
||||||
|
ScriptCanvas::RuntimeDataOverrides runtimeOverrides;
|
||||||
|
|
||||||
|
runtimeOverrides.m_runtimeAsset = AZ::Data::Asset<ScriptCanvas::RuntimeAsset>
|
||||||
|
(AZ::Data::AssetId(buildOverrides.m_source.GetId().m_guid, AZ_CRC("RuntimeData", 0x163310ae)), azrtti_typeid<ScriptCanvas::RuntimeAsset>(), {});
|
||||||
|
runtimeOverrides.m_runtimeAsset.SetAutoLoadBehavior(AZ::Data::AssetLoadBehavior::PreLoad);
|
||||||
|
runtimeOverrides.m_variableIndices.resize(buildOverrides.m_variables.size());
|
||||||
|
|
||||||
|
for (size_t index = 0; index != buildOverrides.m_variables.size(); ++index)
|
||||||
|
{
|
||||||
|
auto& variable = buildOverrides.m_variables[index];
|
||||||
|
auto iter = AZStd::find_if
|
||||||
|
( buildOverrides.m_overrides.begin()
|
||||||
|
, buildOverrides.m_overrides.end()
|
||||||
|
, [&variable](auto& candidate) { return candidate.GetVariableId() == variable.GetVariableId(); });
|
||||||
|
|
||||||
|
if (iter != buildOverrides.m_overrides.end())
|
||||||
|
{
|
||||||
|
if (iter->GetDatum())
|
||||||
|
{
|
||||||
|
runtimeOverrides.m_variables.push_back(ScriptCanvas::RuntimeVariable(iter->GetDatum()->ToAny()));
|
||||||
|
runtimeOverrides.m_variableIndices[index] = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AZ_Warning("ScriptCanvasBuilder", false, "build overrides missing variable override, Script may not function properly");
|
||||||
|
runtimeOverrides.m_variableIndices[index] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
runtimeOverrides.m_variableIndices[index] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto& entity : buildOverrides.m_entityIds)
|
||||||
|
{
|
||||||
|
auto& variableId = entity.first;
|
||||||
|
auto iter = AZStd::find_if(buildOverrides.m_overrides.begin(), buildOverrides.m_overrides.end(), [&variableId](auto& candidate) { return candidate.GetVariableId() == variableId; });
|
||||||
|
if (iter != buildOverrides.m_overrides.end())
|
||||||
|
{
|
||||||
|
// the entity was overridden on the instance
|
||||||
|
if (iter->GetDatum() && iter->GetDatum()->GetAs<AZ::EntityId>())
|
||||||
|
{
|
||||||
|
runtimeOverrides.m_entityIds.push_back(*iter->GetDatum()->GetAs<AZ::EntityId>());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AZ_Warning("ScriptCanvasBuilder", false, "build overrides missing EntityId, Script may not function properly");
|
||||||
|
runtimeOverrides.m_entityIds.push_back(AZ::EntityId{});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// the entity is overridden, as part of the required process of to instantiation
|
||||||
|
runtimeOverrides.m_entityIds.push_back(entity.second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto& buildDependency : buildOverrides.m_dependencies)
|
||||||
|
{
|
||||||
|
runtimeOverrides.m_dependencies.push_back(ConvertToRuntime(buildDependency));
|
||||||
|
}
|
||||||
|
|
||||||
|
return runtimeOverrides;
|
||||||
|
}
|
||||||
|
|
||||||
|
AZ::Outcome<EditorAssetTree, AZStd::string> LoadEditorAssetTree(AZ::Data::AssetId editorAssetId, AZStd::string_view assetHint, EditorAssetTree* parent)
|
||||||
|
{
|
||||||
|
EditorAssetTree result;
|
||||||
|
AZ::Data::AssetInfo assetInfo;
|
||||||
|
AZStd::string watchFolder;
|
||||||
|
bool resultFound = false;
|
||||||
|
|
||||||
|
if (!AzToolsFramework::AssetSystemRequestBus::FindFirstHandler())
|
||||||
|
{
|
||||||
|
return AZ::Failure(AZStd::string("LoadEditorAssetTree found no handler for AzToolsFramework::AssetSystemRequestBus."));
|
||||||
|
}
|
||||||
|
|
||||||
|
AzToolsFramework::AssetSystemRequestBus::BroadcastResult
|
||||||
|
( resultFound
|
||||||
|
, &AzToolsFramework::AssetSystem::AssetSystemRequest::GetSourceInfoBySourceUUID
|
||||||
|
, editorAssetId.m_guid
|
||||||
|
, assetInfo
|
||||||
|
, watchFolder);
|
||||||
|
|
||||||
|
if (!resultFound)
|
||||||
|
{
|
||||||
|
return AZ::Failure(AZStd::string::format("LoadEditorAssetTree failed to get engine relative path from %s-%.*s.", editorAssetId.ToString<AZStd::string>().c_str(), aznumeric_cast<int>(assetHint.size()), assetHint.data()));
|
||||||
|
}
|
||||||
|
|
||||||
|
AZStd::vector<AZ::Data::AssetId> dependentAssets;
|
||||||
|
|
||||||
|
auto filterCB = [&dependentAssets](const AZ::Data::AssetFilterInfo& filterInfo)->bool
|
||||||
|
{
|
||||||
|
if (filterInfo.m_assetType == azrtti_typeid<ScriptCanvas::SubgraphInterfaceAsset>())
|
||||||
|
{
|
||||||
|
dependentAssets.push_back(AZ::Data::AssetId(filterInfo.m_assetId.m_guid, 0));
|
||||||
|
}
|
||||||
|
else if (filterInfo.m_assetType == azrtti_typeid<ScriptCanvasEditor::ScriptCanvasAsset>())
|
||||||
|
{
|
||||||
|
dependentAssets.push_back(filterInfo.m_assetId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
auto loadAssetOutcome = ScriptCanvasBuilder::LoadEditorAsset(assetInfo.m_relativePath, editorAssetId, filterCB);
|
||||||
|
if (!loadAssetOutcome.IsSuccess())
|
||||||
|
{
|
||||||
|
return AZ::Failure(AZStd::string::format("LoadEditorAssetTree failed to load graph from %s-%s: %s", editorAssetId.ToString<AZStd::string>().c_str(), assetHint.data(), loadAssetOutcome.GetError().c_str()));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto& dependentAsset : dependentAssets)
|
||||||
|
{
|
||||||
|
auto loadDependentOutcome = LoadEditorAssetTree(dependentAsset, "", &result);
|
||||||
|
if (!loadDependentOutcome.IsSuccess())
|
||||||
|
{
|
||||||
|
return AZ::Failure(AZStd::string::format("LoadEditorAssetTree failed to load dependent graph from %s-%s: %s", editorAssetId.ToString<AZStd::string>().c_str(), assetHint.data(), 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<BuildVariableOverrides, AZStd::string> ParseEditorAssetTree(const EditorAssetTree& editorAssetTree)
|
||||||
|
{
|
||||||
|
auto buildEntity = editorAssetTree.m_asset->GetScriptCanvasEntity();
|
||||||
|
if (!buildEntity)
|
||||||
|
{
|
||||||
|
return AZ::Failure(AZStd::string("No entity from source asset"));
|
||||||
|
}
|
||||||
|
|
||||||
|
auto variableComponent = AZ::EntityUtils::FindFirstDerivedComponent<ScriptCanvas::GraphVariableManagerComponent>(buildEntity);
|
||||||
|
if (!variableComponent)
|
||||||
|
{
|
||||||
|
return AZ::Failure(AZStd::string("No GraphVariableManagerComponent in source Entity"));
|
||||||
|
}
|
||||||
|
|
||||||
|
const ScriptCanvas::VariableData* variableData = variableComponent->GetVariableDataConst(); // get this from the entity
|
||||||
|
if (!variableData)
|
||||||
|
{
|
||||||
|
return AZ::Failure(AZStd::string("No variableData in source GraphVariableManagerComponent"));
|
||||||
|
}
|
||||||
|
|
||||||
|
auto parseOutcome = ScriptCanvasBuilder::ParseGraph(*buildEntity, "");
|
||||||
|
if (!parseOutcome.IsSuccess() || !parseOutcome.GetValue())
|
||||||
|
{
|
||||||
|
return AZ::Failure(AZStd::string("graph failed to parse"));
|
||||||
|
}
|
||||||
|
|
||||||
|
BuildVariableOverrides result;
|
||||||
|
result.m_source = editorAssetTree.m_asset;
|
||||||
|
result.PopulateFromParsedResults(parseOutcome.GetValue()->GetRuntimeInputs(), *variableData);
|
||||||
|
|
||||||
|
// recurse...
|
||||||
|
for (auto& dependentAsset : editorAssetTree.m_dependencies)
|
||||||
|
{
|
||||||
|
// #functions2 provide an identifier for the node/variable in the source that caused the dependency. the root will not have one.
|
||||||
|
auto parseDependentOutcome = ParseEditorAssetTree(dependentAsset);
|
||||||
|
if (!parseDependentOutcome.IsSuccess())
|
||||||
|
{
|
||||||
|
return AZ::Failure(AZStd::string::format
|
||||||
|
("ParseEditorAssetTree failed to parse dependent graph from %s-%s: %s"
|
||||||
|
, dependentAsset.m_asset.GetId().ToString<AZStd::string>().c_str()
|
||||||
|
, dependentAsset.m_asset.GetHint().c_str()
|
||||||
|
, parseDependentOutcome.GetError().c_str()));
|
||||||
|
}
|
||||||
|
|
||||||
|
result.m_dependencies.push_back(parseDependentOutcome.TakeValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
return AZ::Success(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <AzCore/Asset/AssetCommon.h>
|
||||||
|
#include <ScriptCanvas/Asset/RuntimeAsset.h>
|
||||||
|
#include <ScriptCanvas/Variable/VariableCore.h>
|
||||||
|
|
||||||
|
namespace ScriptCanvas
|
||||||
|
{
|
||||||
|
namespace Grammar
|
||||||
|
{
|
||||||
|
struct ParsedRuntimeInputs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace ScriptCanvasEditor
|
||||||
|
{
|
||||||
|
class ScriptCanvasAsset;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace ScriptCanvasBuilder
|
||||||
|
{
|
||||||
|
class BuildVariableOverrides
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AZ_TYPE_INFO(BuildVariableOverrides, "{8336D44C-8EDC-4C28-AEB4-3420D5FD5AE2}");
|
||||||
|
AZ_CLASS_ALLOCATOR(BuildVariableOverrides, AZ::SystemAllocator, 0);
|
||||||
|
|
||||||
|
static void Reflect(AZ::ReflectContext* reflectContext);
|
||||||
|
|
||||||
|
void Clear();
|
||||||
|
|
||||||
|
// use this to preserve old values that may have been overridden on the instance, and are still valid in the parsed graph
|
||||||
|
void CopyPreviousOverriddenValues(const BuildVariableOverrides& source);
|
||||||
|
|
||||||
|
bool IsEmpty() const;
|
||||||
|
|
||||||
|
// use this to initialize the new data, and make sure they have a editor graph variable for proper editor display
|
||||||
|
void PopulateFromParsedResults(const ScriptCanvas::Grammar::ParsedRuntimeInputs& inputs, const ScriptCanvas::VariableData& variables);
|
||||||
|
|
||||||
|
// #functions2 provide an identifier for the node/variable in the source that caused the dependency. the root will not have one.
|
||||||
|
AZ::Data::Asset<ScriptCanvasEditor::ScriptCanvasAsset> m_source;
|
||||||
|
|
||||||
|
// all of the variables here are overrides
|
||||||
|
AZStd::vector<ScriptCanvas::GraphVariable> m_variables;
|
||||||
|
// the values here may or may not be overrides
|
||||||
|
AZStd::vector<AZStd::pair<ScriptCanvas::VariableId, AZ::EntityId>> m_entityIds;
|
||||||
|
// this is all that gets exposed to the edit context
|
||||||
|
AZStd::vector<ScriptCanvas::GraphVariable> m_overrides;
|
||||||
|
// AZStd::vector<size_t> m_entityIdRuntimeInputIndices; since all of the entity ids need to go in, they may not need indices
|
||||||
|
AZStd::vector<BuildVariableOverrides> m_dependencies;
|
||||||
|
};
|
||||||
|
|
||||||
|
class EditorAssetTree
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AZ_CLASS_ALLOCATOR(EditorAssetTree, AZ::SystemAllocator, 0);
|
||||||
|
|
||||||
|
EditorAssetTree* m_parent = nullptr;
|
||||||
|
AZStd::vector<EditorAssetTree> m_dependencies;
|
||||||
|
AZ::Data::Asset<ScriptCanvasEditor::ScriptCanvasAsset> m_asset;
|
||||||
|
|
||||||
|
EditorAssetTree* ModRoot();
|
||||||
|
|
||||||
|
void SetParent(EditorAssetTree& parent);
|
||||||
|
|
||||||
|
AZStd::string ToString(size_t depth = 0) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
// copy the variables overridden during editor / prefab build time back to runtime data
|
||||||
|
ScriptCanvas::RuntimeDataOverrides ConvertToRuntime(const BuildVariableOverrides& overrides);
|
||||||
|
|
||||||
|
AZ::Outcome<EditorAssetTree, AZStd::string> LoadEditorAssetTree(AZ::Data::AssetId editorAssetId, AZStd::string_view assetHint, EditorAssetTree* parent = nullptr);
|
||||||
|
|
||||||
|
AZ::Outcome<BuildVariableOverrides, AZStd::string> ParseEditorAssetTree(const EditorAssetTree& editorAssetTree);
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,101 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <AzCore/Serialization/Json/JsonSerialization.h>
|
||||||
|
#include <ScriptCanvas/Asset/RuntimeAsset.h>
|
||||||
|
#include <ScriptCanvas/Serialization/ScriptUserDataSerializer.h>
|
||||||
|
|
||||||
|
using namespace ScriptCanvas;
|
||||||
|
|
||||||
|
namespace AZ
|
||||||
|
{
|
||||||
|
AZ_CLASS_ALLOCATOR_IMPL(ScriptUserDataSerializer, SystemAllocator, 0);
|
||||||
|
|
||||||
|
JsonSerializationResult::Result ScriptUserDataSerializer::Load
|
||||||
|
( void* outputValue
|
||||||
|
, [[maybe_unused]] const Uuid& outputValueTypeId
|
||||||
|
, const rapidjson::Value& inputValue
|
||||||
|
, JsonDeserializerContext& context)
|
||||||
|
{
|
||||||
|
namespace JSR = JsonSerializationResult;
|
||||||
|
|
||||||
|
AZ_Assert(outputValueTypeId == azrtti_typeid<RuntimeVariable>(), "ScriptUserDataSerializer Load against output typeID that was not RuntimeVariable");
|
||||||
|
AZ_Assert(outputValue, "ScriptUserDataSerializer Load against null output");
|
||||||
|
|
||||||
|
auto outputVariable = reinterpret_cast<RuntimeVariable*>(outputValue);
|
||||||
|
JsonSerializationResult::ResultCode result(JSR::Tasks::ReadField);
|
||||||
|
AZ::Uuid typeId = AZ::Uuid::CreateNull();
|
||||||
|
|
||||||
|
auto typeIdMember = inputValue.FindMember(JsonSerialization::TypeIdFieldIdentifier);
|
||||||
|
if (typeIdMember == inputValue.MemberEnd())
|
||||||
|
{
|
||||||
|
return context.Report(JSR::Tasks::ReadField, JSR::Outcomes::Missing, AZStd::string::format("ScriptUserDataSerializer::Load failed to load the %s member", JsonSerialization::TypeIdFieldIdentifier));
|
||||||
|
}
|
||||||
|
|
||||||
|
result.Combine(LoadTypeId(typeId, typeIdMember->value, context));
|
||||||
|
if (typeId.IsNull())
|
||||||
|
{
|
||||||
|
return context.Report(JSR::Tasks::ReadField, JSR::Outcomes::Catastrophic, "ScriptUserDataSerializer::Load failed to load the AZ TypeId of the value");
|
||||||
|
}
|
||||||
|
|
||||||
|
outputVariable->value = context.GetSerializeContext()->CreateAny(typeId);
|
||||||
|
if (outputVariable->value.empty() || outputVariable->value.type() != typeId)
|
||||||
|
{
|
||||||
|
return context.Report(result, "ScriptUserDataSerializer::Load failed to load a value matched the reported AZ TypeId. The C++ declaration may have been deleted or changed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
result.Combine(ContinueLoadingFromJsonObjectField(AZStd::any_cast<void>(&outputVariable->value), typeId, inputValue, "value", context));
|
||||||
|
return context.Report(result, result.GetProcessing() != JSR::Processing::Halted
|
||||||
|
? "ScriptUserDataSerializer Load finished loading RuntimeVariable"
|
||||||
|
: "ScriptUserDataSerializer Load failed to load RuntimeVariable");
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonSerializationResult::Result ScriptUserDataSerializer::Store
|
||||||
|
( rapidjson::Value& outputValue
|
||||||
|
, const void* inputValue
|
||||||
|
, const void* defaultValue
|
||||||
|
, [[maybe_unused]] const Uuid& valueTypeId
|
||||||
|
, JsonSerializerContext& context)
|
||||||
|
{
|
||||||
|
namespace JSR = JsonSerializationResult;
|
||||||
|
|
||||||
|
AZ_Assert(valueTypeId == azrtti_typeid<RuntimeVariable>(), "RuntimeVariable Store against value typeID that was not RuntimeVariable");
|
||||||
|
AZ_Assert(inputValue, "RuntimeVariable Store against null inputValue pointer ");
|
||||||
|
|
||||||
|
auto inputScriptDataPtr = reinterpret_cast<const RuntimeVariable*>(inputValue);
|
||||||
|
auto defaultScriptDataPtr = reinterpret_cast<const RuntimeVariable*>(defaultValue);
|
||||||
|
auto inputAnyPtr = &inputScriptDataPtr->value;
|
||||||
|
auto defaultAnyPtr = defaultScriptDataPtr ? &defaultScriptDataPtr->value : nullptr;
|
||||||
|
|
||||||
|
if (defaultAnyPtr)
|
||||||
|
{
|
||||||
|
ScriptCanvas::Datum inputDatum(ScriptCanvas::Data::FromAZType(inputAnyPtr->type()), ScriptCanvas::Datum::eOriginality::Copy, AZStd::any_cast<void>(inputAnyPtr), inputAnyPtr->type());
|
||||||
|
ScriptCanvas::Datum defaultDatum(ScriptCanvas::Data::FromAZType(defaultAnyPtr->type()), ScriptCanvas::Datum::eOriginality::Copy, AZStd::any_cast<void>(defaultAnyPtr), defaultAnyPtr->type());
|
||||||
|
|
||||||
|
if (inputDatum == defaultDatum)
|
||||||
|
{
|
||||||
|
return context.Report(JSR::Tasks::WriteValue, JSR::Outcomes::DefaultsUsed, "ScriptUserDataSerializer Store used defaults for RuntimeVariable");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JSR::ResultCode result(JSR::Tasks::WriteValue);
|
||||||
|
outputValue.SetObject();
|
||||||
|
|
||||||
|
{
|
||||||
|
rapidjson::Value typeValue;
|
||||||
|
result.Combine(StoreTypeId(typeValue, inputAnyPtr->type(), context));
|
||||||
|
outputValue.AddMember(rapidjson::StringRef(JsonSerialization::TypeIdFieldIdentifier), AZStd::move(typeValue), context.GetJsonAllocator());
|
||||||
|
}
|
||||||
|
|
||||||
|
result.Combine(ContinueStoringToJsonObjectField(outputValue, "value", AZStd::any_cast<void>(inputAnyPtr), AZStd::any_cast<void>(defaultAnyPtr), inputAnyPtr->type(), context));
|
||||||
|
|
||||||
|
return context.Report(result, result.GetProcessing() != JSR::Processing::Halted
|
||||||
|
? "ScriptUserDataSerializer Store finished saving RuntimeVariable"
|
||||||
|
: "ScriptUserDataSerializer Store failed to save RuntimeVariable");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <AzCore/Memory/Memory.h>
|
||||||
|
#include <AzCore/Serialization/Json/BaseJsonSerializer.h>
|
||||||
|
#include <AzCore/Serialization/SerializeContext.h>
|
||||||
|
|
||||||
|
namespace AZ
|
||||||
|
{
|
||||||
|
class ScriptUserDataSerializer
|
||||||
|
: public BaseJsonSerializer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AZ_RTTI(ScriptUserDataSerializer, "{7E5FC193-8CDB-4251-A68B-F337027381DF}", BaseJsonSerializer);
|
||||||
|
AZ_CLASS_ALLOCATOR_DECL;
|
||||||
|
|
||||||
|
private:
|
||||||
|
JsonSerializationResult::Result Load
|
||||||
|
( void* outputValue
|
||||||
|
, const Uuid& outputValueTypeId
|
||||||
|
, const rapidjson::Value& inputValue
|
||||||
|
, JsonDeserializerContext& context) override;
|
||||||
|
|
||||||
|
JsonSerializationResult::Result Store
|
||||||
|
( rapidjson::Value& outputValue
|
||||||
|
, const void* inputValue
|
||||||
|
, const void* defaultValue
|
||||||
|
, const Uuid& valueTypeId, JsonSerializerContext& context) override;
|
||||||
|
};
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue