Skip to content

Commit

Permalink
GH-825 Refactor OScriptLanguage & add OScriptNodeFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
Naros committed Oct 26, 2024
1 parent d091f26 commit b84fff2
Show file tree
Hide file tree
Showing 9 changed files with 328 additions and 275 deletions.
5 changes: 2 additions & 3 deletions src/editor/graph/actions/default_action_registrar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@

void OrchestratorDefaultGraphActionRegistrar::_register_node(const StringName& p_class_name, const StringName& p_category, const Dictionary& p_data)
{
OScriptLanguage* language = OScriptLanguage::get_singleton();
Orchestration* orchestration = _context->graph->get_orchestration();

const Ref<OScriptNode> node = language->create_node_from_name(p_class_name, orchestration, false);
if (!node->get_flags().has_flag(OScriptNode::ScriptNodeFlags::CATALOGABLE))
const Ref<OScriptNode> node = OScriptNodeFactory::create_node_from_name(p_class_name, orchestration);
if (!node.is_valid() || !node->get_flags().has_flag(OScriptNode::ScriptNodeFlags::CATALOGABLE))
return;

PackedStringArray name_parts = p_category.split("/");
Expand Down
148 changes: 74 additions & 74 deletions src/editor/register_editor_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,96 +58,96 @@
void register_editor_types()
{
// Plugin bits
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorPlugin)
GDREGISTER_INTERNAL_CLASS(OrchestratorPlugin)
#if GODOT_VERSION >= 0x040300
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorEditorDebuggerPlugin)
GDREGISTER_INTERNAL_CLASS(OrchestratorEditorDebuggerPlugin)
#endif
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorEditorExportPlugin)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorEditorInspectorPluginFunction)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorEditorInspectorPluginSignal)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorEditorInspectorPluginVariable)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorThemeCache)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorEditorCache)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorBuildOutputPanel)
GDREGISTER_INTERNAL_CLASS(OrchestratorEditorExportPlugin)
GDREGISTER_INTERNAL_CLASS(OrchestratorEditorInspectorPluginFunction)
GDREGISTER_INTERNAL_CLASS(OrchestratorEditorInspectorPluginSignal)
GDREGISTER_INTERNAL_CLASS(OrchestratorEditorInspectorPluginVariable)
GDREGISTER_INTERNAL_CLASS(OrchestratorThemeCache)
GDREGISTER_INTERNAL_CLASS(OrchestratorEditorCache)
GDREGISTER_INTERNAL_CLASS(OrchestratorBuildOutputPanel)

// Editor bits
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorPropertyInfoContainerEditorProperty)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorEditorPropertyVariableClassification)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorFileDialog)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorEditorSearchDialogItem)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorEditorSearchDialog)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorSelectTypeSearchDialog)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorEditorSearchHelpBit)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorScriptAutowireSelections)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorPropertySelector)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorSceneNodeSelector)
GDREGISTER_INTERNAL_CLASS(OrchestratorPropertyInfoContainerEditorProperty)
GDREGISTER_INTERNAL_CLASS(OrchestratorEditorPropertyVariableClassification)
GDREGISTER_INTERNAL_CLASS(OrchestratorFileDialog)
GDREGISTER_INTERNAL_CLASS(OrchestratorEditorSearchDialogItem)
GDREGISTER_INTERNAL_CLASS(OrchestratorEditorSearchDialog)
GDREGISTER_INTERNAL_CLASS(OrchestratorSelectTypeSearchDialog)
GDREGISTER_INTERNAL_CLASS(OrchestratorEditorSearchHelpBit)
GDREGISTER_INTERNAL_CLASS(OrchestratorScriptAutowireSelections)
GDREGISTER_INTERNAL_CLASS(OrchestratorPropertySelector)
GDREGISTER_INTERNAL_CLASS(OrchestratorSceneNodeSelector)

// Action components
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorGraphActionMenu)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorGraphActionMenuItem)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorGraphActionHandler)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorGraphNodeSpawner)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorGraphActionRegistrar)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorDefaultGraphActionRegistrar)
GDREGISTER_INTERNAL_CLASS(OrchestratorGraphActionMenu)
GDREGISTER_INTERNAL_CLASS(OrchestratorGraphActionMenuItem)
GDREGISTER_INTERNAL_CLASS(OrchestratorGraphActionHandler)
GDREGISTER_INTERNAL_CLASS(OrchestratorGraphNodeSpawner)
GDREGISTER_INTERNAL_CLASS(OrchestratorGraphActionRegistrar)
GDREGISTER_INTERNAL_CLASS(OrchestratorDefaultGraphActionRegistrar)

// Node spawners
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorGraphNodeSpawnerProperty)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorGraphNodeSpawnerPropertyGet)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorGraphNodeSpawnerPropertySet)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorGraphNodeSpawnerCallMemberFunction)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorGraphNodeSpawnerCallScriptFunction)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorGraphNodeSpawnerEvent)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorGraphNodeSpawnerEmitMemberSignal)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorGraphNodeSpawnerEmitSignal)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorGraphNodeSpawnerVariable)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorGraphNodeSpawnerVariableGet)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorGraphNodeSpawnerVariableSet)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorGraphNodeSpawnerScriptNode)
GDREGISTER_INTERNAL_CLASS(OrchestratorGraphNodeSpawnerProperty)
GDREGISTER_INTERNAL_CLASS(OrchestratorGraphNodeSpawnerPropertyGet)
GDREGISTER_INTERNAL_CLASS(OrchestratorGraphNodeSpawnerPropertySet)
GDREGISTER_INTERNAL_CLASS(OrchestratorGraphNodeSpawnerCallMemberFunction)
GDREGISTER_INTERNAL_CLASS(OrchestratorGraphNodeSpawnerCallScriptFunction)
GDREGISTER_INTERNAL_CLASS(OrchestratorGraphNodeSpawnerEvent)
GDREGISTER_INTERNAL_CLASS(OrchestratorGraphNodeSpawnerEmitMemberSignal)
GDREGISTER_INTERNAL_CLASS(OrchestratorGraphNodeSpawnerEmitSignal)
GDREGISTER_INTERNAL_CLASS(OrchestratorGraphNodeSpawnerVariable)
GDREGISTER_INTERNAL_CLASS(OrchestratorGraphNodeSpawnerVariableGet)
GDREGISTER_INTERNAL_CLASS(OrchestratorGraphNodeSpawnerVariableSet)
GDREGISTER_INTERNAL_CLASS(OrchestratorGraphNodeSpawnerScriptNode)

// View components
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorEditorPanel)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorEditorViewport)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorScriptEditorViewport)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorGotoNodeDialog)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorUpdaterButton)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorUpdaterVersionPicker)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorUpdaterReleaseNotesDialog)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorAboutDialog)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorScreenSelect)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorWindowWrapper)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorGettingStarted)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorScriptConnectionsDialog)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorScriptComponentPanel)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorScriptFunctionsComponentPanel)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorScriptGraphsComponentPanel)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorScriptMacrosComponentPanel)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorScriptSignalsComponentPanel)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorScriptVariablesComponentPanel)
GDREGISTER_INTERNAL_CLASS(OrchestratorEditorPanel)
GDREGISTER_INTERNAL_CLASS(OrchestratorEditorViewport)
GDREGISTER_INTERNAL_CLASS(OrchestratorScriptEditorViewport)
GDREGISTER_INTERNAL_CLASS(OrchestratorGotoNodeDialog)
GDREGISTER_INTERNAL_CLASS(OrchestratorUpdaterButton)
GDREGISTER_INTERNAL_CLASS(OrchestratorUpdaterVersionPicker)
GDREGISTER_INTERNAL_CLASS(OrchestratorUpdaterReleaseNotesDialog)
GDREGISTER_INTERNAL_CLASS(OrchestratorAboutDialog)
GDREGISTER_INTERNAL_CLASS(OrchestratorScreenSelect)
GDREGISTER_INTERNAL_CLASS(OrchestratorWindowWrapper)
GDREGISTER_INTERNAL_CLASS(OrchestratorGettingStarted)
GDREGISTER_INTERNAL_CLASS(OrchestratorScriptConnectionsDialog)
GDREGISTER_INTERNAL_CLASS(OrchestratorScriptComponentPanel)
GDREGISTER_INTERNAL_CLASS(OrchestratorScriptFunctionsComponentPanel)
GDREGISTER_INTERNAL_CLASS(OrchestratorScriptGraphsComponentPanel)
GDREGISTER_INTERNAL_CLASS(OrchestratorScriptMacrosComponentPanel)
GDREGISTER_INTERNAL_CLASS(OrchestratorScriptSignalsComponentPanel)
GDREGISTER_INTERNAL_CLASS(OrchestratorScriptVariablesComponentPanel)

// Graph Classes
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorGraphEdit)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorGraphNode)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorGraphNodePin)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorKnotPoint)
GDREGISTER_INTERNAL_CLASS(OrchestratorGraphEdit)
GDREGISTER_INTERNAL_CLASS(OrchestratorGraphNode)
GDREGISTER_INTERNAL_CLASS(OrchestratorGraphNodePin)
GDREGISTER_INTERNAL_CLASS(OrchestratorKnotPoint)

// Graph Node Type
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorGraphNodeDefault)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorGraphNodeComment)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorGraphKnot)
GDREGISTER_INTERNAL_CLASS(OrchestratorGraphNodeDefault)
GDREGISTER_INTERNAL_CLASS(OrchestratorGraphNodeComment)
GDREGISTER_INTERNAL_CLASS(OrchestratorGraphKnot)

// Graph Pin Types
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorGraphNodePinBitField)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorGraphNodePinBool)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorGraphNodePinColor)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorGraphNodePinEnum)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorGraphNodePinExec)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorGraphNodePinFile)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorGraphNodePinInputAction)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorGraphNodePinNodePath)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorGraphNodePinNumeric)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorGraphNodePinObject)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorGraphNodePinString)
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorGraphNodePinStruct)
GDREGISTER_INTERNAL_CLASS(OrchestratorGraphNodePinBitField)
GDREGISTER_INTERNAL_CLASS(OrchestratorGraphNodePinBool)
GDREGISTER_INTERNAL_CLASS(OrchestratorGraphNodePinColor)
GDREGISTER_INTERNAL_CLASS(OrchestratorGraphNodePinEnum)
GDREGISTER_INTERNAL_CLASS(OrchestratorGraphNodePinExec)
GDREGISTER_INTERNAL_CLASS(OrchestratorGraphNodePinFile)
GDREGISTER_INTERNAL_CLASS(OrchestratorGraphNodePinInputAction)
GDREGISTER_INTERNAL_CLASS(OrchestratorGraphNodePinNodePath)
GDREGISTER_INTERNAL_CLASS(OrchestratorGraphNodePinNumeric)
GDREGISTER_INTERNAL_CLASS(OrchestratorGraphNodePinObject)
GDREGISTER_INTERNAL_CLASS(OrchestratorGraphNodePinString)
GDREGISTER_INTERNAL_CLASS(OrchestratorGraphNodePinStruct)

// Add plugin to the editor
EditorPlugins::add_by_type<OrchestratorPlugin>();
Expand Down
5 changes: 4 additions & 1 deletion src/script/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,12 @@ void OScriptGraph::remove_connection_knot(uint64_t p_connection_id)

Ref<OScriptNode> OScriptGraph::create_node(const StringName& p_type, const OScriptNodeInitContext& p_context, const Vector2& p_position)
{
const Ref<OScriptNode> spawned = OScriptLanguage::get_singleton()->create_node_from_name(p_type, _orchestration);
const Ref<OScriptNode> spawned = OScriptNodeFactory::create_node_from_name(p_type, _orchestration);
if (spawned.is_valid())
{
spawned->set_id(_orchestration->get_available_id());
_initialize_node(spawned, p_context, p_position);
}

return spawned;
}
33 changes: 0 additions & 33 deletions src/script/language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#endif

OScriptLanguage* OScriptLanguage::_singleton = nullptr;
HashMap<StringName, OScriptLanguage::ScriptNodeInfo> OScriptLanguage::_nodes;

OScriptLanguage::OScriptLanguage()
{
Expand All @@ -59,27 +58,6 @@ OScriptLanguage* OScriptLanguage::get_singleton()
return _singleton;
}

void OScriptLanguage::_add_node_class_internal(const StringName& p_class, const StringName& p_inherits)
{
const StringName& name = p_class;
ERR_FAIL_COND_MSG(_nodes.has(name), "Class '" + String(p_class) + "' already exists.");

_nodes[name] = ScriptNodeInfo();
ScriptNodeInfo& sni = _nodes[name];
sni.name = name;
sni.inherits = p_inherits;

if (!sni.inherits.is_empty())
{
ERR_FAIL_COND_MSG(!_nodes.has(sni.inherits), "Node " + p_inherits + " is not defined as a node");
sni.inherits_ptr = &_nodes[sni.inherits];
}
else
{
sni.inherits_ptr = nullptr;
}
}

void OScriptLanguage::_init()
{
Logger::info("Initializing OrchestratorScript");
Expand Down Expand Up @@ -729,14 +707,3 @@ String OScriptLanguage::get_script_extension_filter() const

return StringUtils::join(",", results);
}

Ref<OScriptNode> OScriptLanguage::create_node_from_name(const String& p_class_name, Orchestration* p_owner, bool p_allocate_id)
{
ERR_FAIL_COND_V_MSG(!_nodes.has(p_class_name), Ref<OScriptNode>(), "No node found with name: " + p_class_name);

Ref<OScriptNode> node(_nodes[p_class_name].creation_func());
node->set_id(p_allocate_id ? p_owner->get_available_id() : -1);
node->_orchestration = p_owner;

return node;
}
Loading

0 comments on commit b84fff2

Please sign in to comment.