From 355776d3a96a8b2f1d8dde0b02559464d7995929 Mon Sep 17 00:00:00 2001 From: chcurran <82187351+carlitosan@users.noreply.github.com> Date: Tue, 29 Jun 2021 17:25:23 -0700 Subject: [PATCH] Add versioning updates for prefab conversion, and PR clean up & nitpicks Signed-off-by: chcurran <82187351+carlitosan@users.noreply.github.com> --- .../Code/Builder/ScriptCanvasBuilder.cpp | 8 +- .../Code/Builder/ScriptCanvasBuilderWorker.h | 2 + .../EditorScriptCanvasComponent.cpp | 88 +++++++++++++++---- .../Code/Include/ScriptCanvas/Core/Datum.cpp | 30 +++---- .../Grammar/AbstractCodeModel.cpp | 8 +- .../ScriptUserDataSerializer.cpp | 17 ++-- .../ScriptCanvas/Variable/GraphVariable.cpp | 3 + 7 files changed, 111 insertions(+), 45 deletions(-) diff --git a/Gems/ScriptCanvas/Code/Builder/ScriptCanvasBuilder.cpp b/Gems/ScriptCanvas/Code/Builder/ScriptCanvasBuilder.cpp index ff0fdf6273..d6ee28af9e 100644 --- a/Gems/ScriptCanvas/Code/Builder/ScriptCanvasBuilder.cpp +++ b/Gems/ScriptCanvas/Code/Builder/ScriptCanvasBuilder.cpp @@ -200,7 +200,11 @@ namespace ScriptCanvasBuilder 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(); }); + 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()) @@ -265,7 +269,7 @@ namespace ScriptCanvasBuilder } AzToolsFramework::AssetSystemRequestBus::BroadcastResult - (resultFound + ( resultFound , &AzToolsFramework::AssetSystem::AssetSystemRequest::GetSourceInfoBySourceUUID , editorAssetId.m_guid , assetInfo diff --git a/Gems/ScriptCanvas/Code/Builder/ScriptCanvasBuilderWorker.h b/Gems/ScriptCanvas/Code/Builder/ScriptCanvasBuilderWorker.h index 90dfb843b9..465be7760b 100644 --- a/Gems/ScriptCanvas/Code/Builder/ScriptCanvasBuilderWorker.h +++ b/Gems/ScriptCanvas/Code/Builder/ScriptCanvasBuilderWorker.h @@ -55,6 +55,8 @@ namespace ScriptCanvasBuilder DependencyArguments, DependencyRequirementsData, AddAssetDependencySearch, + PrefabIntegration, + CorrectGraphVariableVersion, // add new entries above Current, }; diff --git a/Gems/ScriptCanvas/Code/Editor/Components/EditorScriptCanvasComponent.cpp b/Gems/ScriptCanvas/Code/Editor/Components/EditorScriptCanvasComponent.cpp index 56a170f851..a1d90839f8 100644 --- a/Gems/ScriptCanvas/Code/Editor/Components/EditorScriptCanvasComponent.cpp +++ b/Gems/ScriptCanvas/Code/Editor/Components/EditorScriptCanvasComponent.cpp @@ -31,6 +31,18 @@ #include #include + +namespace EditorScriptCanvasComponentCpp +{ + enum Version + { + PrefabIntegration = 10, + + // add description above + Current + }; +} + namespace ScriptCanvasEditor { static bool EditorScriptCanvasComponentVersionConverter(AZ::SerializeContext& serializeContext, AZ::SerializeContext::DataElementNode& rootElement) @@ -73,6 +85,63 @@ namespace ScriptCanvasEditor rootElement.RemoveElementByName(AZ_CRC("m_variableEntityIdMap", 0xdc6c75a8)); } + if (rootElement.GetVersion() <= EditorScriptCanvasComponentCpp::Version::PrefabIntegration) + { + auto variableDataElementIndex = rootElement.FindElement(AZ_CRC_CE("m_variableData")); + if (variableDataElementIndex == -1) + { + AZ_Error("ScriptCanvas", false, "EditorScriptCanvasComponent conversion failed: 'm_variableData' index was missing"); + return false; + } + + auto& variableDataElement = rootElement.GetSubElement(variableDataElementIndex); + + ScriptCanvas::EditableVariableData editableData; + if (!variableDataElement.GetData(editableData)) + { + AZ_Error("ScriptCanvas", false, "EditorScriptCanvasComponent conversion failed: could not retrieve old 'm_variableData'"); + return false; + } + + auto scriptCanvasAssetHolderElementIndex = rootElement.FindElement(AZ_CRC_CE("m_assetHolder")); + if (scriptCanvasAssetHolderElementIndex == -1) + { + AZ_Error("ScriptCanvas", false, "EditorScriptCanvasComponent conversion failed: 'm_assetHolder' index was missing"); + return false; + } + + auto& scriptCanvasAssetHolderElement = rootElement.GetSubElement(scriptCanvasAssetHolderElementIndex); + + ScriptCanvasAssetHolder assetHolder; + if (!scriptCanvasAssetHolderElement.GetData(assetHolder)) + { + AZ_Error("ScriptCanvas", false, "EditorScriptCanvasComponent conversion failed: could not retrieve old 'm_assetHolder'"); + return false; + } + + rootElement.RemoveElement(variableDataElementIndex); + + if (!rootElement.AddElementWithData(serializeContext, "runtimeDataIsValid", true)) + { + AZ_Error("ScriptCanvas", false, "EditorScriptCanvasComponent conversion failed: failed to add 'runtimeDataIsValid'"); + return false; + } + + ScriptCanvasBuilder::BuildVariableOverrides overrides; + overrides.m_source = AZ::Data::Asset(assetHolder.GetAssetId(), assetHolder.GetAssetType(), assetHolder.GetAssetHint());; + + for (auto& variable : editableData.GetVariables()) + { + overrides.m_overrides.push_back(variable.m_graphVariable); + } + + if (!rootElement.AddElementWithData(serializeContext, "runtimeDataOverrides", overrides)) + { + AZ_Error("ScriptCanvas", false, "EditorScriptCanvasComponent conversion failed: failed to add 'runtimeDataOverrides'"); + return false; + } + } + return true; } @@ -82,7 +151,7 @@ namespace ScriptCanvasEditor if (auto serializeContext = azrtti_cast(context)) { serializeContext->Class() - ->Version(10, &EditorScriptCanvasComponentVersionConverter) + ->Version(EditorScriptCanvasComponentCpp::Version::Current, &EditorScriptCanvasComponentVersionConverter) ->Field("m_name", &EditorScriptCanvasComponent::m_name) ->Field("m_assetHolder", &EditorScriptCanvasComponent::m_scriptCanvasAssetHolder) ->Field("runtimeDataIsValid", &EditorScriptCanvasComponent::m_runtimeDataIsValid) @@ -213,18 +282,7 @@ namespace ScriptCanvasEditor if (fileAssetId.IsValid()) { AssetTrackerNotificationBus::Handler::BusConnect(fileAssetId); - - ScriptCanvasMemoryAsset::pointer memoryAsset; - AssetTrackerRequestBus::BroadcastResult(memoryAsset, &AssetTrackerRequests::GetAsset, fileAssetId); - - if (memoryAsset && memoryAsset->GetAsset().GetStatus() == AZ::Data::AssetData::AssetStatus::Ready) - { - OnScriptCanvasAssetReady(memoryAsset); - } - else - { - AssetTrackerRequestBus::Broadcast(&AssetTrackerRequests::Load, m_scriptCanvasAssetHolder.GetAssetId(), m_scriptCanvasAssetHolder.GetAssetType(), nullptr); - } + AzToolsFramework::ToolsApplicationNotificationBus::Broadcast(&AzToolsFramework::ToolsApplicationEvents::InvalidatePropertyDisplay, AzToolsFramework::Refresh_EntireTree_NewContent); } } @@ -251,7 +309,7 @@ namespace ScriptCanvasEditor auto assetTreeOutcome = LoadEditorAssetTree(m_scriptCanvasAssetHolder.GetAssetId(), m_scriptCanvasAssetHolder.GetAssetHint()); if (!assetTreeOutcome.IsSuccess()) { - AZ_Warning("ScriptCanvas", false, AZStd::string::format("EditorScriptCanvasComponent::BuildGameEntityData failed: %s", assetTreeOutcome.GetError().c_str()).c_str()); + AZ_Warning("ScriptCanvas", false, "EditorScriptCanvasComponent::BuildGameEntityData failed: %s", assetTreeOutcome.GetError().c_str()); return; } @@ -260,7 +318,7 @@ namespace ScriptCanvasEditor auto parseOutcome = ParseEditorAssetTree(editorAssetTree); if (!parseOutcome.IsSuccess()) { - AZ_Warning("ScriptCanvas", false, AZStd::string::format("EditorScriptCanvasComponent::BuildGameEntityData failed: %s", parseOutcome.GetError().c_str()).c_str()); + AZ_Warning("ScriptCanvas", false, "EditorScriptCanvasComponent::BuildGameEntityData failed: %s", parseOutcome.GetError().c_str()); return; } diff --git a/Gems/ScriptCanvas/Code/Include/ScriptCanvas/Core/Datum.cpp b/Gems/ScriptCanvas/Code/Include/ScriptCanvas/Core/Datum.cpp index 3c70031af0..9a785dceba 100644 --- a/Gems/ScriptCanvas/Code/Include/ScriptCanvas/Core/Datum.cpp +++ b/Gems/ScriptCanvas/Code/Include/ScriptCanvas/Core/Datum.cpp @@ -209,7 +209,7 @@ namespace DatumHelpers } else if (typeID == azrtti_typeid()) { - target = BehaviorContextObject::Create(AZ::Vector2(static_cast(sourceVector.GetX()), static_cast(sourceVector.GetY())), behaviorClass); + target = BehaviorContextObject::Create(AZ::Vector2((sourceVector.GetX()), (sourceVector.GetY())), behaviorClass); } else if (typeID == azrtti_typeid()) { @@ -264,7 +264,7 @@ namespace DatumHelpers } else if (typeID == azrtti_typeid()) { - target = BehaviorContextObject::Create(AZ::Vector2(static_cast(sourceVector.GetX()), static_cast(sourceVector.GetY())), behaviorClass); + target = BehaviorContextObject::Create(AZ::Vector2((sourceVector.GetX()), (sourceVector.GetY())), behaviorClass); } else if (typeID == azrtti_typeid()) { @@ -2478,7 +2478,7 @@ namespace ScriptCanvas AZStd::string Datum::ToStringColor(const Data::ColorType& c) const { - return AZStd::string::format("(r=%.7f,g=%.7f,b=%.7f,a=%.7f)", static_cast(c.GetR()), static_cast(c.GetG()), static_cast(c.GetB()), static_cast(c.GetA())); + return AZStd::string::format("(r=%.7f,g=%.7f,b=%.7f,a=%.7f)", (c.GetR()), (c.GetG()), (c.GetB()), (c.GetA())); } bool Datum::ToStringBehaviorClassObject(Data::StringType& stringOut) const @@ -2555,9 +2555,9 @@ namespace ScriptCanvas AZ::Vector3 eulerRotation = AZ::ConvertTransformToEulerDegrees(AZ::Transform::CreateFromQuaternion(source)); return AZStd::string::format ("(Pitch: %5.2f, Roll: %5.2f, Yaw: %5.2f)" - , static_cast(eulerRotation.GetX()) - , static_cast(eulerRotation.GetY()) - , static_cast(eulerRotation.GetZ())); + , (eulerRotation.GetX()) + , (eulerRotation.GetY()) + , (eulerRotation.GetZ())); } AZStd::string Datum::ToStringTransform(const Data::TransformType& source) const @@ -2570,8 +2570,8 @@ namespace ScriptCanvas ("(Position: X: %f, Y: %f, Z: %f," " Rotation: X: %f, Y: %f, Z: %f," " Scale: %f)" - , static_cast(pos.GetX()), static_cast(pos.GetY()), static_cast(pos.GetZ()) - , static_cast(rotation.GetX()), static_cast(rotation.GetY()), static_cast(rotation.GetZ()) + , (pos.GetX()), (pos.GetY()), (pos.GetZ()) + , (rotation.GetX()), (rotation.GetY()), (rotation.GetZ()) , scale); } @@ -2587,19 +2587,19 @@ namespace ScriptCanvas { return AZStd::string::format ("(X: %f, Y: %f, Z: %f)" - , static_cast(source.GetX()) - , static_cast(source.GetY()) - , static_cast(source.GetZ())); + , (source.GetX()) + , (source.GetY()) + , (source.GetZ())); } AZStd::string Datum::ToStringVector4(const AZ::Vector4& source) const { return AZStd::string::format ("(X: %f, Y: %f, Z: %f, W: %f)" - , static_cast(source.GetX()) - , static_cast(source.GetY()) - , static_cast(source.GetZ()) - , static_cast(source.GetW())); + , (source.GetX()) + , (source.GetY()) + , (source.GetZ()) + , (source.GetW())); } AZ::Outcome Datum::CallBehaviorContextMethod(const AZ::BehaviorMethod* method, AZ::BehaviorValueParameter* params, unsigned int numExpectedArgs) diff --git a/Gems/ScriptCanvas/Code/Include/ScriptCanvas/Grammar/AbstractCodeModel.cpp b/Gems/ScriptCanvas/Code/Include/ScriptCanvas/Grammar/AbstractCodeModel.cpp index 1851b5e65d..a42f624f01 100644 --- a/Gems/ScriptCanvas/Code/Include/ScriptCanvas/Grammar/AbstractCodeModel.cpp +++ b/Gems/ScriptCanvas/Code/Include/ScriptCanvas/Grammar/AbstractCodeModel.cpp @@ -1226,8 +1226,8 @@ namespace ScriptCanvas (nodeling->GetEntityId() , nullptr , AZStd::string::format - ("%s is the name of multiple In Nodelings in a subgraph,\n" - "this will result in a difficult or impossible to use Function Node when used in another graph", displayName.data())); + ( "%s is the name of multiple In Nodelings in a subgraph,\n" + "this will result in a difficult or impossible to use Function Node when used in another graph", displayName.c_str())); return; } else @@ -1355,8 +1355,8 @@ namespace ScriptCanvas if (ExecutionContainsCycles(node, outSlot)) { AddError(nullptr, aznew Internal::ParseError(node.GetEntityId(), AZStd::string::format - ("Execution cycle detected (see connections to %s-%s. Use a looping node like While or For" - , node.GetDebugName().data(), outSlot.GetName().data()).data())); + ( "Execution cycle detected (see connections to %s-%s. Use a looping node like While or For" + , node.GetDebugName().c_str(), outSlot.GetName().c_str()).c_str())); return true; } diff --git a/Gems/ScriptCanvas/Code/Include/ScriptCanvas/Serialization/ScriptUserDataSerializer.cpp b/Gems/ScriptCanvas/Code/Include/ScriptCanvas/Serialization/ScriptUserDataSerializer.cpp index 207acafd82..f626cb1da2 100644 --- a/Gems/ScriptCanvas/Code/Include/ScriptCanvas/Serialization/ScriptUserDataSerializer.cpp +++ b/Gems/ScriptCanvas/Code/Include/ScriptCanvas/Serialization/ScriptUserDataSerializer.cpp @@ -5,10 +5,9 @@ * */ -#include "ScriptUserDataSerializer.h" - #include #include +#include using namespace ScriptCanvas; @@ -31,10 +30,10 @@ namespace AZ JsonSerializationResult::ResultCode result(JSR::Tasks::ReadField); AZ::Uuid typeId = AZ::Uuid::CreateNull(); - auto typeIdMember = inputValue.FindMember("$type"); + auto typeIdMember = inputValue.FindMember(JsonSerialization::TypeIdFieldIdentifier); if (typeIdMember == inputValue.MemberEnd()) { - return context.Report(JSR::Tasks::ReadField, JSR::Outcomes::Catastrophic, "ScriptUserDataSerializer::Load failed to load the $type member"); + return context.Report(JSR::Tasks::ReadField, JSR::Outcomes::Catastrophic, AZStd::string::format("ScriptUserDataSerializer::Load failed to load the %s member", JsonSerialization::TypeIdFieldIdentifier).c_str()); } result.Combine(LoadTypeId(typeId, typeIdMember->value, context)); @@ -46,13 +45,13 @@ namespace AZ outputVariable->value = context.GetSerializeContext()->CreateAny(typeId); if (outputVariable->value.empty() || outputVariable->value.type() != typeId) { - return context.Report(JSR::Tasks::ReadField, JSR::Outcomes::Catastrophic, "ScriptUserDataSerializer::Load failed to load a value matched the reported AZ TypeId. The C++ declaration may have been deleted or changed."); + return context.Report(JSR::Tasks::ReadField, JSR::Outcomes::Unknown, "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(&outputVariable->value), typeId, inputValue, "value", context)); return context.Report(result, result.GetProcessing() != JSR::Processing::Halted - ? "ScriptUserDataSerializer Store finished loading RuntimeVariable" - : "ScriptUserDataSerializer Store failed to load RuntimeVariable"); + ? "ScriptUserDataSerializer Load finished loading RuntimeVariable" + : "ScriptUserDataSerializer Load failed to load RuntimeVariable"); } JsonSerializationResult::Result ScriptUserDataSerializer::Store @@ -91,7 +90,7 @@ namespace AZ rapidjson::Value typeValue; typeValue.SetString(azTypeString.begin(), azTypeString.length(), context.GetJsonAllocator()); result.Combine(StoreTypeId(typeValue, inputAnyPtr->type(), context)); - outputValue.AddMember("$type", typeValue, context.GetJsonAllocator()); + outputValue.AddMember("$type", AZStd::move(typeValue), context.GetJsonAllocator()); } result.Combine(ContinueStoringToJsonObjectField(outputValue, "value", AZStd::any_cast(inputAnyPtr), AZStd::any_cast(defaultAnyPtr), inputAnyPtr->type(), context)); @@ -101,4 +100,4 @@ namespace AZ : "ScriptUserDataSerializer Store failed to save RuntimeVariable"); } -} \ No newline at end of file +} diff --git a/Gems/ScriptCanvas/Code/Include/ScriptCanvas/Variable/GraphVariable.cpp b/Gems/ScriptCanvas/Code/Include/ScriptCanvas/Variable/GraphVariable.cpp index aa340f55b9..57c40111a6 100644 --- a/Gems/ScriptCanvas/Code/Include/ScriptCanvas/Variable/GraphVariable.cpp +++ b/Gems/ScriptCanvas/Code/Include/ScriptCanvas/Variable/GraphVariable.cpp @@ -102,6 +102,9 @@ namespace ScriptCanvas classElement.RemoveElementByName(AZ_CRC_CE("Scope")); classElement.AddElementWithData(context, "InitialValueSource", VariableFlags::InitialValueSource::Component); } + + classElement.RemoveElementByName(AZ_CRC("ExposeAsInput", 0x0f7879f0)); + classElement.RemoveElementByName(AZ_CRC("Exposure", 0x398f29cd)); } else if (classElement.GetVersion() < 3)