|
4 | 4 | #include "EngineUtils.h" |
5 | 5 | #include "Kismet/GameplayStatics.h" |
6 | 6 | #include "Runtime/CoreUObject/Public/UObject/UObjectIterator.h" |
| 7 | +#if WITH_EDITOR |
| 8 | +#include "Editor/UnrealEd/Public/EditorActorFolders.h" |
| 9 | +#endif |
7 | 10 |
|
8 | 11 | PyObject *py_ue_world_exec(ue_PyUObject *self, PyObject * args) |
9 | 12 | { |
@@ -315,3 +318,105 @@ PyObject *py_ue_set_current_level(ue_PyUObject *self, PyObject * args) |
315 | 318 | Py_RETURN_FALSE; |
316 | 319 | } |
317 | 320 |
|
| 321 | +#if WITH_EDITOR |
| 322 | +PyObject *py_ue_world_create_folder(ue_PyUObject *self, PyObject * args) |
| 323 | +{ |
| 324 | + |
| 325 | + ue_py_check(self); |
| 326 | + |
| 327 | + char *path; |
| 328 | + if (!PyArg_ParseTuple(args, "s:world_create_folder", &path)) |
| 329 | + return nullptr; |
| 330 | + |
| 331 | + if (!FActorFolders::IsAvailable()) |
| 332 | + return PyErr_Format(PyExc_Exception, "FActorFolders is not available"); |
| 333 | + |
| 334 | + UWorld *world = ue_get_uworld(self); |
| 335 | + if (!world) |
| 336 | + return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject"); |
| 337 | + |
| 338 | + FName FolderPath = FName(UTF8_TO_TCHAR(path)); |
| 339 | + |
| 340 | + FActorFolders::Get().CreateFolder(*world, FolderPath); |
| 341 | + |
| 342 | + Py_RETURN_NONE; |
| 343 | +} |
| 344 | + |
| 345 | +PyObject *py_ue_world_delete_folder(ue_PyUObject *self, PyObject * args) |
| 346 | +{ |
| 347 | + |
| 348 | + ue_py_check(self); |
| 349 | + |
| 350 | + char *path; |
| 351 | + if (!PyArg_ParseTuple(args, "s:world_delete_folder", &path)) |
| 352 | + return nullptr; |
| 353 | + |
| 354 | + if (!FActorFolders::IsAvailable()) |
| 355 | + return PyErr_Format(PyExc_Exception, "FActorFolders is not available"); |
| 356 | + |
| 357 | + UWorld *world = ue_get_uworld(self); |
| 358 | + if (!world) |
| 359 | + return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject"); |
| 360 | + |
| 361 | + FName FolderPath = FName(UTF8_TO_TCHAR(path)); |
| 362 | + |
| 363 | + FActorFolders::Get().DeleteFolder(*world, FolderPath); |
| 364 | + |
| 365 | + Py_RETURN_NONE; |
| 366 | +} |
| 367 | + |
| 368 | +PyObject *py_ue_world_rename_folder(ue_PyUObject *self, PyObject * args) |
| 369 | +{ |
| 370 | + |
| 371 | + ue_py_check(self); |
| 372 | + |
| 373 | + char *path; |
| 374 | + char *new_path; |
| 375 | + if (!PyArg_ParseTuple(args, "ss:world_rename_folder", &path, &new_path)) |
| 376 | + return nullptr; |
| 377 | + |
| 378 | + if (!FActorFolders::IsAvailable()) |
| 379 | + return PyErr_Format(PyExc_Exception, "FActorFolders is not available"); |
| 380 | + |
| 381 | + UWorld *world = ue_get_uworld(self); |
| 382 | + if (!world) |
| 383 | + return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject"); |
| 384 | + |
| 385 | + FName FolderPath = FName(UTF8_TO_TCHAR(path)); |
| 386 | + FName NewFolderPath = FName(UTF8_TO_TCHAR(new_path)); |
| 387 | + |
| 388 | + if (FActorFolders::Get().RenameFolderInWorld(*world, FolderPath, NewFolderPath)) |
| 389 | + Py_RETURN_TRUE; |
| 390 | + |
| 391 | + Py_RETURN_FALSE; |
| 392 | +} |
| 393 | + |
| 394 | +PyObject *py_ue_world_folders(ue_PyUObject *self, PyObject * args) |
| 395 | +{ |
| 396 | + |
| 397 | + ue_py_check(self); |
| 398 | + |
| 399 | + if (!FActorFolders::IsAvailable()) |
| 400 | + return PyErr_Format(PyExc_Exception, "FActorFolders is not available"); |
| 401 | + |
| 402 | + UWorld *world = ue_get_uworld(self); |
| 403 | + if (!world) |
| 404 | + return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject"); |
| 405 | + |
| 406 | + const TMap<FName, FActorFolderProps> &Folders = FActorFolders::Get().GetFolderPropertiesForWorld(*world); |
| 407 | + |
| 408 | + PyObject *py_list = PyList_New(0); |
| 409 | + |
| 410 | + TArray<FName> FolderNames; |
| 411 | + Folders.GenerateKeyArray(FolderNames); |
| 412 | + |
| 413 | + for (FName FolderName : FolderNames) |
| 414 | + { |
| 415 | + PyObject *py_str = PyUnicode_FromString(TCHAR_TO_UTF8(*FolderName.ToString())); |
| 416 | + PyList_Append(py_list, py_str); |
| 417 | + Py_DECREF(py_str); |
| 418 | + } |
| 419 | + |
| 420 | + return py_list; |
| 421 | +} |
| 422 | +#endif |
0 commit comments