|
| 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 |
0 commit comments