Add variable, datum sanity for user added slots

Signed-off-by: carlitosan <82187351+carlitosan@users.noreply.github.com>
This commit is contained in:
carlitosan
2022-01-12 16:21:40 -08:00
parent ce2e433b71
commit 4e755cc258
19 changed files with 70 additions and 59 deletions
@@ -100,12 +100,18 @@ namespace ScriptCanvas
{
RuntimeAsset* runtimeAsset = asset.GetAs<RuntimeAsset>();
AZ_Assert(runtimeAsset, "This should be a Script Canvas runtime asset, as this is the only type we process!");
if (runtimeAsset && m_serializeContext)
{
stream->Seek(0U, AZ::IO::GenericStream::ST_SEEK_BEGIN);
bool loadSuccess = AZ::Utils::LoadObjectFromStreamInPlace(*stream, runtimeAsset->m_runtimeData, m_serializeContext, AZ::ObjectStream::FilterDescriptor(assetLoadFilterCB));
const bool loadSuccess = AZ::Utils::LoadObjectFromStreamInPlace(*stream, runtimeAsset->m_runtimeData
, m_serializeContext, AZ::ObjectStream::FilterDescriptor(assetLoadFilterCB));
AZ_Error("ScriptCanvas", loadSuccess, "ScriptCanvas failed to load runtime asset: %s - %s"
, asset.GetHint().c_str(), asset.GetId().ToString<AZStd::string>().c_str());
return loadSuccess ? AZ::Data::AssetHandler::LoadResult::LoadComplete : AZ::Data::AssetHandler::LoadResult::Error;
}
return AZ::Data::AssetHandler::LoadResult::Error;
}
@@ -2577,11 +2577,11 @@ namespace ScriptCanvas
}
}
bool Node::ConvertSlotToReference(const SlotId& slotId)
bool Node::ConvertSlotToReference(const SlotId& slotId, bool isNewSlot)
{
Slot* slot = GetSlot(slotId);
if (slot && slot->ConvertToReference())
if (slot && slot->ConvertToReference(isNewSlot))
{
InitializeVariableReference((*slot), {});
return true;
@@ -498,7 +498,7 @@ namespace ScriptCanvas
void SanityCheckDynamicDisplay();
void SanityCheckDynamicDisplay(ExploredDynamicGroupCache& exploredGroupCache);
bool ConvertSlotToReference(const SlotId& slotId);
bool ConvertSlotToReference(const SlotId& slotId, bool isNewSlot = false);
bool ConvertSlotToValue(const SlotId& slotId);
NamedEndpoint CreateNamedEndpoint(SlotId slotId) const;
@@ -460,14 +460,15 @@ namespace ScriptCanvas
&& GetDataType() != Data::Type::BehaviorContextObject(GraphScopedVariableId::TYPEINFO_Uuid());
}
bool Slot::CanConvertToReference() const
{
return !m_isUserAdded && CanConvertTypes() && !m_isVariableReference && !m_node->HasConnectedNodes((*this));
bool Slot::CanConvertToReference(bool isNewSlot) const
{
// #sc_user_slot_variable_ux make sure this can be converted to reference, or created as one
return (!m_isUserAdded || isNewSlot) && CanConvertTypes() && !m_isVariableReference && !m_node->HasConnectedNodes((*this));
}
bool Slot::ConvertToReference()
bool Slot::ConvertToReference(bool isNewSlot)
{
if (CanConvertToReference())
if (CanConvertToReference(isNewSlot))
{
m_isVariableReference = true;
@@ -147,8 +147,8 @@ namespace ScriptCanvas
bool CanConvertToValue() const;
bool ConvertToValue();
bool CanConvertToReference() const;
bool ConvertToReference();
bool CanConvertToReference(bool isNewSlot = false) const;
bool ConvertToReference(bool isNewSlot = false);
void SetVariableReference(const VariableId& variableId);
const VariableId& GetVariableReference() const;
GraphVariable* GetVariable() const;
@@ -237,7 +237,7 @@ namespace ScriptCanvas
if (auto datum = variablePair.second.GetDatum())
{
// #functions2 slot<->variable consider getting all variables from the UX variable manager, or from the ACM and looking them up in the variable manager for ordering
// #sc_user_slot_variable_ux consider getting all variables from the UX variable manager, or from the ACM and looking them up in the variable manager for ordering
m_sourceVariableByDatum.insert(AZStd::make_pair(datum, &variablePair.second));
}
@@ -248,7 +248,7 @@ namespace ScriptCanvas
auto datum = sourceVariable->GetDatum();
AZ_Assert(datum != nullptr, "the datum must be valid");
// #functions2 slot<->variable check to verify if it is a member variable
// #sc_user_slot_variable_ux check to verify if it is a member variable
auto variable = sourceVariable->GetScope() == VariableFlags::Scope::Graph
? AddMemberVariable(*datum, sourceVariable->GetVariableName(), sourceVariable->GetVariableId())
: AddVariable(*datum, sourceVariable->GetVariableName(), sourceVariable->GetVariableId());
@@ -1671,7 +1671,7 @@ namespace ScriptCanvas
if (returnValue.second->m_source->m_sourceSlotId == slot->GetId())
{
// #functions2 slot<->variable determine if the root or the function call should be passed in here...the slot/node lead to the user call on the thread, but it may not even be created yet
// #sc_user_slot_variable_ux determine if the root or the function call should be passed in here...the slot/node lead to the user call on the thread, but it may not even be created yet
return AZStd::make_pair(root, returnValue.second->m_source);
}
}
@@ -4644,7 +4644,7 @@ namespace ScriptCanvas
void AbstractCodeModel::ParseNodelingVariables(const Node& node, NodelingType nodelingType)
{
// #functions2 slot<->variable adjust once datums are more coordinated
// #sc_user_slot_variable_ux adjust once datums are more coordinated
auto createVariablesSlots = [&](AZStd::unordered_map<const Slot*, VariablePtr>& variablesBySlots, const AZStd::vector<const Slot*>& slots, bool slotHasDatum)
{
for (const auto& slot : slots)
@@ -4660,7 +4660,7 @@ namespace ScriptCanvas
return;
}
// #functions2 slot<->variable consider getting all variables from the UX variable manager, or from the ACM and looking them up in the variable manager for ordering
// #sc_user_slot_variable_ux consider getting all variables from the UX variable manager, or from the ACM and looking them up in the variable manager for ordering
// auto iter = m_sourceVariableByDatum.find(variableDatum);
// if (iter == m_sourceVariableByDatum.end())
// {
@@ -220,7 +220,7 @@ namespace ScriptCanvas
return AZ::Success(newId);
}
// #functions2 slot<->variable add this to the graph, using the old datum
// #sc_user_slot_variable_ux add this to the graph, using the old datum
AZ::Outcome<VariableId, AZStd::string> GraphVariableManagerComponent::AddVariable(AZStd::string_view name, const Datum& value, bool functionScope)
{
if (FindVariable(name))