forked from bartvdbraak/blender
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.
This commit is contained in:
parent
639f3e12a9
commit
47c2271d67
@ -540,9 +540,16 @@ void BL_ConvertActuators(char* maggiename,
|
||||
// does the 'original' for replication exists, and
|
||||
// is it in a non-active layer ?
|
||||
SCA_IObject* originalval = NULL;
|
||||
if (editobact->ob && !(editobact->ob->lay & activeLayerBitInfo))
|
||||
originalval = converter->FindGameObject(editobact->ob);
|
||||
|
||||
if (editobact->ob)
|
||||
{
|
||||
if (editobact->ob->lay & activeLayerBitInfo)
|
||||
{
|
||||
fprintf(stderr, "Warning, object \"%s\" from AddObject actuator \"%s\" is not in a hidden layer.\n", objectname.Ptr(), uniquename.Ptr());
|
||||
}
|
||||
else {
|
||||
originalval = converter->FindGameObject(editobact->ob);
|
||||
}
|
||||
}
|
||||
MT_Vector3 linvelvec ( KX_BLENDERTRUNC(editobact->linVelocity[0]),
|
||||
KX_BLENDERTRUNC(editobact->linVelocity[1]),
|
||||
KX_BLENDERTRUNC(editobact->linVelocity[2]));
|
||||
|
@ -121,6 +121,13 @@ static inline void Py_Fatal(char *M) {
|
||||
}; \
|
||||
static char method_name##_doc[]; \
|
||||
|
||||
#define KX_PYMETHOD_DOC_VARARGS(class_name, method_name) \
|
||||
PyObject* Py##method_name(PyObject* self, PyObject* args); \
|
||||
static PyObject* sPy##method_name( PyObject* self, PyObject* args) { \
|
||||
return ((class_name*) self)->Py##method_name(self, args); \
|
||||
}; \
|
||||
static char method_name##_doc[]; \
|
||||
|
||||
#define KX_PYMETHOD_DOC_O(class_name, method_name) \
|
||||
PyObject* Py##method_name(PyObject* self, PyObject* value); \
|
||||
static PyObject* sPy##method_name( PyObject* self, PyObject* value) { \
|
||||
|
@ -395,8 +395,8 @@ PyParentObject KX_CameraActuator::Parents[] = {
|
||||
};
|
||||
|
||||
PyMethodDef KX_CameraActuator::Methods[] = {
|
||||
{"setObject",(PyCFunction) KX_CameraActuator::sPySetObject, METH_VARARGS, SetObject_doc},
|
||||
{"getObject",(PyCFunction) KX_CameraActuator::sPyGetObject, METH_NOARGS, GetObject_doc},
|
||||
{"setObject",(PyCFunction) KX_CameraActuator::sPySetObject, METH_O, SetObject_doc},
|
||||
{"getObject",(PyCFunction) KX_CameraActuator::sPyGetObject, METH_VARARGS, GetObject_doc},
|
||||
{"setMin" ,(PyCFunction) KX_CameraActuator::sPySetMin, METH_VARARGS, SetMin_doc},
|
||||
{"getMin" ,(PyCFunction) KX_CameraActuator::sPyGetMin, METH_NOARGS, GetMin_doc},
|
||||
{"setMax" ,(PyCFunction) KX_CameraActuator::sPySetMax, METH_VARARGS, SetMax_doc},
|
||||
@ -413,50 +413,43 @@ PyObject* KX_CameraActuator::_getattr(const STR_String& attr) {
|
||||
}
|
||||
/* get obj ---------------------------------------------------------- */
|
||||
char KX_CameraActuator::GetObject_doc[] =
|
||||
"getObject\n"
|
||||
"getObject(name_only = 1)\n"
|
||||
"name_only - optional arg, when true will return the KX_GameObject rather then its name\n"
|
||||
"\tReturns the object this sensor reacts to.\n";
|
||||
PyObject* KX_CameraActuator::PyGetObject(PyObject* self,
|
||||
PyObject* args,
|
||||
PyObject* kwds)
|
||||
PyObject* KX_CameraActuator::PyGetObject(PyObject* self, PyObject* args)
|
||||
{
|
||||
return PyString_FromString(m_ob->GetName());
|
||||
int ret_name_only = 1;
|
||||
if (!PyArg_ParseTuple(args, "|i", &ret_name_only))
|
||||
return NULL;
|
||||
|
||||
if (!m_ob)
|
||||
Py_RETURN_NONE;
|
||||
|
||||
if (ret_name_only)
|
||||
return PyString_FromString(m_ob->GetName());
|
||||
else
|
||||
return m_ob->AddRef();
|
||||
}
|
||||
/* set obj ---------------------------------------------------------- */
|
||||
char KX_CameraActuator::SetObject_doc[] =
|
||||
"setObject\n"
|
||||
"setObject(object)\n"
|
||||
"\t- object: KX_GameObject, string or None\n"
|
||||
"\tSets the object this sensor reacts to.\n";
|
||||
PyObject* KX_CameraActuator::PySetObject(PyObject* self,
|
||||
PyObject* args,
|
||||
PyObject* kwds)
|
||||
PyObject* KX_CameraActuator::PySetObject(PyObject* self, PyObject* value)
|
||||
{
|
||||
|
||||
PyObject* gameobj;
|
||||
if (PyArg_ParseTuple(args, "O!", &KX_GameObject::Type, &gameobj))
|
||||
{
|
||||
if (m_ob)
|
||||
m_ob->UnregisterActuator(this);
|
||||
m_ob = (SCA_IObject*)gameobj;
|
||||
if (m_ob)
|
||||
m_ob->RegisterActuator(this);
|
||||
Py_Return;
|
||||
}
|
||||
PyErr_Clear();
|
||||
KX_GameObject *gameobj;
|
||||
|
||||
char* objectname;
|
||||
if (PyArg_ParseTuple(args, "s", &objectname))
|
||||
{
|
||||
SCA_IObject *object = (SCA_IObject*)SCA_ILogicBrick::m_sCurrentLogicManager->GetGameObjectByName(STR_String(objectname));
|
||||
if(object)
|
||||
{
|
||||
if (m_ob != NULL)
|
||||
m_ob->UnregisterActuator(this);
|
||||
m_ob = object;
|
||||
m_ob->RegisterActuator(this);
|
||||
Py_Return;
|
||||
}
|
||||
}
|
||||
if (!ConvertPythonToGameObject(value, &gameobj, true))
|
||||
return NULL; // ConvertPythonToGameObject sets the error
|
||||
|
||||
return NULL;
|
||||
if (m_ob != NULL)
|
||||
m_ob->UnregisterActuator(this);
|
||||
|
||||
m_ob = (SCA_IObject*)gameobj;
|
||||
if (m_ob)
|
||||
m_ob->RegisterActuator(this);
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
/* get min ---------------------------------------------------------- */
|
||||
|
@ -123,9 +123,9 @@ private :
|
||||
virtual PyObject* _getattr(const STR_String& attr);
|
||||
|
||||
/* set object to look at */
|
||||
KX_PYMETHOD_DOC(KX_CameraActuator,SetObject);
|
||||
KX_PYMETHOD_DOC_O(KX_CameraActuator,SetObject);
|
||||
/* get current object */
|
||||
KX_PYMETHOD_DOC(KX_CameraActuator,GetObject);
|
||||
KX_PYMETHOD_DOC_VARARGS(KX_CameraActuator,GetObject);
|
||||
KX_PYMETHOD_DOC(KX_CameraActuator,SetMin);
|
||||
KX_PYMETHOD_DOC(KX_CameraActuator,GetMin);
|
||||
KX_PYMETHOD_DOC(KX_CameraActuator,SetMax);
|
||||
|
@ -1551,9 +1551,9 @@ KX_PYMETHODDEF_DOC(KX_GameObject, getDistanceTo,
|
||||
PyErr_Clear();
|
||||
|
||||
PyObject *pyother;
|
||||
if (PyArg_ParseTuple(args, "O!", &KX_GameObject::Type, &pyother))
|
||||
KX_GameObject *other;
|
||||
if (PyArg_ParseTuple(args, "O", &pyother) && ConvertPythonToGameObject(pyother, &other, false))
|
||||
{
|
||||
KX_GameObject *other = static_cast<KX_GameObject*>(pyother);
|
||||
return PyFloat_FromDouble(NodeGetWorldPosition().distance(other->NodeGetWorldPosition()));
|
||||
}
|
||||
|
||||
@ -1574,11 +1574,12 @@ KX_PYMETHODDEF_DOC(KX_GameObject, getVectTo,
|
||||
if (!PyVecArgTo(args, toPoint))
|
||||
{
|
||||
PyErr_Clear();
|
||||
if (PyArg_ParseTuple(args, "O!", &KX_GameObject::Type, &pyother))
|
||||
|
||||
KX_GameObject *other;
|
||||
if (PyArg_ParseTuple(args, "O", &pyother) && ConvertPythonToGameObject(pyother, &other, false))
|
||||
{
|
||||
KX_GameObject *other = static_cast<KX_GameObject*>(pyother);
|
||||
toPoint = other->NodeGetWorldPosition();
|
||||
}else
|
||||
} else
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "Expected a 3D Vector or GameObject type");
|
||||
return NULL;
|
||||
@ -1648,12 +1649,15 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCastTo,
|
||||
{
|
||||
KX_GameObject *other;
|
||||
PyErr_Clear();
|
||||
if (!PyType_IsSubtype(pyarg->ob_type, &KX_GameObject::Type)) {
|
||||
|
||||
if (ConvertPythonToGameObject(pyarg, &other, false))
|
||||
{
|
||||
toPoint = other->NodeGetWorldPosition();
|
||||
} else
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "the first argument to rayCastTo must be a vector or a KX_GameObject");
|
||||
return NULL;
|
||||
}
|
||||
other = static_cast<KX_GameObject*>(pyarg);
|
||||
toPoint = other->NodeGetWorldPosition();
|
||||
}
|
||||
MT_Point3 fromPoint = NodeGetWorldPosition();
|
||||
if (dist != 0.0f)
|
||||
@ -1712,12 +1716,15 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCast,
|
||||
if (!PyVecTo(pyto, toPoint))
|
||||
{
|
||||
PyErr_Clear();
|
||||
if (!PyType_IsSubtype(pyto->ob_type, &KX_GameObject::Type)) {
|
||||
|
||||
if (ConvertPythonToGameObject(pyto, &other, false))
|
||||
{
|
||||
toPoint = other->NodeGetWorldPosition();
|
||||
} else
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "the first argument to rayCast must be a vector or a KX_GameObject");
|
||||
return NULL;
|
||||
}
|
||||
other = static_cast<KX_GameObject*>(pyto);
|
||||
toPoint = other->NodeGetWorldPosition();
|
||||
}
|
||||
if (!pyfrom || pyfrom == Py_None)
|
||||
{
|
||||
@ -1726,12 +1733,15 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCast,
|
||||
else if (!PyVecTo(pyfrom, fromPoint))
|
||||
{
|
||||
PyErr_Clear();
|
||||
if (!PyType_IsSubtype(pyfrom->ob_type, &KX_GameObject::Type)) {
|
||||
|
||||
if (ConvertPythonToGameObject(pyfrom, &other, false))
|
||||
{
|
||||
fromPoint = other->NodeGetWorldPosition();
|
||||
} else
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "the second optional argument to rayCast must be a vector or a KX_GameObject");
|
||||
return NULL;
|
||||
}
|
||||
other = static_cast<KX_GameObject*>(pyfrom);
|
||||
fromPoint = other->NodeGetWorldPosition();
|
||||
}
|
||||
|
||||
if (dist != 0.0f) {
|
||||
@ -1798,3 +1808,49 @@ void KX_GameObject::Relink(GEN_Map<GEN_HashedPtr, void*> *map_parameter)
|
||||
}
|
||||
}
|
||||
|
||||
bool ConvertPythonToGameObject(PyObject * value, KX_GameObject **object, bool py_none_ok)
|
||||
{
|
||||
if (value==NULL) {
|
||||
PyErr_SetString(PyExc_TypeError, "Error in ConvertPythonToGameObject, python pointer NULL, should never happen");
|
||||
*object = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (value==Py_None) {
|
||||
*object = NULL;
|
||||
|
||||
if (py_none_ok) {
|
||||
return true;
|
||||
} else {
|
||||
PyErr_SetString(PyExc_TypeError, "Expected KX_GameObject or a string for a name of a KX_GameObject, None is invalid");
|
||||
return false;
|
||||
}
|
||||
return (py_none_ok ? true : false);
|
||||
}
|
||||
|
||||
if (PyString_Check(value)) {
|
||||
*object = (KX_GameObject *)SCA_ILogicBrick::m_sCurrentLogicManager->GetGameObjectByName(STR_String( PyString_AsString(value) ));
|
||||
|
||||
if (*object) {
|
||||
return true;
|
||||
} else {
|
||||
PyErr_SetString(PyExc_ValueError, "Requested name did not match any KX_GameObject");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (PyObject_TypeCheck(value, &KX_GameObject::Type)) {
|
||||
*object = static_cast<KX_GameObject*>(value);
|
||||
return true;
|
||||
}
|
||||
|
||||
*object = NULL;
|
||||
|
||||
if (py_none_ok) {
|
||||
PyErr_SetString(PyExc_TypeError, "Expect a KX_GameObject, a string or None");
|
||||
} else {
|
||||
PyErr_SetString(PyExc_TypeError, "Expect a KX_GameObject or a string");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -48,6 +48,7 @@
|
||||
#include "KX_KetsjiEngine.h" /* for m_anim_framerate */
|
||||
#include "KX_IPhysicsController.h" /* for suspend/resume */
|
||||
#include "DNA_object_types.h"
|
||||
#include "SCA_LogicManager.h" /* for ConvertPythonToGameObject to search object names */
|
||||
#define KX_OB_DYNAMIC 1
|
||||
|
||||
|
||||
@ -775,5 +776,8 @@ private :
|
||||
|
||||
};
|
||||
|
||||
/* utility conversion function */
|
||||
bool ConvertPythonToGameObject(PyObject * value, KX_GameObject **object, bool py_none_ok);
|
||||
|
||||
#endif //__KX_GAMEOBJECT
|
||||
|
||||
|
@ -164,7 +164,7 @@ PyParentObject KX_ParentActuator::Parents[] = {
|
||||
};
|
||||
|
||||
PyMethodDef KX_ParentActuator::Methods[] = {
|
||||
{"setObject", (PyCFunction) KX_ParentActuator::sPySetObject, METH_VARARGS, SetObject_doc},
|
||||
{"setObject", (PyCFunction) KX_ParentActuator::sPySetObject, METH_O, SetObject_doc},
|
||||
{"getObject", (PyCFunction) KX_ParentActuator::sPyGetObject, METH_VARARGS, GetObject_doc},
|
||||
{NULL,NULL} //Sentinel
|
||||
};
|
||||
@ -176,44 +176,44 @@ PyObject* KX_ParentActuator::_getattr(const STR_String& attr) {
|
||||
/* 1. setObject */
|
||||
char KX_ParentActuator::SetObject_doc[] =
|
||||
"setObject(object)\n"
|
||||
"\tSet the object to set as parent.\n"
|
||||
"\tCan be an object name or an object\n";
|
||||
PyObject* KX_ParentActuator::PySetObject(PyObject* self, PyObject* args, PyObject* kwds) {
|
||||
PyObject* gameobj;
|
||||
if (PyArg_ParseTuple(args, "O!", &KX_GameObject::Type, &gameobj))
|
||||
{
|
||||
if (m_ob != NULL)
|
||||
m_ob->UnregisterActuator(this);
|
||||
m_ob = (SCA_IObject*)gameobj;
|
||||
if (m_ob)
|
||||
m_ob->RegisterActuator(this);
|
||||
Py_Return;
|
||||
}
|
||||
PyErr_Clear();
|
||||
"\t- object: KX_GameObject, string or None\n"
|
||||
"\tSet the object to set as parent.\n";
|
||||
PyObject* KX_ParentActuator::PySetObject(PyObject* self, PyObject* value) {
|
||||
KX_GameObject *gameobj;
|
||||
|
||||
char* objectname;
|
||||
if (PyArg_ParseTuple(args, "s", &objectname))
|
||||
{
|
||||
SCA_IObject *object = (SCA_IObject*)SCA_ILogicBrick::m_sCurrentLogicManager->GetGameObjectByName(STR_String(objectname));
|
||||
if(object)
|
||||
{
|
||||
if (m_ob != NULL)
|
||||
m_ob->UnregisterActuator(this);
|
||||
m_ob = object;
|
||||
m_ob->RegisterActuator(this);
|
||||
Py_Return;
|
||||
}
|
||||
}
|
||||
if (!ConvertPythonToGameObject(value, &gameobj, true))
|
||||
return NULL; // ConvertPythonToGameObject sets the error
|
||||
|
||||
return NULL;
|
||||
if (m_ob != NULL)
|
||||
m_ob->UnregisterActuator(this);
|
||||
|
||||
m_ob = (SCA_IObject*)gameobj;
|
||||
if (m_ob)
|
||||
m_ob->RegisterActuator(this);
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
/* 2. getObject */
|
||||
char KX_ParentActuator::GetObject_doc[] =
|
||||
"getObject()\n"
|
||||
|
||||
/* get obj ---------------------------------------------------------- */
|
||||
char KX_ParentActuator::GetObject_doc[] =
|
||||
"getObject(name_only = 1)\n"
|
||||
"name_only - optional arg, when true will return the KX_GameObject rather then its name\n"
|
||||
"\tReturns the object that is set to.\n";
|
||||
PyObject* KX_ParentActuator::PyGetObject(PyObject* self, PyObject* args, PyObject* kwds) {
|
||||
return PyString_FromString(m_ob->GetName());
|
||||
}
|
||||
PyObject* KX_ParentActuator::PyGetObject(PyObject* self, PyObject* args)
|
||||
{
|
||||
int ret_name_only = 1;
|
||||
if (!PyArg_ParseTuple(args, "|i", &ret_name_only))
|
||||
return NULL;
|
||||
|
||||
if (!m_ob)
|
||||
Py_RETURN_NONE;
|
||||
|
||||
if (ret_name_only)
|
||||
return PyString_FromString(m_ob->GetName());
|
||||
else
|
||||
return m_ob->AddRef();
|
||||
}
|
||||
|
||||
/* eof */
|
||||
|
@ -79,9 +79,9 @@ class KX_ParentActuator : public SCA_IActuator
|
||||
virtual PyObject* _getattr(const STR_String& attr);
|
||||
|
||||
/* 1. setObject */
|
||||
KX_PYMETHOD_DOC(KX_ParentActuator,SetObject);
|
||||
KX_PYMETHOD_DOC_O(KX_ParentActuator,SetObject);
|
||||
/* 2. getObject */
|
||||
KX_PYMETHOD_DOC(KX_ParentActuator,GetObject);
|
||||
KX_PYMETHOD_DOC_VARARGS(KX_ParentActuator,GetObject);
|
||||
|
||||
}; /* end of class KX_ParentActuator : public SCA_PropertyActuator */
|
||||
|
||||
|
@ -180,7 +180,7 @@ PyParentObject KX_SCA_AddObjectActuator::Parents[] = {
|
||||
NULL
|
||||
};
|
||||
PyMethodDef KX_SCA_AddObjectActuator::Methods[] = {
|
||||
{"setObject", (PyCFunction) KX_SCA_AddObjectActuator::sPySetObject, METH_VARARGS, SetObject_doc},
|
||||
{"setObject", (PyCFunction) KX_SCA_AddObjectActuator::sPySetObject, METH_O, SetObject_doc},
|
||||
{"setTime", (PyCFunction) KX_SCA_AddObjectActuator::sPySetTime, METH_VARARGS, SetTime_doc},
|
||||
{"getObject", (PyCFunction) KX_SCA_AddObjectActuator::sPyGetObject, METH_VARARGS, GetObject_doc},
|
||||
{"getTime", (PyCFunction) KX_SCA_AddObjectActuator::sPyGetTime, METH_VARARGS, GetTime_doc},
|
||||
@ -200,41 +200,25 @@ PyObject* KX_SCA_AddObjectActuator::_getattr(const STR_String& attr)
|
||||
|
||||
/* 1. setObject */
|
||||
char KX_SCA_AddObjectActuator::SetObject_doc[] =
|
||||
"setObject(name)\n"
|
||||
"\t- name: string\n"
|
||||
"setObject(object)\n"
|
||||
"\t- object: KX_GameObject, string or None\n"
|
||||
"\tSets the object that will be added. There has to be an object\n"
|
||||
"\tof this name. If not, this function does nothing.\n";
|
||||
|
||||
|
||||
|
||||
PyObject* KX_SCA_AddObjectActuator::PySetObject(PyObject* self,
|
||||
PyObject* args,
|
||||
PyObject* kwds)
|
||||
{
|
||||
PyObject* gameobj;
|
||||
if (PyArg_ParseTuple(args, "O!", &KX_GameObject::Type, &gameobj))
|
||||
{
|
||||
if (m_OriginalObject != NULL)
|
||||
m_OriginalObject->UnregisterActuator(this);
|
||||
m_OriginalObject = (SCA_IObject*)gameobj;
|
||||
if (m_OriginalObject)
|
||||
m_OriginalObject->RegisterActuator(this);
|
||||
Py_Return;
|
||||
}
|
||||
PyErr_Clear();
|
||||
PyObject* KX_SCA_AddObjectActuator::PySetObject(PyObject* self, PyObject* value)
|
||||
{
|
||||
KX_GameObject *gameobj;
|
||||
|
||||
char* objectname;
|
||||
if (PyArg_ParseTuple(args, "s", &objectname))
|
||||
{
|
||||
if (m_OriginalObject != NULL)
|
||||
m_OriginalObject->UnregisterActuator(this);
|
||||
m_OriginalObject = (SCA_IObject*)SCA_ILogicBrick::m_sCurrentLogicManager->GetGameObjectByName(STR_String(objectname));;
|
||||
if (m_OriginalObject)
|
||||
m_OriginalObject->RegisterActuator(this);
|
||||
Py_Return;
|
||||
}
|
||||
if (!ConvertPythonToGameObject(value, &gameobj, true))
|
||||
return NULL; // ConvertPythonToGameObject sets the error
|
||||
|
||||
return NULL;
|
||||
if (m_OriginalObject != NULL)
|
||||
m_OriginalObject->UnregisterActuator(this);
|
||||
|
||||
m_OriginalObject = (SCA_IObject*)gameobj;
|
||||
if (m_OriginalObject)
|
||||
m_OriginalObject->RegisterActuator(this);
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
||||
@ -280,19 +264,22 @@ PyObject* KX_SCA_AddObjectActuator::PyGetTime(PyObject* self,
|
||||
|
||||
/* 4. getObject */
|
||||
char KX_SCA_AddObjectActuator::GetObject_doc[] =
|
||||
"getObject()\n"
|
||||
"getObject(name_only = 1)\n"
|
||||
"name_only - optional arg, when true will return the KX_GameObject rather then its name\n"
|
||||
"\tReturns the name of the object that will be added.\n";
|
||||
|
||||
|
||||
|
||||
PyObject* KX_SCA_AddObjectActuator::PyGetObject(PyObject* self,
|
||||
PyObject* args,
|
||||
PyObject* kwds)
|
||||
PyObject* KX_SCA_AddObjectActuator::PyGetObject(PyObject* self, PyObject* args)
|
||||
{
|
||||
int ret_name_only = 1;
|
||||
if (!PyArg_ParseTuple(args, "|i", &ret_name_only))
|
||||
return NULL;
|
||||
|
||||
if (!m_OriginalObject)
|
||||
Py_Return;
|
||||
|
||||
return PyString_FromString(m_OriginalObject->GetName());
|
||||
Py_RETURN_NONE;
|
||||
|
||||
if (ret_name_only)
|
||||
return PyString_FromString(m_OriginalObject->GetName());
|
||||
else
|
||||
return m_OriginalObject->AddRef();
|
||||
}
|
||||
|
||||
|
||||
|
@ -113,13 +113,13 @@ public:
|
||||
void InstantAddObject();
|
||||
|
||||
/* 1. setObject */
|
||||
KX_PYMETHOD_DOC(KX_SCA_AddObjectActuator,SetObject);
|
||||
KX_PYMETHOD_DOC_O(KX_SCA_AddObjectActuator,SetObject);
|
||||
/* 2. setTime */
|
||||
KX_PYMETHOD_DOC(KX_SCA_AddObjectActuator,SetTime);
|
||||
/* 3. getTime */
|
||||
KX_PYMETHOD_DOC(KX_SCA_AddObjectActuator,GetTime);
|
||||
/* 4. getObject */
|
||||
KX_PYMETHOD_DOC(KX_SCA_AddObjectActuator,GetObject);
|
||||
KX_PYMETHOD_DOC_VARARGS(KX_SCA_AddObjectActuator,GetObject);
|
||||
/* 5. getLinearVelocity */
|
||||
KX_PYMETHOD_DOC(KX_SCA_AddObjectActuator,GetLinearVelocity);
|
||||
/* 6. setLinearVelocity */
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
@ -75,9 +75,9 @@ class KX_TrackToActuator : public SCA_IActuator
|
||||
virtual PyObject* _getattr(const STR_String& attr);
|
||||
|
||||
/* 1. setObject */
|
||||
KX_PYMETHOD_DOC(KX_TrackToActuator,SetObject);
|
||||
KX_PYMETHOD_DOC_O(KX_TrackToActuator,SetObject);
|
||||
/* 2. getObject */
|
||||
KX_PYMETHOD_DOC(KX_TrackToActuator,GetObject);
|
||||
KX_PYMETHOD_DOC_VARARGS(KX_TrackToActuator,GetObject);
|
||||
/* 3. setTime */
|
||||
KX_PYMETHOD_DOC(KX_TrackToActuator,SetTime);
|
||||
/* 4. getTime */
|
||||
|
@ -8,11 +8,13 @@ class KX_CameraActuator(SCA_IActuator):
|
||||
|
||||
@author: snail
|
||||
"""
|
||||
def getObject():
|
||||
def getObject(name_only = 1):
|
||||
"""
|
||||
Returns the name of the object this actuator tracks.
|
||||
|
||||
rtype: string
|
||||
@type name_only: bool
|
||||
@param name_only: optional argument, when 0 return a KX_GameObject
|
||||
@rtype: string, KX_GameObject or None if no object is set
|
||||
"""
|
||||
|
||||
def setObject(target):
|
||||
@ -20,7 +22,7 @@ class KX_CameraActuator(SCA_IActuator):
|
||||
Sets the object this actuator tracks.
|
||||
|
||||
@param target: the object to track.
|
||||
@type target: string or L{KX_GameObject}
|
||||
@type target: L{KX_GameObject}, string or None
|
||||
"""
|
||||
|
||||
def getMin():
|
||||
|
@ -12,11 +12,12 @@ class KX_ParentActuator(SCA_IActuator):
|
||||
|
||||
Object can be either a L{KX_GameObject} or the name of the object.
|
||||
|
||||
@type object: L{KX_GameObject} or string
|
||||
@type object: L{KX_GameObject}, string or None
|
||||
"""
|
||||
def getObject():
|
||||
def getObject(name_only = 1):
|
||||
"""
|
||||
Returns the name of the object to change to.
|
||||
|
||||
@rtype: string
|
||||
@type name_only: bool
|
||||
@param name_only: optional argument, when 0 return a KX_GameObject
|
||||
@rtype: string, KX_GameObject or None if no object is set
|
||||
"""
|
||||
|
@ -13,7 +13,7 @@ class KX_SCA_AddObjectActuator(SCA_IActuator):
|
||||
|
||||
C{ERROR: GameObject I{OBName} has a AddObjectActuator I{ActuatorName} without object (in 'nonactive' layer)}
|
||||
"""
|
||||
def setObject(obj):
|
||||
def setObject(object):
|
||||
"""
|
||||
Sets the game object to add.
|
||||
|
||||
@ -21,17 +21,18 @@ class KX_SCA_AddObjectActuator(SCA_IActuator):
|
||||
|
||||
If the object does not exist, this function is ignored.
|
||||
|
||||
obj can either be a L{KX_GameObject} or the name of an object.
|
||||
object can either be a L{KX_GameObject} or the name of an object or None.
|
||||
|
||||
@type obj: L{KX_GameObject} or string
|
||||
@type object: L{KX_GameObject}, string or None
|
||||
"""
|
||||
def getObject():
|
||||
def getObject(name_only = 0):
|
||||
"""
|
||||
Returns the name of the game object to be added.
|
||||
|
||||
Returns None if no game object has been assigned to be added.
|
||||
|
||||
@rtype: string
|
||||
@type name_only: bool
|
||||
@param name_only: optional argument, when 0 return a KX_GameObject
|
||||
@rtype: string, KX_GameObject or None if no object is set
|
||||
"""
|
||||
def setTime(time):
|
||||
"""
|
||||
|
@ -18,16 +18,16 @@ class KX_TrackToActuator(SCA_IActuator):
|
||||
"""
|
||||
Sets the object to track.
|
||||
|
||||
@type object: L{KX_GameObject} or string
|
||||
@type object: L{KX_GameObject}, string or None
|
||||
@param object: Either a reference to a game object or the name of the object to track.
|
||||
"""
|
||||
def getObject():
|
||||
"""
|
||||
Returns the name of the object to track.
|
||||
|
||||
Returns None if no object has been set to track.
|
||||
|
||||
@rtype: string
|
||||
@type name_only: bool
|
||||
@param name_only: optional argument, when 0 return a KX_GameObject
|
||||
@rtype: string, KX_GameObject or None if no object is set
|
||||
"""
|
||||
def setTime(time):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user