diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-02-28 02:53:09 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-02-28 02:53:09 +0300 |
commit | 8d3dcfb104bcfc4fa9fdfecaa8e5c8fd9a900e98 (patch) | |
tree | 0fa6ffbaff90c088e346a14a2462796d5c0735fb /source/gameengine/Ketsji | |
parent | e872843c85434efad2c1a082c4ecad2008ab1ef5 (diff) |
BGE Python API
* Scene's and GameObjects can now be printed (raised an exception)
* Added GameLogic.getSceneList()
Diffstat (limited to 'source/gameengine/Ketsji')
-rw-r--r-- | source/gameengine/Ketsji/KX_GameObject.h | 3 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_PythonInit.cpp | 28 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_Scene.h | 2 |
3 files changed, 32 insertions, 1 deletions
diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index d95e3751d33..211c9b7ca7d 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -758,7 +758,8 @@ public: virtual PyObject* _getattr(const char *attr); virtual int _setattr(const char *attr, PyObject *value); // _setattr method - + virtual PyObject* _repr(void) { return PyString_FromString(GetName().ReadPtr()); } + KX_PYMETHOD_NOARGS(KX_GameObject,GetPosition); KX_PYMETHOD_O(KX_GameObject,SetPosition); KX_PYMETHOD_O(KX_GameObject,SetWorldPosition); diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index b3e8d15189f..93f57986181 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -329,6 +329,32 @@ static PyObject* gPyGetCurrentScene(PyObject* self) return (PyObject*) gp_KetsjiScene; } +static STR_String gPyGetSceneList_doc = +"getSceneList()\n" +"Return a list of converted scenes.\n"; +static PyObject* gPyGetSceneList(PyObject* self) +{ + KX_KetsjiEngine* m_engine = KX_GetActiveEngine(); + //CListValue* list = new CListValue(); + PyObject* list; + KX_SceneList* scenes = m_engine->CurrentScenes(); + int numScenes = scenes->size(); + int i; + + list = PyList_New(numScenes); + + for (i=0;i<numScenes;i++) + { + KX_Scene* scene = scenes->at(i); + //list->Add(scene); + PyList_SET_ITEM(list, i, scene); + Py_INCREF(scene); + + } + + return (PyObject*)list; +} + static PyObject *pyPrintExt(PyObject *,PyObject *,PyObject *) { #define pprint(x) std::cout << x << std::endl; @@ -408,6 +434,8 @@ static struct PyMethodDef game_methods[] = { METH_NOARGS, (PY_METHODCHAR)SCA_PythonController::sPyGetCurrentController__doc__}, {"getCurrentScene", (PyCFunction) gPyGetCurrentScene, METH_NOARGS, (PY_METHODCHAR)gPyGetCurrentScene_doc.Ptr()}, + {"getSceneList", (PyCFunction) gPyGetSceneList, + METH_NOARGS, (PY_METHODCHAR)gPyGetSceneList_doc.Ptr()}, {"addActiveActuator",(PyCFunction) SCA_PythonController::sPyAddActiveActuator, METH_VARARGS, (PY_METHODCHAR)SCA_PythonController::sPyAddActiveActuator__doc__}, {"getRandomFloat",(PyCFunction) gPyGetRandomFloat, diff --git a/source/gameengine/Ketsji/KX_Scene.h b/source/gameengine/Ketsji/KX_Scene.h index e4d4b6fe2cd..e49a87b0402 100644 --- a/source/gameengine/Ketsji/KX_Scene.h +++ b/source/gameengine/Ketsji/KX_Scene.h @@ -567,7 +567,9 @@ public: virtual PyObject* _getattr(const char *attr); /* name, active_camera, gravity, suspended, viewport, framing, activity_culling, activity_culling_radius */ virtual int _setattr(const char *attr, PyObject *pyvalue); virtual int _delattr(const char *attr); + virtual PyObject* _repr(void) { return PyString_FromString(GetName().ReadPtr()); } + /** * Sets the time the scene was suspended */ |