Fixed scoping rules for variables
This commit is contained in:
@@ -43,20 +43,12 @@ namespace ScriptCanvas
|
||||
{
|
||||
const char* GetScopeDisplayLabel(Scope scopeType)
|
||||
{
|
||||
switch (scopeType)
|
||||
{
|
||||
case Scope::Graph:
|
||||
return "Graph";
|
||||
case Scope::Function:
|
||||
return "Function";
|
||||
default:
|
||||
return "?";
|
||||
}
|
||||
return GraphVariable::s_ScopeNames[static_cast<int>(scopeType)];
|
||||
}
|
||||
|
||||
Scope GetScopeFromLabel(const char* label)
|
||||
{
|
||||
if (strcmp("Function", label) == 0)
|
||||
if (strcmp(GraphVariable::s_ScopeNames[static_cast<int>(VariableFlags::Scope::Function)], label) == 0)
|
||||
{
|
||||
return Scope::Function;
|
||||
}
|
||||
@@ -71,6 +63,7 @@ namespace ScriptCanvas
|
||||
case Scope::Graph:
|
||||
return "Variable is accessible in the entire graph.";
|
||||
case Scope::Function:
|
||||
case Scope::FunctionReadOnly:
|
||||
return "Variable is accessible only in the execution path of the function that defined it";
|
||||
default:
|
||||
return "?";
|
||||
@@ -162,6 +155,14 @@ namespace ScriptCanvas
|
||||
"From Component"
|
||||
};
|
||||
|
||||
const char* GraphVariable::s_ScopeNames[static_cast<int>(VariableFlags::Scope::COUNT)] =
|
||||
{
|
||||
"Graph",
|
||||
"Function",
|
||||
"Function",
|
||||
};
|
||||
|
||||
|
||||
void GraphVariable::Reflect(AZ::ReflectContext* context)
|
||||
{
|
||||
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
|
||||
@@ -197,6 +198,13 @@ namespace ScriptCanvas
|
||||
return choices;
|
||||
};
|
||||
|
||||
auto scopeChoices = [] {
|
||||
AZStd::vector< AZStd::pair<VariableFlags::Scope, AZStd::string>> choices;
|
||||
choices.emplace_back(AZStd::make_pair(VariableFlags::Scope::Graph, s_ScopeNames[0]));
|
||||
choices.emplace_back(AZStd::make_pair(VariableFlags::Scope::Function, s_ScopeNames[1]));
|
||||
return choices;
|
||||
};
|
||||
|
||||
editContext->Class<GraphVariable>("Variable", "Represents a Variable field within a Script Canvas Graph")
|
||||
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
|
||||
->Attribute(AZ::Edit::Attributes::Visibility, &GraphVariable::GetVisibility)
|
||||
@@ -215,8 +223,8 @@ namespace ScriptCanvas
|
||||
->Attribute(AZ::Edit::Attributes::ChangeNotify, &GraphVariable::OnValueChanged)
|
||||
|
||||
->DataElement(AZ::Edit::UIHandlers::ComboBox, &GraphVariable::m_scope, "Scope", "Controls the scope of this variable. i.e. If this is exposed as input to this script, or output from this script, or if the variable is just locally scoped.")
|
||||
->Attribute(AZ::Edit::Attributes::Visibility, &GraphVariable::GetInputControlVisibility)
|
||||
->Attribute(AZ::Edit::Attributes::GenericValueList, &GraphVariable::GetScopes)
|
||||
->Attribute(AZ::Edit::Attributes::Visibility, &GraphVariable::GetScopeControlVisibility)
|
||||
->Attribute(AZ::Edit::Attributes::GenericValueList, scopeChoices)
|
||||
->Attribute(AZ::Edit::Attributes::ChangeNotify, &GraphVariable::OnScopeTypedChanged)
|
||||
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &GraphVariable::m_networkProperties, "Network Properties", "Enables whether or not this value should be network synchronized")
|
||||
@@ -382,6 +390,16 @@ namespace ScriptCanvas
|
||||
m_inputControlVisibility = inputControlVisibility;
|
||||
}
|
||||
|
||||
AZ::Crc32 GraphVariable::GetScopeControlVisibility() const
|
||||
{
|
||||
if (m_scope == VariableFlags::Scope::FunctionReadOnly)
|
||||
{
|
||||
return AZ::Edit::PropertyVisibility::Hide;
|
||||
}
|
||||
|
||||
return GetInputControlVisibility();
|
||||
}
|
||||
|
||||
AZ::Crc32 GraphVariable::GetInputControlVisibility() const
|
||||
{
|
||||
return m_inputControlVisibility;
|
||||
@@ -462,6 +480,8 @@ namespace ScriptCanvas
|
||||
return m_scope == VariableFlags::Scope::Graph;
|
||||
// All graph variables are in function local scope
|
||||
case VariableFlags::Scope::Function:
|
||||
case VariableFlags::Scope::FunctionReadOnly:
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -52,8 +52,10 @@ namespace ScriptCanvas
|
||||
|
||||
enum class Scope : AZ::u8
|
||||
{
|
||||
Graph = 0,
|
||||
Function = 1,
|
||||
Graph,
|
||||
Function,
|
||||
FunctionReadOnly,
|
||||
COUNT
|
||||
};
|
||||
|
||||
enum InitialValueSource : AZ::u8
|
||||
@@ -142,6 +144,7 @@ namespace ScriptCanvas
|
||||
void SetScriptInputControlVisibility(const AZ::Crc32& inputControlVisibility);
|
||||
|
||||
AZ::Crc32 GetInputControlVisibility() const;
|
||||
AZ::Crc32 GetScopeControlVisibility() const;
|
||||
AZ::Crc32 GetScriptInputControlVisibility() const;
|
||||
AZ::Crc32 GetNetworkSettingsVisibility() const;
|
||||
AZ::Crc32 GetFunctionInputControlVisibility() const;
|
||||
@@ -181,6 +184,7 @@ namespace ScriptCanvas
|
||||
int GetSortPriority() const;
|
||||
|
||||
static const char* s_InitialValueSourceNames[VariableFlags::InitialValueSource::COUNT];
|
||||
static const char* GraphVariable::s_ScopeNames[VariableFlags::Scope::COUNT];
|
||||
|
||||
private:
|
||||
|
||||
|
||||
+6
-2
@@ -225,7 +225,7 @@ namespace ScriptCanvas
|
||||
}
|
||||
|
||||
// #functions2 slot<->variable add this to the graph, using the old datum
|
||||
AZ::Outcome<VariableId, AZStd::string> GraphVariableManagerComponent::AddVariable(AZStd::string_view name, const Datum& value)
|
||||
AZ::Outcome<VariableId, AZStd::string> GraphVariableManagerComponent::AddVariable(AZStd::string_view name, const Datum& value, bool functionScope)
|
||||
{
|
||||
if (FindVariable(name))
|
||||
{
|
||||
@@ -245,6 +245,10 @@ namespace ScriptCanvas
|
||||
|
||||
GraphVariable* variable = m_variableData.FindVariable(newId);
|
||||
variable->SetOwningScriptCanvasId(GetScriptCanvasId());
|
||||
if (functionScope)
|
||||
{
|
||||
variable->SetScope(VariableFlags::Scope::FunctionReadOnly);
|
||||
}
|
||||
|
||||
VariableRequestBus::MultiHandler::BusConnect(GraphScopedVariableId(m_scriptCanvasId, newId));
|
||||
GraphVariableManagerNotificationBus::Event(GetScriptCanvasId(), &GraphVariableManagerNotifications::OnVariableAddedToGraph, newId, name);
|
||||
@@ -254,7 +258,7 @@ namespace ScriptCanvas
|
||||
|
||||
AZ::Outcome<VariableId, AZStd::string> GraphVariableManagerComponent::AddVariablePair(const AZStd::pair<AZStd::string_view, Datum>& keyValuePair)
|
||||
{
|
||||
return AddVariable(keyValuePair.first, keyValuePair.second);
|
||||
return AddVariable(keyValuePair.first, keyValuePair.second, false);
|
||||
}
|
||||
|
||||
VariableValidationOutcome GraphVariableManagerComponent::IsNameValid(AZStd::string_view varName)
|
||||
|
||||
+1
-1
@@ -63,7 +63,7 @@ namespace ScriptCanvas
|
||||
//// GraphVariableManagerRequestBus
|
||||
AZ::Outcome<VariableId, AZStd::string> CloneVariable(const GraphVariable& variableConfiguration) override;
|
||||
AZ::Outcome<VariableId, AZStd::string> RemapVariable(const GraphVariable& variableConfiguration) override;
|
||||
AZ::Outcome<VariableId, AZStd::string> AddVariable(AZStd::string_view name, const Datum& value) override;
|
||||
AZ::Outcome<VariableId, AZStd::string> AddVariable(AZStd::string_view name, const Datum& value, bool functionScope) override;
|
||||
AZ::Outcome<VariableId, AZStd::string> AddVariablePair(const AZStd::pair<AZStd::string_view, Datum>& nameValuePair) override;
|
||||
|
||||
VariableValidationOutcome IsNameValid(AZStd::string_view key) override;
|
||||
|
||||
@@ -90,7 +90,7 @@ namespace ScriptCanvas
|
||||
//! returns an AZ::Outcome which on success contains the VariableId and on Failure contains a string with error information
|
||||
virtual AZ::Outcome<VariableId, AZStd::string> CloneVariable(const GraphVariable& baseVariable) = 0;
|
||||
virtual AZ::Outcome<VariableId, AZStd::string> RemapVariable(const GraphVariable& variableConfiguration) = 0;
|
||||
virtual AZ::Outcome<VariableId, AZStd::string> AddVariable(AZStd::string_view key, const Datum& value) = 0;
|
||||
virtual AZ::Outcome<VariableId, AZStd::string> AddVariable(AZStd::string_view key, const Datum& value, bool functionScope) = 0;
|
||||
virtual AZ::Outcome<VariableId, AZStd::string> AddVariablePair(const AZStd::pair<AZStd::string_view, Datum>& keyValuePair) = 0;
|
||||
|
||||
virtual VariableValidationOutcome IsNameValid(AZStd::string_view variableName) = 0;
|
||||
|
||||
Reference in New Issue
Block a user