Skip to content

Commit 5eed906

Browse files
author
Roberto De Ioris
committed
added preliminary support for collections
1 parent 0ac7a03 commit 5eed906

File tree

5 files changed

+157
-1
lines changed

5 files changed

+157
-1
lines changed
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
#if WITH_EDITOR
2+
#include "UnrealEnginePythonPrivatePCH.h"
3+
4+
#include "UEPyICollectionManager.h"
5+
6+
#include "Developer/CollectionManager/Public/CollectionManagerModule.h"
7+
8+
static PyObject *py_ue_icollection_manager_get_collections(PyObject *cls, PyObject * args)
9+
{
10+
PyObject *py_list = PyList_New(0);
11+
ICollectionManager &CollectionManager = FCollectionManagerModule::GetModule().Get();
12+
TArray<FCollectionNameType> collections;
13+
CollectionManager.GetCollections(collections);
14+
for (FCollectionNameType name_type : collections) {
15+
PyList_Append(py_list, Py_BuildValue((char *)"(si)", TCHAR_TO_UTF8(*name_type.Name.ToString()), (int)name_type.Type));
16+
}
17+
return py_list;
18+
}
19+
20+
static PyObject *py_ue_icollection_manager_create_static_collection(PyObject *cls, PyObject * args)
21+
{
22+
char *name;
23+
int type;
24+
25+
if (!PyArg_ParseTuple(args, "si", &name, &type))
26+
return nullptr;
27+
28+
ICollectionManager &CollectionManager = FCollectionManagerModule::GetModule().Get();
29+
30+
if (CollectionManager.CreateCollection(FName(UTF8_TO_TCHAR(name)), (ECollectionShareType::Type)type, ECollectionStorageMode::Static))
31+
Py_RETURN_TRUE;
32+
Py_RETURN_FALSE;
33+
}
34+
35+
static PyObject *py_ue_icollection_manager_create_dynamic_collection(PyObject *cls, PyObject * args)
36+
{
37+
char *name;
38+
int type;
39+
40+
if (!PyArg_ParseTuple(args, "si", &name, &type))
41+
return nullptr;
42+
43+
ICollectionManager &CollectionManager = FCollectionManagerModule::GetModule().Get();
44+
45+
if (CollectionManager.CreateCollection(FName(UTF8_TO_TCHAR(name)), (ECollectionShareType::Type)type, ECollectionStorageMode::Dynamic))
46+
Py_RETURN_TRUE;
47+
Py_RETURN_FALSE;
48+
}
49+
50+
static PyObject *py_ue_icollection_manager_reparent_collection(PyObject *cls, PyObject * args)
51+
{
52+
char *name;
53+
int type;
54+
char *parent;
55+
int parent_type;
56+
57+
if (!PyArg_ParseTuple(args, "sisi", &name, &type, &parent, &parent_type))
58+
return nullptr;
59+
60+
ICollectionManager &CollectionManager = FCollectionManagerModule::GetModule().Get();
61+
62+
if (CollectionManager.ReparentCollection(
63+
FName(UTF8_TO_TCHAR(name)),
64+
(ECollectionShareType::Type)type,
65+
FName(UTF8_TO_TCHAR(parent)),
66+
(ECollectionShareType::Type)parent_type
67+
))
68+
Py_RETURN_TRUE;
69+
Py_RETURN_FALSE;
70+
}
71+
72+
73+
static PyMethodDef ue_PyICollectionManager_methods[] = {
74+
{ "get_collections", (PyCFunction)py_ue_icollection_manager_get_collections, METH_VARARGS | METH_CLASS, "" },
75+
{ "create_static_collection", (PyCFunction)py_ue_icollection_manager_create_static_collection, METH_VARARGS | METH_CLASS, "" },
76+
{ "create_dynamic_collection", (PyCFunction)py_ue_icollection_manager_create_dynamic_collection, METH_VARARGS | METH_CLASS, "" },
77+
{ "reparent_collection", (PyCFunction)py_ue_icollection_manager_reparent_collection, METH_VARARGS | METH_CLASS, "" },
78+
{ NULL } /* Sentinel */
79+
};
80+
81+
82+
static PyTypeObject ue_PyICollectionManagerType = {
83+
PyVarObject_HEAD_INIT(NULL, 0)
84+
"unreal_engine.ICollectionManager", /* tp_name */
85+
sizeof(ue_PyICollectionManager), /* tp_basicsize */
86+
0, /* tp_itemsize */
87+
0, /* tp_dealloc */
88+
0, /* tp_print */
89+
0, /* tp_getattr */
90+
0, /* tp_setattr */
91+
0, /* tp_reserved */
92+
0, /* tp_repr */
93+
0, /* tp_as_number */
94+
0, /* tp_as_sequence */
95+
0, /* tp_as_mapping */
96+
0, /* tp_hash */
97+
0, /* tp_call */
98+
0, /* tp_str */
99+
0, /* tp_getattro */
100+
0, /* tp_setattro */
101+
0, /* tp_as_buffer */
102+
Py_TPFLAGS_DEFAULT, /* tp_flags */
103+
"Unreal Engine CollectionManager Interface", /* tp_doc */
104+
0, /* tp_traverse */
105+
0, /* tp_clear */
106+
0, /* tp_richcompare */
107+
0, /* tp_weaklistoffset */
108+
0, /* tp_iter */
109+
0, /* tp_iternext */
110+
ue_PyICollectionManager_methods, /* tp_methods */
111+
0,
112+
0,
113+
};
114+
115+
static int py_ue_icollection_manager_init(ue_PyICollectionManager *self, PyObject * args)
116+
{
117+
PyErr_SetString(PyExc_Exception, "ICollectionManager is a singleton");
118+
return -1;
119+
}
120+
121+
void ue_python_init_icollection_manager(PyObject *ue_module)
122+
{
123+
ue_PyICollectionManagerType.tp_new = PyType_GenericNew;
124+
ue_PyICollectionManagerType.tp_init = (initproc)py_ue_icollection_manager_init;
125+
126+
if (PyType_Ready(&ue_PyICollectionManagerType) < 0)
127+
return;
128+
129+
Py_INCREF(&ue_PyICollectionManagerType);
130+
PyModule_AddObject(ue_module, "ICollectionManager", (PyObject *)&ue_PyICollectionManagerType);
131+
}
132+
133+
#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 "Developer/CollectionManager/Public/ICollectionManager.h"
8+
9+
10+
typedef struct
11+
{
12+
PyObject_HEAD
13+
/* Type-specific fields go here. */
14+
} ue_PyICollectionManager;
15+
16+
void ue_python_init_icollection_manager(PyObject *);
17+
18+
#endif

Source/UnrealEnginePython/Private/ConsoleManager/UEPyIConsoleManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ static PyTypeObject ue_PyIConsoleManagerType = {
636636

637637
static int py_ue_iconsole_manager_init(ue_PyIConsoleManager *self, PyObject * args)
638638
{
639-
PyErr_SetString(PyExc_Exception, "IConsoleManage is a singleton");
639+
PyErr_SetString(PyExc_Exception, "IConsoleManager is a singleton");
640640
return -1;
641641
}
642642

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1905,6 +1905,10 @@ void unreal_engine_init_py_module()
19051905

19061906
ue_python_init_iconsole_manager(new_unreal_engine_module);
19071907

1908+
#if WITH_EDITOR
1909+
ue_python_init_icollection_manager(new_unreal_engine_module);
1910+
#endif
1911+
19081912
ue_python_init_ivoice_capture(new_unreal_engine_module);
19091913

19101914
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
@@ -67,6 +67,7 @@
6767
#include "UObject/UEPyAnimSequence.h"
6868
#include "Blueprint/UEPyEdGraphPin.h"
6969
#include "UEPyIPlugin.h"
70+
#include "CollectionManager/UEPyICollectionManager.h"
7071
#endif
7172

7273
#include "Slate/UEPySlate.h"

0 commit comments

Comments
 (0)