Editor Script Component simplified and working

Signed-off-by: chcurran <82187351+carlitosan@users.noreply.github.com>
This commit is contained in:
chcurran
2021-11-23 10:31:26 -08:00
parent 24b3167d48
commit cdb858e8af
6 changed files with 74 additions and 56 deletions
@@ -30,11 +30,10 @@ namespace ScriptCanvasBuilder
void BuildVariableOverrides::CopyPreviousOverriddenValues(const BuildVariableOverrides& source)
{
auto isEqual = [](const ScriptCanvas::GraphVariable& overrideValue, const ScriptCanvas::GraphVariable& candidate)
auto isEqual = [](const ScriptCanvas::GraphVariable& lhs, const ScriptCanvas::GraphVariable& rhs)
{
return candidate.GetVariableId() == overrideValue.GetVariableId()
|| (candidate.GetVariableName() == overrideValue.GetVariableName()
&& candidate.GetDataType() == overrideValue.GetDataType());
return (lhs.GetVariableId() == rhs.GetVariableId() && lhs.GetDataType() == rhs.GetDataType())
|| (lhs.GetVariableName() == rhs.GetVariableName() && lhs.GetDataType() == rhs.GetDataType());
};
auto copyPreviousIfFound = [isEqual](ScriptCanvas::GraphVariable& overriddenValue, const AZStd::vector<ScriptCanvas::GraphVariable>& source)
@@ -44,7 +43,7 @@ namespace ScriptCanvasBuilder
if (iter != source.end())
{
overriddenValue.DeepCopy(*iter);
overriddenValue.ModDatum().DeepCopyDatum(*iter->GetDatum());
overriddenValue.SetScriptInputControlVisibility(AZ::Edit::PropertyVisibility::Hide);
overriddenValue.SetAllowSignalOnChange(false);
return true;
@@ -64,6 +63,15 @@ namespace ScriptCanvasBuilder
}
}
for (auto& overriddenValue : m_overridesUnused)
{
if (!copyPreviousIfFound(overriddenValue, source.m_overridesUnused))
{
// the variable in question may have been previously used, and is now unused, so copy the previous value over
copyPreviousIfFound(overriddenValue, source.m_overrides);
}
}
//////////////////////////////////////////////////////////////////////////
// #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
@@ -23,7 +23,8 @@
#include <ScriptCanvas/Components/EditorGraph.h>
#include <ScriptCanvas/Core/SerializationListener.h>
#include <ScriptCanvas/Asset/RuntimeAsset.h>
#include <ScriptCanvas/Libraries/Math/MathNodeUtilities.h>
namespace ScriptCanvasFileHandlingCpp
{
void AppendTabs(AZStd::string& result, size_t depth)
@@ -135,26 +136,19 @@ namespace ScriptCanvasEditor
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())
if (!handle.Get())
{
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>())
auto loadAssetOutcome = LoadFromFile(handle.Path().c_str());
if (!loadAssetOutcome.IsSuccess())
{
dependentAssets.push_back(SourceHandle(nullptr, filterInfo.m_assetId.m_guid, {}));
return AZ::Failure(AZStd::string::format("LoadEditorAssetTree failed to load graph from %s: %s"
, handle.ToString().c_str(), loadAssetOutcome.GetError().c_str()));
}
return true;
};
handle = SourceHandle(loadAssetOutcome.GetValue(), handle.Id(), handle.Path().c_str());
}
AZStd::vector<SourceHandle> dependentAssets;
const auto subgraphInterfaceAssetTypeID = azrtti_typeid<AZ::Data::Asset<ScriptCanvas::SubgraphInterfaceAsset>>();
auto beginElementCB = [&subgraphInterfaceAssetTypeID, &dependentAssets]
@@ -170,12 +164,13 @@ namespace ScriptCanvasEditor
// 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, {}));
}
if (classData->m_typeId == subgraphInterfaceAssetTypeID)
{
auto asset = reinterpret_cast<AZ::Data::Asset<ScriptCanvas::SubgraphInterfaceAsset>*>(instance);
auto id = asset->GetId();
dependentAssets.push_back(SourceHandle(nullptr, id.m_guid, {}));
}
return true;
@@ -183,7 +178,10 @@ namespace ScriptCanvasEditor
AZ::SerializeContext* serializeContext = nullptr;
AZ::ComponentApplicationBus::BroadcastResult(serializeContext, &AZ::ComponentApplicationRequests::GetSerializeContext);
serializeContext->EnumerateObject( handle.Get(), beginElementCB, nullptr, AZ::SerializeContext::ENUM_ACCESS_FOR_READ);
AZ_Assert(serializeContext, "LoadEditorAssetTree() ailed to retrieve serialize context!");
const ScriptCanvasEditor::Graph* graph = handle.Get();
serializeContext->EnumerateObject(graph, beginElementCB, nullptr, AZ::SerializeContext::ENUM_ACCESS_FOR_READ);
EditorAssetTree result;
@@ -204,8 +202,7 @@ namespace ScriptCanvasEditor
result.SetParent(*parent);
}
result.m_asset = loadAssetOutcome.TakeValue();
result.m_asset = AZStd::move(handle);
return AZ::Success(result);
}
@@ -252,6 +249,10 @@ namespace ScriptCanvasEditor
if (auto entity = scriptCanvasData->GetScriptCanvasEntity())
{
AZ_Assert(entity->GetState() == AZ::Entity::State::Constructed, "Entity loaded in bad state");
AZ::u64 entityId =
aznumeric_caster(ScriptCanvas::MathNodeUtilities::GetRandomIntegral<AZ::s64>(1, std::numeric_limits<AZ::s64>::max()));
entity->SetId(AZ::EntityId(entityId));
entity->Init();
entity->Activate();
@@ -377,7 +377,7 @@ namespace ScriptCanvasEditor
m_sourceHandle = *completeAsset;
}
OnScriptCanvasAssetChanged(m_sourceHandle);
OnScriptCanvasAssetChanged(SourceChangeDescription::SelectionChanged);
SetName(m_sourceHandle.Path().Filename().Native());
AzToolsFramework::ToolsApplicationEvents::Bus::Broadcast(&AzToolsFramework::ToolsApplicationEvents::InvalidatePropertyDisplay, AzToolsFramework::Refresh_AttributesAndValues);
}
@@ -391,26 +391,16 @@ namespace ScriptCanvasEditor
{
m_sourceHandle = SourceHandle(nullptr, m_sourceHandle.Path());
CompleteDescriptionInPlace(m_sourceHandle);
m_previousHandle = {};
m_removedHandle = {};
if (m_sourceHandle.IsDescriptionValid())
{
OnScriptCanvasAssetChanged(m_sourceHandle);
}
else
{
ClearVariables();
}
OnScriptCanvasAssetChanged(SourceChangeDescription::SelectionChanged);
return AZ::Edit::PropertyRefreshLevels::EntireTree;
}
void EditorScriptCanvasComponent::OnScriptCanvasAssetChanged(const SourceHandle& assetId)
void EditorScriptCanvasComponent::OnScriptCanvasAssetChanged(SourceChangeDescription changeDescription)
{
ScriptCanvas::GraphIdentifier newIdentifier = GetGraphIdentifier();
newIdentifier.m_assetId = assetId.Id();
newIdentifier.m_assetId = m_sourceHandle.Id();
ScriptCanvas::GraphIdentifier oldIdentifier = GetGraphIdentifier();
oldIdentifier.m_assetId = m_previousHandle.Id();
@@ -419,21 +409,24 @@ namespace ScriptCanvasEditor
m_previousHandle = m_sourceHandle.Describe();
// Only clear our variables when we are given a new asset id
// or when the asset was explicitly set to empty.
//
// i.e. do not clear variables when we lose the catalog asset.
if ((assetId.IsDescriptionValid() && assetId.Describe() != m_removedHandle.Describe())
|| (!assetId.IsDescriptionValid() && !m_removedHandle.IsDescriptionValid()))
if (changeDescription == SourceChangeDescription::SelectionChanged)
{
ClearVariables();
}
if (assetId.IsDescriptionValid())
if (m_sourceHandle.IsDescriptionValid())
{
if (auto loaded = LoadFromFile(assetId.Path().c_str()); loaded.IsSuccess())
if (!m_sourceHandle.Get())
{
UpdatePropertyDisplay(loaded.GetValue());
if (auto loaded = LoadFromFile(m_sourceHandle.Path().c_str()); loaded.IsSuccess())
{
m_sourceHandle = SourceHandle(loaded.TakeValue(), m_sourceHandle.Id(), m_sourceHandle.Path().c_str());
}
}
if (m_sourceHandle.Get())
{
UpdatePropertyDisplay(m_sourceHandle);
}
}
@@ -467,8 +460,9 @@ namespace ScriptCanvasEditor
{
if (auto handle = CompleteDescription(SourceHandle(nullptr, fileAssetId, {})))
{
m_sourceHandle = *handle;
// consider queueing on tick bus
OnScriptCanvasAssetChanged(*handle);
OnScriptCanvasAssetChanged(SourceChangeDescription::Modified);
}
}
}
@@ -479,7 +473,7 @@ namespace ScriptCanvasEditor
if (fileAssetId == m_sourceHandle.Id())
{
m_removedHandle = m_sourceHandle;
OnScriptCanvasAssetChanged(m_removedHandle);
OnScriptCanvasAssetChanged(SourceChangeDescription::Removed);
}
}
@@ -489,7 +483,7 @@ namespace ScriptCanvasEditor
if (fileAssetId == m_sourceHandle.Id())
{
m_removedHandle = m_sourceHandle;
OnScriptCanvasAssetChanged(m_removedHandle);
OnScriptCanvasAssetChanged(SourceChangeDescription::Error);
}
}
@@ -98,6 +98,14 @@ namespace ScriptCanvasEditor
void OnStopPlayInEditor() override;
protected:
enum class SourceChangeDescription : AZ::u8
{
Error,
Modified,
Removed,
SelectionChanged,
};
static void Reflect(AZ::ReflectContext* context);
static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
@@ -123,7 +131,7 @@ namespace ScriptCanvasEditor
AZ::u32 OnFileSelectionChanged();
void OnScriptCanvasAssetChanged(const SourceHandle& sourceHandle);
void OnScriptCanvasAssetChanged(SourceChangeDescription changeDescription);
void UpdateName();
@@ -335,6 +335,11 @@ namespace ScriptCanvas
return &m_datum;
}
Datum& GraphVariable::ModDatum()
{
return m_datum;
}
void GraphVariable::ConfigureDatumView(ModifiableDatumView& datumView)
{
datumView.ConfigureView((*this));
@@ -127,6 +127,8 @@ namespace ScriptCanvas
const Datum* GetDatum() const;
Datum& ModDatum();
bool IsComponentProperty() const;
void ConfigureDatumView(ModifiableDatumView& accessController);