Skip to content

Commit bc83281

Browse files
author
Roberto De Ioris
committed
preliminary support for plugins
1 parent 6939eda commit bc83281

7 files changed

Lines changed: 123 additions & 1 deletion

File tree

‎Source/UnrealEnginePython/Private/UEPyEditor.cpp‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "Kismet2/BlueprintEditorUtils.h"
1414
#include "Editor/LevelEditor/Public/LevelEditorActions.h"
1515
#include "Editor/UnrealEd/Public/EditorLevelUtils.h"
16+
#include "Runtime/Projects/Public/Interfaces/IPluginManager.h"
1617
#include "ObjectTools.h"
1718

1819

@@ -521,6 +522,20 @@ PyObject *py_unreal_engine_get_assets_by_filter(PyObject * self, PyObject * args
521522
return assets_list;
522523
}
523524

525+
PyObject *py_unreal_engine_get_discovered_plugins(PyObject * self, PyObject * args) {
526+
527+
PyObject *plugins_list = PyList_New(0);
528+
529+
for (TSharedRef<IPlugin>plugin : IPluginManager::Get().GetDiscoveredPlugins()) {
530+
PyObject *ret = py_ue_new_iplugin(&plugin.Get());
531+
if (ret) {
532+
PyList_Append(plugins_list, ret);
533+
}
534+
}
535+
536+
return plugins_list;
537+
}
538+
524539
PyObject *py_unreal_engine_get_assets_by_class(PyObject * self, PyObject * args) {
525540
char *path;
526541
PyObject *py_recursive = nullptr;

‎Source/UnrealEnginePython/Private/UEPyEditor.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ PyObject *py_unreal_engine_get_assets_by_class(PyObject *, PyObject *);
1818
PyObject *py_unreal_engine_get_assets_by_filter(PyObject *, PyObject *, PyObject *);
1919
PyObject *py_unreal_engine_set_fbx_import_option(PyObject *, PyObject *);
2020

21+
PyObject *py_unreal_engine_get_discovered_plugins(PyObject *, PyObject *);
22+
2123
PyObject *py_unreal_engine_rename_asset(PyObject *, PyObject *);
2224
PyObject *py_unreal_engine_duplicate_asset(PyObject *, PyObject *);
2325
PyObject *py_unreal_engine_delete_asset(PyObject *, PyObject *);
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
2+
#if WITH_EDITOR
3+
4+
5+
#include "UnrealEnginePythonPrivatePCH.h"
6+
#include "Runtime/Projects/Public/Interfaces/IPluginManager.h"
7+
8+
static PyObject *py_ue_iplugin_get_name(ue_PyIPlugin *self, PyObject * args) {
9+
return PyUnicode_FromString(TCHAR_TO_UTF8(*(self->plugin->GetName())));
10+
}
11+
12+
13+
static PyMethodDef ue_PyIPlugin_methods[] = {
14+
{ "get_name", (PyCFunction)py_ue_iplugin_get_name, METH_VARARGS, "" },
15+
{ NULL } /* Sentinel */
16+
};
17+
18+
static PyObject *py_ue_iplugin_get_category(ue_PyIPlugin *self, void *closure) {
19+
return PyUnicode_FromString(TCHAR_TO_UTF8(*(self->plugin->GetDescriptor().Category)));
20+
}
21+
22+
static PyGetSetDef ue_PyIPlugin_getseters[] = {
23+
{ (char*)"category", (getter)py_ue_iplugin_get_category, NULL, (char *)"", NULL },
24+
{ NULL } /* Sentinel */
25+
};
26+
27+
static PyObject *ue_PyIPlugin_str(ue_PyIPlugin *self)
28+
{
29+
return PyUnicode_FromFormat("<unreal_engine.EdGraphPin {'name': '%s'}>",
30+
TCHAR_TO_UTF8(*self->plugin->GetName()));
31+
}
32+
33+
static PyTypeObject ue_PyIPluginType = {
34+
PyVarObject_HEAD_INIT(NULL, 0)
35+
"unreal_engine.IPlugin", /* tp_name */
36+
sizeof(ue_PyIPlugin), /* tp_basicsize */
37+
0, /* tp_itemsize */
38+
0, /* tp_dealloc */
39+
0, /* tp_print */
40+
0, /* tp_getattr */
41+
0, /* tp_setattr */
42+
0, /* tp_reserved */
43+
0, /* tp_repr */
44+
0, /* tp_as_number */
45+
0, /* tp_as_sequence */
46+
0, /* tp_as_mapping */
47+
0, /* tp_hash */
48+
0, /* tp_call */
49+
(reprfunc)ue_PyIPlugin_str, /* tp_str */
50+
0, /* tp_getattro */
51+
0, /* tp_setattro */
52+
0, /* tp_as_buffer */
53+
Py_TPFLAGS_DEFAULT, /* tp_flags */
54+
"Unreal Engine Editor IPlugin", /* tp_doc */
55+
0, /* tp_traverse */
56+
0, /* tp_clear */
57+
0, /* tp_richcompare */
58+
0, /* tp_weaklistoffset */
59+
0, /* tp_iter */
60+
0, /* tp_iternext */
61+
ue_PyIPlugin_methods, /* tp_methods */
62+
0,
63+
ue_PyIPlugin_getseters,
64+
};
65+
66+
67+
void ue_python_init_iplugin(PyObject *ue_module) {
68+
ue_PyIPluginType.tp_new = PyType_GenericNew;
69+
70+
if (PyType_Ready(&ue_PyIPluginType) < 0)
71+
return;
72+
73+
Py_INCREF(&ue_PyIPluginType);
74+
PyModule_AddObject(ue_module, "IPlugin", (PyObject *)&ue_PyIPluginType);
75+
}
76+
77+
PyObject *py_ue_new_iplugin(IPlugin *plugin) {
78+
ue_PyIPlugin *ret = (ue_PyIPlugin *)PyObject_New(ue_PyIPlugin, &ue_PyIPluginType);
79+
ret->plugin = plugin;
80+
return (PyObject *)ret;
81+
}
82+
#endif
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#pragma once
2+
3+
#if WITH_EDITOR
4+
5+
#include "UnrealEnginePython.h"
6+
7+
#include "Runtime/Projects/Public/Interfaces/IPluginManager.h"
8+
9+
typedef struct {
10+
PyObject_HEAD
11+
/* Type-specific fields go here. */
12+
IPlugin *plugin;
13+
} ue_PyIPlugin;
14+
15+
PyObject *py_ue_new_iplugin(IPlugin *);
16+
17+
void ue_python_init_iplugin(PyObject *);
18+
#endif

‎Source/UnrealEnginePython/Private/UEPyModule.cpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ static PyMethodDef unreal_engine_methods[] = {
153153
{ "editor_command_save_all_levels", py_unreal_engine_editor_command_save_all_levels, METH_VARARGS, "" },
154154

155155
{ "editor_save_all", py_unreal_engine_editor_save_all, METH_VARARGS, "" },
156+
157+
{ "get_discovered_plugins", py_unreal_engine_get_discovered_plugins, METH_VARARGS, "" },
156158
#pragma warning(suppress: 4191)
157159
{ "get_assets_by_filter", (PyCFunction)py_unreal_engine_get_assets_by_filter, METH_VARARGS | METH_KEYWORDS, "" },
158160
{ "create_blueprint", py_unreal_engine_create_blueprint, METH_VARARGS, "" },
@@ -1048,6 +1050,7 @@ void unreal_engine_init_py_module() {
10481050
ue_python_init_farfilter(new_unreal_engine_module);
10491051
ue_python_init_fassetdata(new_unreal_engine_module);
10501052
ue_python_init_edgraphpin(new_unreal_engine_module);
1053+
ue_python_init_iplugin(new_unreal_engine_module);
10511054
#endif
10521055

10531056
PyObject *py_sys = PyImport_ImportModule("sys");

‎Source/UnrealEnginePython/Private/UnrealEnginePythonPrivatePCH.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "UEPyFARFilter.h"
4545
#include "UEPyAnimSequence.h"
4646
#include "UEPyEdGraphPin.h"
47+
#include "UEPyIPlugin.h"
4748
#endif
4849

4950
#define ue_py_check(py_u) if (!py_u->ue_object || !py_u->ue_object->IsValidLowLevel() || py_u->ue_object->IsPendingKillOrUnreachable())\

‎Source/UnrealEnginePython/UnrealEnginePython.Build.cs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ public UnrealEnginePython(TargetInfo Target)
8787
PrivateDependencyModuleNames.AddRange(new string[]{
8888
"UnrealEd",
8989
"LevelEditor",
90-
"BlueprintGraph"
90+
"BlueprintGraph",
91+
"Projects"
9192
});
9293
}
9394

0 commit comments

Comments
 (0)