BGE API cleanup: more bricks converted to attributes.

This commit is contained in:
2009-01-02 22:09:57 +00:00
parent cc569504d0
commit 10702bf93f
4 changed files with 53 additions and 0 deletions

View File

@@ -247,11 +247,18 @@ PyParentObject SCA_ILogicBrick::Parents[] = {
PyMethodDef SCA_ILogicBrick::Methods[] = {
{"getOwner", (PyCFunction) SCA_ILogicBrick::sPyGetOwner, METH_NOARGS},
// --> Deprecated
{"getExecutePriority", (PyCFunction) SCA_ILogicBrick::sPyGetExecutePriority, METH_NOARGS},
{"setExecutePriority", (PyCFunction) SCA_ILogicBrick::sPySetExecutePriority, METH_VARARGS},
// <-- Deprecated
{NULL,NULL} //Sentinel
};
PyAttributeDef SCA_ILogicBrick::Attributes[] = {
KX_PYATTRIBUTE_INT_RW("executePriority",0,100000,false,SCA_ILogicBrick,m_Execute_Ueber_Priority),
{NULL} //Sentinel
};
int SCA_ILogicBrick::CheckProperty(void *self, const PyAttributeDef *attrdef)
{
if (attrdef->m_type != KX_PYATTRIBUTE_TYPE_STRING || attrdef->m_length != 1) {
@@ -273,9 +280,19 @@ int SCA_ILogicBrick::CheckProperty(void *self, const PyAttributeDef *attrdef)
PyObject*
SCA_ILogicBrick::_getattr(const STR_String& attr)
{
PyObject* object = _getattr_self(Attributes, this, attr);
if (object != NULL)
return object;
_getattr_up(CValue);
}
int SCA_ILogicBrick::_setattr(const STR_String& attr, PyObject *value)
{
int ret = _setattr_self(Attributes, this, attr, value);
if (ret >= 0)
return ret;
return CValue::_setattr(attr, value);
}
PyObject* SCA_ILogicBrick::PyGetOwner(PyObject* self)
@@ -297,6 +314,7 @@ PyObject* SCA_ILogicBrick::PySetExecutePriority(PyObject* self,
PyObject* args,
PyObject* kwds)
{
ShowDeprecationWarning("setExecutePriority()", "the executePriority property");
int priority=0;
@@ -313,6 +331,7 @@ PyObject* SCA_ILogicBrick::PySetExecutePriority(PyObject* self,
PyObject* SCA_ILogicBrick::PyGetExecutePriority(PyObject* self)
{
ShowDeprecationWarning("getExecutePriority()", "the executePriority property");
return PyInt_FromLong(m_Execute_Ueber_Priority);
}

View File

@@ -79,6 +79,7 @@ public:
virtual bool LessComparedTo(SCA_ILogicBrick* other);
virtual PyObject* _getattr(const STR_String& attr);
virtual int _setattr(const STR_String& attr, PyObject *value);
static class SCA_LogicManager* m_sCurrentLogicManager;

View File

@@ -160,10 +160,39 @@ PyMethodDef SCA_RandomSensor::Methods[] = {
{NULL,NULL} //Sentinel
};
PyAttributeDef SCA_RandomSensor::Attributes[] = {
KX_PYATTRIBUTE_BOOL_RO("lastDraw",SCA_RandomSensor,m_lastdraw),
{NULL} //Sentinel
};
PyObject* SCA_RandomSensor::_getattr(const STR_String& attr) {
PyObject* object = _getattr_self(Attributes, this, attr);
if (object != NULL)
return object;
if (attr == "seed") {
return PyInt_FromLong(m_basegenerator->GetSeed());
}
_getattr_up(SCA_ISensor);
}
int SCA_RandomSensor::_setattr(const STR_String& attr, PyObject *value)
{
int ret = _setattr_self(Attributes, this, attr, value);
if (ret >= 0)
return ret;
if (attr == "seed") {
if (PyInt_Check(value)) {
int ival = PyInt_AsLong(value);
m_basegenerator->SetSeed(ival);
return 0;
} else {
PyErr_SetString(PyExc_TypeError, "expected an integer");
return 1;
}
}
return SCA_ISensor::_setattr(attr, value);
}
/* 1. setSeed */
const char SCA_RandomSensor::SetSeed_doc[] =
"setSeed(seed)\n"
@@ -172,6 +201,7 @@ const char SCA_RandomSensor::SetSeed_doc[] =
"\tequal series. If the seed is 0, the generator will produce\n"
"\tthe same value on every call.\n";
PyObject* SCA_RandomSensor::PySetSeed(PyObject* self, PyObject* args, PyObject* kwds) {
ShowDeprecationWarning("setSeed()", "the seed property");
long seedArg;
if(!PyArg_ParseTuple(args, "i", &seedArg)) {
return NULL;
@@ -188,6 +218,7 @@ const char SCA_RandomSensor::GetSeed_doc[] =
"\tReturns the initial seed of the generator. Equal seeds produce\n"
"\tequal series.\n";
PyObject* SCA_RandomSensor::PyGetSeed(PyObject* self, PyObject* args, PyObject* kwds) {
ShowDeprecationWarning("getSeed()", "the seed property");
return PyInt_FromLong(m_basegenerator->GetSeed());
}
@@ -196,6 +227,7 @@ const char SCA_RandomSensor::GetLastDraw_doc[] =
"getLastDraw()\n"
"\tReturn the last value that was drawn.\n";
PyObject* SCA_RandomSensor::PyGetLastDraw(PyObject* self, PyObject* args, PyObject* kwds) {
ShowDeprecationWarning("getLastDraw()", "the lastDraw property");
return PyInt_FromLong(m_lastdraw);
}

View File

@@ -61,6 +61,7 @@ public:
/* --------------------------------------------------------------------- */
virtual PyObject* _getattr(const STR_String& attr);
virtual int _setattr(const STR_String& attr, PyObject *value);
/* 1. setSeed */
KX_PYMETHOD_DOC(SCA_RandomSensor,SetSeed);