diff options
author | Benoit Bolsee <benoit.bolsee@online.be> | 2008-12-29 19:36:58 +0300 |
---|---|---|
committer | Benoit Bolsee <benoit.bolsee@online.be> | 2008-12-29 19:36:58 +0300 |
commit | 1c663bbc7e53cda1fe35579302574b0d98aa8db3 (patch) | |
tree | 4c0d3be6453932c01a9dc0fee0f820275cd6701d /source/gameengine/GameLogic/SCA_ActuatorSensor.cpp | |
parent | d91daaa5f690645153adf647c371262c9c6cb009 (diff) |
First batch of GE API cleanup.
The principle is to replace most get/set methods of logic bricks by direct property access.
To make porting of game code easier, the properties have usually the same type and use than
the return values/parameters of the get/set methods.
More details on http://wiki.blender.org/index.php/GameEngineDev/Python_API_Clean_Up
Old methods are still available but will produce deprecation warnings on the console:
"<method> is deprecated, use the <property> property instead"
You can avoid these messages by turning on the "Ignore deprecation warnings" option in Game menu.
PyDoc is updated to include the new properties and display a deprecation warning
for the get/set methods that are being deprecated.
Diffstat (limited to 'source/gameengine/GameLogic/SCA_ActuatorSensor.cpp')
-rw-r--r-- | source/gameengine/GameLogic/SCA_ActuatorSensor.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp b/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp index 7c37b237d60..5ad28dbf329 100644 --- a/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp +++ b/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp @@ -149,21 +149,44 @@ PyParentObject SCA_ActuatorSensor::Parents[] = { }; PyMethodDef SCA_ActuatorSensor::Methods[] = { + //Deprecated functions ------> {"getActuator", (PyCFunction) SCA_ActuatorSensor::sPyGetActuator, METH_NOARGS, (PY_METHODCHAR)GetActuator_doc}, {"setActuator", (PyCFunction) SCA_ActuatorSensor::sPySetActuator, METH_VARARGS, (PY_METHODCHAR)SetActuator_doc}, + //<----- Deprecated {NULL,NULL} //Sentinel }; PyObject* SCA_ActuatorSensor::_getattr(const STR_String& attr) { + if (attr == "actuator") { + return PyString_FromString(m_checkactname); + } _getattr_up(SCA_ISensor); /* implicit return! */ } +int SCA_ActuatorSensor::_setattr(const STR_String& attr, PyObject *value) { + if (PyString_Check(value)) { + char* sval = PyString_AsString(value); + if (attr == "actuator") { + SCA_IActuator* act = GetParent()->FindActuator(STR_String(sval)); + if (act) { + m_checkactname = sval; + m_actuator = act; + return 0; + } + PyErr_SetString(PyExc_AttributeError, "string does not correspond to an actuator"); + return 1; + } + } + return SCA_ISensor::_setattr(attr, value); +} + /* 3. getActuator */ const char SCA_ActuatorSensor::GetActuator_doc[] = "getActuator()\n" "\tReturn the Actuator with which the sensor operates.\n"; PyObject* SCA_ActuatorSensor::PyGetActuator(PyObject* self) { + ShowDeprecationWarning("getActuator()", "the actuator property"); return PyString_FromString(m_checkactname); } @@ -175,6 +198,7 @@ const char SCA_ActuatorSensor::SetActuator_doc[] = "\tof this name, the call is ignored.\n"; PyObject* SCA_ActuatorSensor::PySetActuator(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setActuator()", "the actuator property"); /* We should query whether the name exists. Or should we create a prop */ /* on the fly? */ char *actNameArg = NULL; |