Name attributes added since 2.48a more consistently.
[blender.git] / source / gameengine / GameLogic / SCA_KeyboardSensor.cpp
index 3e19c880c4dd562cb11e3eb959fc9bc331069c5c..f8ee8ed8b414c23382108cedde31c8967a3d8ac1 100644 (file)
@@ -85,7 +85,7 @@ CValue* SCA_KeyboardSensor::GetReplica()
 {
        SCA_KeyboardSensor* replica = new SCA_KeyboardSensor(*this);
        // this will copy properties and so on...
-       CValue::AddDataToReplica(replica);
+       replica->ProcessReplica();
        replica->Init();
        return replica;
 }
@@ -118,7 +118,7 @@ bool SCA_KeyboardSensor::TriggerOnAllKeys()
 
 
 
-bool SCA_KeyboardSensor::Evaluate(CValue* eventval)
+bool SCA_KeyboardSensor::Evaluate()
 {
        bool result    = false;
        bool reset     = m_reset && m_level;
@@ -195,6 +195,9 @@ bool SCA_KeyboardSensor::Evaluate(CValue* eventval)
                                        }
                                }
                        }
+                       if (m_tap)
+                               // special case for tap mode: only generate event for new activation
+                               result = false;
                }
 
 
@@ -412,7 +415,7 @@ void SCA_KeyboardSensor::LogKeystrokes(void)
 const char SCA_KeyboardSensor::GetKey_doc[] = 
 "getKey()\n"
 "\tReturn the code of the key this sensor is listening to.\n" ;
-PyObject* SCA_KeyboardSensor::PyGetKey(PyObject* self, PyObject* args, PyObject* kwds)
+PyObject* SCA_KeyboardSensor::PyGetKey()
 {
        ShowDeprecationWarning("getKey()", "the key property");
        return PyInt_FromLong(m_hotkey);
@@ -423,7 +426,7 @@ const char SCA_KeyboardSensor::SetKey_doc[] =
 "setKey(keycode)\n"
 "\t- keycode: any code from GameKeys\n"
 "\tSet the key this sensor should listen to.\n" ;
-PyObject* SCA_KeyboardSensor::PySetKey(PyObject* self, PyObject* args, PyObject* kwds)
+PyObject* SCA_KeyboardSensor::PySetKey(PyObject* args)
 {
        ShowDeprecationWarning("setKey()", "the key property");
        int keyCode;
@@ -444,7 +447,7 @@ const char SCA_KeyboardSensor::GetHold1_doc[] =
 "getHold1()\n"
 "\tReturn the code of the first key modifier to the key this \n"
 "\tsensor is listening to.\n" ;
-PyObject* SCA_KeyboardSensor::PyGetHold1(PyObject* self, PyObject* args, PyObject* kwds)
+PyObject* SCA_KeyboardSensor::PyGetHold1()
 {
        ShowDeprecationWarning("getHold1()", "the hold1 property");
        return PyInt_FromLong(m_qual);
@@ -455,7 +458,7 @@ const char SCA_KeyboardSensor::SetHold1_doc[] =
 "setHold1(keycode)\n"
 "\t- keycode: any code from GameKeys\n"
 "\tSet the first modifier to the key this sensor should listen to.\n" ;
-PyObject* SCA_KeyboardSensor::PySetHold1(PyObject* self, PyObject* args, PyObject* kwds)
+PyObject* SCA_KeyboardSensor::PySetHold1(PyObject* args)
 {
        ShowDeprecationWarning("setHold1()", "the hold1 property");
        int keyCode;
@@ -476,7 +479,7 @@ const char SCA_KeyboardSensor::GetHold2_doc[] =
 "getHold2()\n"
 "\tReturn the code of the second key modifier to the key this \n"
 "\tsensor is listening to.\n" ;
-PyObject* SCA_KeyboardSensor::PyGetHold2(PyObject* self, PyObject* args, PyObject* kwds)
+PyObject* SCA_KeyboardSensor::PyGetHold2()
 {
        ShowDeprecationWarning("getHold2()", "the hold2 property");
        return PyInt_FromLong(m_qual2);
@@ -487,7 +490,7 @@ const char SCA_KeyboardSensor::SetHold2_doc[] =
 "setHold2(keycode)\n"
 "\t- keycode: any code from GameKeys\n"
 "\tSet the first modifier to the key this sensor should listen to.\n" ;
-PyObject* SCA_KeyboardSensor::PySetHold2(PyObject* self, PyObject* args, PyObject* kwds)
+PyObject* SCA_KeyboardSensor::PySetHold2(PyObject* args)
 {
        ShowDeprecationWarning("setHold2()", "the hold2 property");
        int keyCode;
@@ -508,7 +511,7 @@ const char SCA_KeyboardSensor::GetPressedKeys_doc[] =
 "getPressedKeys()\n"
 "\tGet a list of pressed keys that have either been pressed, or just released this frame.\n" ;
 
-PyObject* SCA_KeyboardSensor::PyGetPressedKeys(PyObject* self, PyObject* args, PyObject* kwds)
+PyObject* SCA_KeyboardSensor::PyGetPressedKeys()
 {
        ShowDeprecationWarning("getPressedKeys()", "events");
 
@@ -549,7 +552,7 @@ const char SCA_KeyboardSensor::GetCurrentlyPressedKeys_doc[] =
 "getCurrentlyPressedKeys()\n"
 "\tGet a list of keys that are currently pressed.\n" ;
 
-PyObject* SCA_KeyboardSensor::PyGetCurrentlyPressedKeys(PyObject* self, PyObject* args, PyObject* kwds)
+PyObject* SCA_KeyboardSensor::PyGetCurrentlyPressedKeys()
 {
        ShowDeprecationWarning("getCurrentlyPressedKeys()", "events");
 
@@ -590,7 +593,7 @@ KX_PYMETHODDEF_DOC_O(SCA_KeyboardSensor, getKeyStatus,
 "\tGet the given key's status (KX_NO_INPUTSTATUS, KX_JUSTACTIVATED, KX_ACTIVE or KX_JUSTRELEASED).\n")
 {
        if (!PyInt_Check(value)) {
-               PyErr_SetString(PyExc_ValueError, "getKeyStatus expected an int");
+               PyErr_SetString(PyExc_ValueError, "sensor.getKeyStatus(int): Keyboard Sensor, expected an int");
                return NULL;
        }
        
@@ -598,7 +601,7 @@ KX_PYMETHODDEF_DOC_O(SCA_KeyboardSensor, getKeyStatus,
        
        if ((keycode < SCA_IInputDevice::KX_BEGINKEY)
                || (keycode > SCA_IInputDevice::KX_ENDKEY)){
-               PyErr_SetString(PyExc_AttributeError, "invalid keycode specified!");
+               PyErr_SetString(PyExc_AttributeError, "sensor.getKeyStatus(int): Keyboard Sensor, invalid keycode specified!");
                return NULL;
        }
        
@@ -612,8 +615,13 @@ KX_PYMETHODDEF_DOC_O(SCA_KeyboardSensor, getKeyStatus,
 /* ------------------------------------------------------------------------- */
 
 PyTypeObject SCA_KeyboardSensor::Type = {
-       PyObject_HEAD_INIT(NULL)
-       0,
+#if (PY_VERSION_HEX >= 0x02060000)
+       PyVarObject_HEAD_INIT(NULL, 0)
+#else
+       /* python 2.5 and below */
+       PyObject_HEAD_INIT( NULL )  /* required py macro */
+       0,                          /* ob_size */
+#endif
        "SCA_KeyboardSensor",
        sizeof(PyObjectPlus_Proxy),
        0,
@@ -640,14 +648,14 @@ PyParentObject SCA_KeyboardSensor::Parents[] = {
 
 PyMethodDef SCA_KeyboardSensor::Methods[] = {
        //Deprecated functions ------>
-       {"getKey", (PyCFunction) SCA_KeyboardSensor::sPyGetKey, METH_VARARGS, (PY_METHODCHAR)GetKey_doc},
+       {"getKey", (PyCFunction) SCA_KeyboardSensor::sPyGetKey, METH_NOARGS, (PY_METHODCHAR)GetKey_doc},
        {"setKey", (PyCFunction) SCA_KeyboardSensor::sPySetKey, METH_VARARGS, (PY_METHODCHAR)SetKey_doc},
-       {"getHold1", (PyCFunction) SCA_KeyboardSensor::sPyGetHold1, METH_VARARGS, (PY_METHODCHAR)GetHold1_doc},
+       {"getHold1", (PyCFunction) SCA_KeyboardSensor::sPyGetHold1, METH_NOARGS, (PY_METHODCHAR)GetHold1_doc},
        {"setHold1", (PyCFunction) SCA_KeyboardSensor::sPySetHold1, METH_VARARGS, (PY_METHODCHAR)SetHold1_doc},
-       {"getHold2", (PyCFunction) SCA_KeyboardSensor::sPyGetHold2, METH_VARARGS, (PY_METHODCHAR)GetHold2_doc},
+       {"getHold2", (PyCFunction) SCA_KeyboardSensor::sPyGetHold2, METH_NOARGS, (PY_METHODCHAR)GetHold2_doc},
        {"setHold2", (PyCFunction) SCA_KeyboardSensor::sPySetHold2, METH_VARARGS, (PY_METHODCHAR)SetHold2_doc},
-       {"getPressedKeys", (PyCFunction) SCA_KeyboardSensor::sPyGetPressedKeys, METH_VARARGS, (PY_METHODCHAR)GetPressedKeys_doc},
-       {"getCurrentlyPressedKeys", (PyCFunction) SCA_KeyboardSensor::sPyGetCurrentlyPressedKeys, METH_VARARGS, (PY_METHODCHAR)GetCurrentlyPressedKeys_doc},
+       {"getPressedKeys", (PyCFunction) SCA_KeyboardSensor::sPyGetPressedKeys, METH_NOARGS, (PY_METHODCHAR)GetPressedKeys_doc},
+       {"getCurrentlyPressedKeys", (PyCFunction) SCA_KeyboardSensor::sPyGetCurrentlyPressedKeys, METH_NOARGS, (PY_METHODCHAR)GetCurrentlyPressedKeys_doc},
        //<----- Deprecated
        KX_PYMETHODTABLE_O(SCA_KeyboardSensor, getKeyStatus),
        {NULL,NULL} //Sentinel
@@ -664,12 +672,15 @@ PyAttributeDef SCA_KeyboardSensor::Attributes[] = {
        { NULL }        //Sentinel
 };
 
-PyObject*
-SCA_KeyboardSensor::py_getattro(PyObject *attr)
+PyObject* SCA_KeyboardSensor::py_getattro(PyObject *attr)
 {
   py_getattro_up(SCA_ISensor);
 }
 
+PyObject* SCA_KeyboardSensor::py_getattro_dict() {
+       py_getattro_dict_up(SCA_ISensor);
+}
+
 int SCA_KeyboardSensor::py_setattro(PyObject *attr, PyObject *value)
 {
        py_setattro_up(SCA_ISensor);
@@ -691,7 +702,7 @@ PyObject* SCA_KeyboardSensor::pyattr_get_events(void *self_v, const KX_PYATTRIBU
                {
                        PyObject* keypair = PyList_New(2);
                        PyList_SET_ITEM(keypair,0,PyInt_FromLong(i));
-                       PyList_SetItem(keypair,1,PyInt_FromLong(inevent.m_status));
+                       PyList_SET_ITEM(keypair,1,PyInt_FromLong(inevent.m_status));
                        PyList_Append(resultlist,keypair);
                }
        }