diff options
author | Campbell Barton <ideasman42@gmail.com> | 2008-08-14 12:58:25 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2008-08-14 12:58:25 +0400 |
commit | 47c2271d673173ee93b9d91926de9ea41415d411 (patch) | |
tree | 0a13432423c321cd415a4ea5771e89d7ee56d3d9 /source/gameengine/Ketsji/KX_TrackToActuator.cpp | |
parent | 639f3e12a98f6459cb1f7d948e7a3f2658570b31 (diff) |
Python API get/setObject update for Actuators. (SetParent, AddObject, Camera and TrackTo)
* bugfix for BGE python api - SetParent actuator getObject would segfault if the object was not set.
* Added utility function ConvertPythonToGameObject() that can take a GameObject, string or None and set the game object from this since it was being done in a number of places.
* allow setObject(None), since no object is valid for actuators, Python should be able to set this.
* added optional argument for getObject() so it returns the KX_GameObject rather then its name, would prefer this be default but it could break existing games.
Diffstat (limited to 'source/gameengine/Ketsji/KX_TrackToActuator.cpp')
-rw-r--r-- | source/gameengine/Ketsji/KX_TrackToActuator.cpp | 60 |
1 files changed, 29 insertions, 31 deletions
diff --git a/source/gameengine/Ketsji/KX_TrackToActuator.cpp b/source/gameengine/Ketsji/KX_TrackToActuator.cpp index f5b463abf02..67937d5c579 100644 --- a/source/gameengine/Ketsji/KX_TrackToActuator.cpp +++ b/source/gameengine/Ketsji/KX_TrackToActuator.cpp @@ -454,7 +454,7 @@ PyParentObject KX_TrackToActuator::Parents[] = { PyMethodDef KX_TrackToActuator::Methods[] = { - {"setObject", (PyCFunction) KX_TrackToActuator::sPySetObject, METH_VARARGS, SetObject_doc}, + {"setObject", (PyCFunction) KX_TrackToActuator::sPySetObject, METH_O, SetObject_doc}, {"getObject", (PyCFunction) KX_TrackToActuator::sPyGetObject, METH_VARARGS, GetObject_doc}, {"setTime", (PyCFunction) KX_TrackToActuator::sPySetTime, METH_VARARGS, SetTime_doc}, {"getTime", (PyCFunction) KX_TrackToActuator::sPyGetTime, METH_VARARGS, GetTime_doc}, @@ -475,47 +475,45 @@ PyObject* KX_TrackToActuator::_getattr(const STR_String& attr) /* 1. setObject */ char KX_TrackToActuator::SetObject_doc[] = "setObject(object)\n" -"\t- object: string\n" +"\t- object: KX_GameObject, string or None\n" "\tSet the object to track with the parent of this actuator.\n"; -PyObject* KX_TrackToActuator::PySetObject(PyObject* self, PyObject* args, PyObject* kwds) { - PyObject* gameobj; - if (PyArg_ParseTuple(args, "O!", &KX_GameObject::Type, &gameobj)) - { - if (m_object != NULL) - m_object->UnregisterActuator(this); - m_object = (SCA_IObject*)gameobj; - if (m_object) - m_object->RegisterActuator(this); - Py_Return; - } - PyErr_Clear(); +PyObject* KX_TrackToActuator::PySetObject(PyObject* self, PyObject* value) +{ + KX_GameObject *gameobj; - char* objectname; - if (PyArg_ParseTuple(args, "s", &objectname)) - { - if (m_object != NULL) - m_object->UnregisterActuator(this); - m_object= static_cast<SCA_IObject*>(SCA_ILogicBrick::m_sCurrentLogicManager->GetGameObjectByName(STR_String(objectname))); - if (m_object) - m_object->RegisterActuator(this); - Py_Return; - } + if (!ConvertPythonToGameObject(value, &gameobj, true)) + return NULL; // ConvertPythonToGameObject sets the error - return NULL; + if (m_object != NULL) + m_object->UnregisterActuator(this); + + m_object = (SCA_IObject*)gameobj; + if (m_object) + m_object->RegisterActuator(this); + + Py_RETURN_NONE; } /* 2. getObject */ char KX_TrackToActuator::GetObject_doc[] = -"getObject()\n" -"\tReturns the object to track with the parent of this actuator.\n"; -PyObject* KX_TrackToActuator::PyGetObject(PyObject* self, PyObject* args, PyObject* kwds) +"getObject(name_only = 1)\n" +"name_only - optional arg, when true will return the KX_GameObject rather then its name\n" +"\tReturns the object to track with the parent of this actuator\n"; +PyObject* KX_TrackToActuator::PyGetObject(PyObject* self, PyObject* args) { + int ret_name_only = 1; + if (!PyArg_ParseTuple(args, "|i", &ret_name_only)) + return NULL; + if (!m_object) - Py_Return; - - return PyString_FromString(m_object->GetName()); + Py_RETURN_NONE; + + if (ret_name_only) + return PyString_FromString(m_object->GetName()); + else + return m_object->AddRef(); } |