diff options
author | Benoit Bolsee <benoit.bolsee@online.be> | 2008-12-30 19:44:34 +0300 |
---|---|---|
committer | Benoit Bolsee <benoit.bolsee@online.be> | 2008-12-30 19:44:34 +0300 |
commit | cbceb6c8b2806587a45e05946cb591bd119cc801 (patch) | |
tree | 2026fa2225120699ebfa37db18938cfbe1ecf390 /source/gameengine/GameLogic/SCA_KeyboardSensor.cpp | |
parent | cbc3c7e8785d21490346d4c2eed8380de6ede378 (diff) |
BGE API cleanup: more consistent type check on set attribute (mouse and keyboard so far). Check type after name so that the user get a type error when assigning a wrong type to a built-in attribute.
Diffstat (limited to 'source/gameengine/GameLogic/SCA_KeyboardSensor.cpp')
-rw-r--r-- | source/gameengine/GameLogic/SCA_KeyboardSensor.cpp | 77 |
1 files changed, 46 insertions, 31 deletions
diff --git a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp index f880cd7768e..0e014628ac7 100644 --- a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp +++ b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp @@ -846,49 +846,64 @@ SCA_KeyboardSensor::_getattr(const STR_String& attr) int SCA_KeyboardSensor::_setattr(const STR_String& attr, PyObject *value) { - if (PyInt_Check(value)) + if (attr == "key") { - int val = PyInt_AsLong(value); - - if (attr == "key") - { - m_hotkey = val; - return 0; + if (!PyInt_Check(value)){ + PyErr_SetString(PyExc_TypeError, "expected an integer"); + return 1; } + m_hotkey = PyInt_AsLong(value); + return 0; + } - if (attr == "hold1") - { - m_qual = val; - return 0; + if (attr == "hold1") + { + if (!PyInt_Check(value)){ + PyErr_SetString(PyExc_TypeError, "expected an integer"); + return 1; } - - if (attr == "hold2") - { - m_qual2 = val; - return 0; + m_qual = PyInt_AsLong(value); + return 0; + } + + if (attr == "hold2") + { + if (!PyInt_Check(value)){ + PyErr_SetString(PyExc_TypeError, "expected an integer"); + return 1; } + m_qual2 = PyInt_AsLong(value); + return 0; + } - if (attr == "useAllKeys") - { - m_bAllKeys = (val != 0); - return 0; + if (attr == "useAllKeys") + { + if (!PyInt_Check(value)){ + PyErr_SetString(PyExc_TypeError, "expected an integer"); + return 1; } + m_bAllKeys = (PyInt_AsLong(value) != 0); + return 0; } - - if (PyString_Check(value)) + + if (attr == "logToggleProperty") { - STR_String val = PyString_AsString(value); - if (attr == "logToggleProperty") - { - m_toggleprop = val; - return 0; + if (!PyString_Check(value)){ + PyErr_SetString(PyExc_TypeError, "expected a string"); + return 1; } + m_toggleprop = PyString_AsString(value); + return 0; + } - if (attr == "logTargetProperty") - { - m_targetprop = val; - return 0; + if (attr == "logTargetProperty") + { + if (!PyString_Check(value)){ + PyErr_SetString(PyExc_TypeError, "expected a string"); + return 1; } + m_targetprop = PyString_AsString(value); + return 0; } return SCA_ISensor::_setattr(attr, value); |