diff options
Diffstat (limited to 'source/gameengine/Ketsji/KX_PythonMain.cpp')
-rw-r--r-- | source/gameengine/Ketsji/KX_PythonMain.cpp | 63 |
1 files changed, 35 insertions, 28 deletions
diff --git a/source/gameengine/Ketsji/KX_PythonMain.cpp b/source/gameengine/Ketsji/KX_PythonMain.cpp index 740bb102fd9..969ecbea5a9 100644 --- a/source/gameengine/Ketsji/KX_PythonMain.cpp +++ b/source/gameengine/Ketsji/KX_PythonMain.cpp @@ -1,4 +1,6 @@ -/* +/* + * $Id: KX_PythonMain.cpp 37750 2011-06-27 09:27:56Z sjoerd $ + * * ***** BEGIN GPL LICENSE BLOCK ***** * * This program is free software; you can redistribute it and/or @@ -15,12 +17,16 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Contributor(s): Benoit Bolsee + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. * * ***** END GPL LICENSE BLOCK ***** */ - -/** \file gameengine/Ketsji/KX_PythonMain.cpp +/** \file gameengine/Ketsji/KX_KetsjiPythonMain.cpp * \ingroup ketsji */ @@ -30,42 +36,43 @@ extern "C" { #endif -#include <stddef.h> - +#include "RNA_access.h" #include "MEM_guardedalloc.h" - -#include "BLI_string.h" -#include "BLI_listbase.h" - #include "BKE_text.h" #include "BKE_main.h" -#include "BKE_idprop.h" - #ifdef __cplusplus } #endif -extern "C" char *KX_GetPythonMain(struct Scene *scene) +extern "C" char *KX_GetPythonMain(struct Scene* scene) { - /* examine custom scene properties */ - if (scene->id.properties) { - IDProperty *item = IDP_GetPropertyTypeFromGroup(scene->id.properties, "__main__", IDP_STRING); - if (item) { - return BLI_strdup(IDP_String(item)); - } - } + //examine custom scene properties + + PointerRNA sceneptr; + RNA_id_pointer_create(&scene->id, &sceneptr); - return NULL; + PropertyRNA *pymain = RNA_struct_find_property(&sceneptr, "[\"__main__\"]"); + if (pymain == NULL) return NULL; + char *python_main; + int len; + python_main = RNA_property_string_get_alloc(&sceneptr, pymain, NULL, 0, &len); + return python_main; } -extern "C" char *KX_GetPythonCode(Main *bmain, char *python_main) +extern "C" char *KX_GetPythonCode(Main *main, char *python_main) { - Text *text; + PointerRNA mainptr, txtptr; + PropertyRNA *texts; - if ((text = (Text *)BLI_findstring(&bmain->text, python_main, offsetof(ID, name) + 2))) { - return txt_to_buf(text); - } - - return NULL; + RNA_main_pointer_create(main, &mainptr); + texts = RNA_struct_find_property(&mainptr, "texts"); + char *python_code = NULL; + int ok = RNA_property_collection_lookup_string(&mainptr, texts, python_main, &txtptr); + if (ok) { + Text *text = (Text *) txtptr.data; + python_code = txt_to_buf(text); + } + return python_code; } + |