diff options
author | Benoit Bolsee <benoit.bolsee@online.be> | 2009-01-02 20:43:56 +0300 |
---|---|---|
committer | Benoit Bolsee <benoit.bolsee@online.be> | 2009-01-02 20:43:56 +0300 |
commit | cc569504d0468ec19a1018ea804aa418c134cb0f (patch) | |
tree | 732f5d6fe3d742f63dae5f6e899aea566ae52b0f /source/gameengine/GameLogic/SCA_DelaySensor.cpp | |
parent | abd4934d1aeceafaa2fc242f00db0ba53a7e24db (diff) |
BGE API Cleanup: update the python attribute definition framework.
* Value clamping to min/max is now supported as an option for integer, float
and string attribute (for string clamping=trim to max length)
* Post check function now take PyAttributeDef parameter so that more
generic function can be written.
* Definition of SCA_ILogicBrick::CheckProperty() function to check that
a string attribute contains a valid property name of the parent game object.
* Definition of enum attribute vi KX_PYATTRIBUTE_ENUM... macros.
Enum are handled just like integer but to be totally paranoid, the sizeof()
of the enum member is check at run time to match integer size.
* More bricks updated to use the framework.
Diffstat (limited to 'source/gameengine/GameLogic/SCA_DelaySensor.cpp')
-rw-r--r-- | source/gameengine/GameLogic/SCA_DelaySensor.cpp | 45 |
1 files changed, 13 insertions, 32 deletions
diff --git a/source/gameengine/GameLogic/SCA_DelaySensor.cpp b/source/gameengine/GameLogic/SCA_DelaySensor.cpp index 362483b58a2..4c97ca98d72 100644 --- a/source/gameengine/GameLogic/SCA_DelaySensor.cpp +++ b/source/gameengine/GameLogic/SCA_DelaySensor.cpp @@ -171,43 +171,24 @@ PyMethodDef SCA_DelaySensor::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef SCA_DelaySensor::Attributes[] = { + KX_PYATTRIBUTE_INT_RW("delay",0,100000,true,SCA_DelaySensor,m_delay), + KX_PYATTRIBUTE_INT_RW("duration",0,100000,true,SCA_DelaySensor,m_duration), + KX_PYATTRIBUTE_BOOL_RW("repeat",SCA_DelaySensor,m_repeat), + { NULL } //Sentinel +}; + PyObject* SCA_DelaySensor::_getattr(const STR_String& attr) { - if (attr == "delay") { - return PyInt_FromLong(m_delay); - } - if (attr == "duration") { - return PyInt_FromLong(m_duration); - } - if (attr == "repeat") { - return PyInt_FromLong(m_repeat); - } + PyObject* object = _getattr_self(Attributes, this, attr); + if (object != NULL) + return object; _getattr_up(SCA_ISensor); } int SCA_DelaySensor::_setattr(const STR_String& attr, PyObject *value) { - if (PyInt_Check(value)) { - int ival = PyInt_AsLong(value); - if (attr == "delay") { - if (ival < 0) { - PyErr_SetString(PyExc_ValueError, "Delay cannot be negative"); - return 1; - } - m_delay = ival; - return 0; - } - if (attr == "duration") { - if (ival < 0) { - PyErr_SetString(PyExc_ValueError, "Duration cannot be negative"); - return 1; - } - m_duration = ival; - return 0; - } - if (attr == "repeat") { - m_repeat = (ival != 0); - return 0; - } - } + int ret = _setattr_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; return SCA_ISensor::_setattr(attr, value); } |