BGE Python API cleanup - no functionality changes
[blender.git] / source / gameengine / GameLogic / SCA_JoystickSensor.cpp
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17  *
18  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19  * All rights reserved.
20  *
21  * The Original Code is: all of this file.
22  *
23  * Contributor(s): none yet.
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27 #include "SCA_JoystickManager.h"
28 #include "SCA_JoystickSensor.h"
29
30 #include "SCA_EventManager.h"
31 #include "SCA_LogicManager.h"
32
33 #include "PyObjectPlus.h"
34
35 #include <iostream>
36
37
38 #ifdef HAVE_CONFIG_H
39 #include <config.h>
40 #endif
41
42
43 SCA_JoystickSensor::SCA_JoystickSensor(class SCA_JoystickManager* eventmgr,
44                                                                            SCA_IObject* gameobj,
45                                                                            short int joyindex,
46                                                                            short int joymode,
47                                                                            int axis, int axisf,int prec,
48                                                                            int button,
49                                                                            int hat, int hatf, bool allevents,
50                                                                            PyTypeObject* T )
51                                                                            :SCA_ISensor(gameobj,eventmgr,T),
52                                                                            m_pJoystickMgr(eventmgr),
53                                                                            m_axis(axis),
54                                                                            m_axisf(axisf),
55                                                                            m_button(button),
56                                                                            m_hat(hat),
57                                                                            m_hatf(hatf),
58                                                                            m_precision(prec),
59                                                                            m_joymode(joymode),
60                                                                            m_joyindex(joyindex),
61                                                                            m_bAllEvents(allevents)
62 {       
63 /*
64 std::cout << " axis "           << m_axis               << std::endl;
65 std::cout << " axis flag "      << m_axisf              << std::endl;
66 std::cout << " precision "      << m_precision  << std::endl;
67 std::cout << " button "         << m_button     << std::endl;
68 std::cout << " hat "            << m_hat                << std::endl;
69 std::cout << " hat flag "       << m_hatf               << std::endl;
70 */
71         Init();
72 }
73
74 void SCA_JoystickSensor::Init()
75 {
76         m_istrig=(m_invert)?1:0;
77         m_istrig_prev=0;
78         m_reset = true;
79 }
80
81 SCA_JoystickSensor::~SCA_JoystickSensor()
82 {
83 }
84
85
86 CValue* SCA_JoystickSensor::GetReplica()
87 {
88         SCA_JoystickSensor* replica = new SCA_JoystickSensor(*this);
89         // this will copy properties and so on...
90         CValue::AddDataToReplica(replica);
91         replica->Init();
92         return replica;
93 }
94
95
96 bool SCA_JoystickSensor::IsPositiveTrigger()
97
98         bool result =   m_istrig;
99         if (m_invert)
100                 result = !result;
101         return result;
102 }
103
104
105 bool SCA_JoystickSensor::Evaluate(CValue* event)
106 {
107         SCA_Joystick *js = m_pJoystickMgr->GetJoystickDevice(m_joyindex);
108         bool result = false;
109         bool reset = m_reset && m_level;
110         
111         if(js==NULL) /* no joystick - dont do anything */
112                 return false;
113         
114         m_reset = false;
115         switch(m_joymode)
116         {
117         case KX_JOYSENSORMODE_AXIS:
118                 {
119                 /* what is what!
120                         m_axisf == JOYAXIS_RIGHT, JOYAXIS_UP, JOYAXIS_DOWN, JOYAXIS_LEFT
121                         m_axisf == 1 == up
122                         m_axisf == 2 == left
123                         m_axisf == 3 == down
124                         
125                         numberof== m_axis (1-4), range is half of JOYAXIS_MAX since 
126                                 it assumes the axis joysticks are axis parirs (0,1), (2,3), etc
127                                 also note that this starts at 1 where functions its used
128                                 with expect a zero index.
129                         */
130                         
131                         if (!js->IsTrigAxis() && !reset) /* No events from SDL? - dont bother */
132                                 return false;
133                         
134                         js->cSetPrecision(m_precision);
135                         if (m_bAllEvents) {
136                                 if(js->aAxisPairIsPositive(m_axis-1)){ /* use zero based axis index internally */
137                                         m_istrig = 1;
138                                         result = true;
139                                 }else{
140                                         if(m_istrig){
141                                                 m_istrig = 0;
142                                                 result = true;
143                                         }
144                                 }
145                         }
146                         else {
147                                 if(js->aAxisPairDirectionIsPositive(m_axis-1, m_axisf)){ /* use zero based axis index internally */
148                                         m_istrig = 1;
149                                         result = true;
150                                 }else{
151                                         if(m_istrig){
152                                                 m_istrig = 0;
153                                                 result = true;
154                                         }
155                                 }
156                         }
157                         break;
158                 }
159         case KX_JOYSENSORMODE_AXIS_SINGLE:
160                 {
161                         /* Like KX_JOYSENSORMODE_AXIS but dont pair up axis */
162                         if (!js->IsTrigAxis() && !reset) /* No events from SDL? - dont bother */
163                                 return false;
164                         
165                         /* No need for 'm_bAllEvents' check here since were only checking 1 axis */
166                         js->cSetPrecision(m_precision);
167                         if(js->aAxisIsPositive(m_axis-1)){ /* use zero based axis index internally */
168                                 m_istrig = 1;
169                                 result = true;
170                         }else{
171                                 if(m_istrig){
172                                         m_istrig = 0;
173                                         result = true;
174                                 }
175                         }
176                         break;
177                 }
178                 
179         case KX_JOYSENSORMODE_BUTTON:
180                 {
181                 /* what is what!
182                         m_button = the actual button in question
183                         */
184                         if (!js->IsTrigButton() && !reset) /* No events from SDL? - dont bother */
185                                 return false;
186                         
187                         if(( m_bAllEvents && js->aAnyButtonPressIsPositive()) || (!m_bAllEvents && js->aButtonPressIsPositive(m_button))) {
188                                 m_istrig = 1;
189                                 result = true;
190                         }else {
191                                 if(m_istrig){
192                                         m_istrig = 0;
193                                         result = true;
194                                 }
195                         }
196                         break;
197                 }
198         case KX_JOYSENSORMODE_HAT:
199                 {
200                 /* what is what!
201                         numberof = m_hat  -- max 2
202                         direction= m_hatf -- max 12
203                         */
204                         
205                         if (!js->IsTrigHat() && !reset) /* No events from SDL? - dont bother */
206                                 return false;
207                         
208                         if(m_hat == 1){
209                                 if(js->aHatIsPositive(m_hatf)){
210                                         m_istrig = 1;
211                                         result = true;
212                                 }else{
213                                         if(m_istrig){
214                                                 m_istrig = 0;
215                                                 result = true;
216                                         }
217                                 }
218                         }
219                         if(m_hat == 2){
220                                 if(js->aHatIsPositive(m_hatf)){
221                                         m_istrig = 1;
222                                         result = true;
223                                 }else{
224                                         if(m_istrig){
225                                                 m_istrig = 0;
226                                                 result = true;
227                                         }
228                                 }
229                         }
230                         break;
231                 }
232                 /* test for ball anyone ?*/
233         default:
234                 printf("Error invalid switch statement\n");
235                 break;
236         }
237         
238         /* if not all events are enabled, only send a positive pulse when 
239          * the button state changes */
240         if (!m_bAllEvents) {
241                 if (m_istrig_prev == m_istrig) {
242                         result = false;
243                 } else {
244                         m_istrig_prev = m_istrig;
245                 }
246         }
247         
248         if (reset)
249                 result = true;
250         
251         return result;
252 }
253
254
255 bool SCA_JoystickSensor::isValid(SCA_JoystickSensor::KX_JOYSENSORMODE m)
256 {
257         bool res = false;
258         res = ((m > KX_JOYSENSORMODE_NODEF) && (m < KX_JOYSENSORMODE_MAX));
259         return res;
260 }
261
262
263 /* ------------------------------------------------------------------------- */
264 /* Python functions                                                                                                              */
265 /* ------------------------------------------------------------------------- */
266
267 /* Integration hooks ------------------------------------------------------- */
268 PyTypeObject SCA_JoystickSensor::Type = {
269         PyObject_HEAD_INIT(NULL)
270                 0,
271                 "SCA_JoystickSensor",
272                 sizeof(PyObjectPlus_Proxy),
273                 0,
274                 py_base_dealloc,
275                 0,
276                 0,
277                 0,
278                 0,
279                 py_base_repr,
280                 0,0,0,0,0,0,
281                 py_base_getattro,
282                 py_base_setattro,
283                 0,0,0,0,0,0,0,0,0,
284                 Methods
285 };
286
287
288 PyParentObject SCA_JoystickSensor::Parents[] = {
289                 &SCA_JoystickSensor::Type,
290                 &SCA_ISensor::Type,
291                 &SCA_ILogicBrick::Type,
292                 &CValue::Type,
293                 NULL
294 };
295
296
297 PyMethodDef SCA_JoystickSensor::Methods[] = {
298         //Deprecated functions ------>
299         {"getIndex",     (PyCFunction) SCA_JoystickSensor::sPyGetIndex,         METH_NOARGS,    (PY_METHODCHAR)GetIndex_doc},
300         {"setIndex",     (PyCFunction) SCA_JoystickSensor::sPySetIndex,         METH_O,                 (PY_METHODCHAR)SetIndex_doc},
301         {"getAxis",      (PyCFunction) SCA_JoystickSensor::sPyGetAxis,          METH_NOARGS,    (PY_METHODCHAR)GetAxis_doc},
302         {"setAxis",      (PyCFunction) SCA_JoystickSensor::sPySetAxis,          METH_VARARGS,   (PY_METHODCHAR)SetAxis_doc},
303         {"getAxisValue", (PyCFunction) SCA_JoystickSensor::sPyGetAxisValue,     METH_NOARGS,    (PY_METHODCHAR)GetAxisValue_doc},
304         {"getThreshold", (PyCFunction) SCA_JoystickSensor::sPyGetThreshold, METH_NOARGS,        (PY_METHODCHAR)GetThreshold_doc},
305         {"setThreshold", (PyCFunction) SCA_JoystickSensor::sPySetThreshold, METH_VARARGS,       (PY_METHODCHAR)SetThreshold_doc},
306         {"getButton",    (PyCFunction) SCA_JoystickSensor::sPyGetButton,        METH_NOARGS,    (PY_METHODCHAR)GetButton_doc},
307         {"setButton",    (PyCFunction) SCA_JoystickSensor::sPySetButton,        METH_O,                 (PY_METHODCHAR)SetButton_doc},
308         {"getHat",               (PyCFunction) SCA_JoystickSensor::sPyGetHat,           METH_NOARGS,    (PY_METHODCHAR)GetHat_doc},
309         {"setHat",               (PyCFunction) SCA_JoystickSensor::sPySetHat,           METH_VARARGS,   (PY_METHODCHAR)SetHat_doc},
310         {"getNumAxes",   (PyCFunction) SCA_JoystickSensor::sPyNumberOfAxes,     METH_NOARGS,    (PY_METHODCHAR)NumberOfAxes_doc},
311         {"getNumButtons",(PyCFunction) SCA_JoystickSensor::sPyNumberOfButtons,METH_NOARGS,      (PY_METHODCHAR)NumberOfButtons_doc},
312         {"getNumHats",   (PyCFunction) SCA_JoystickSensor::sPyNumberOfHats,     METH_NOARGS,    (PY_METHODCHAR)NumberOfHats_doc},
313         {"isConnected", (PyCFunction) SCA_JoystickSensor::sPyConnected,         METH_NOARGS,    (PY_METHODCHAR)Connected_doc},
314         {"getButtonValue",(PyCFunction) SCA_JoystickSensor::sPyGetButtonValue,  METH_NOARGS,(PY_METHODCHAR)GetButtonValue_doc},
315         //<----- Deprecated
316         {"getButtonActiveList",(PyCFunction) SCA_JoystickSensor::sPyGetButtonActiveList,        METH_NOARGS,(PY_METHODCHAR)GetButtonActiveList_doc},
317         {"getButtonStatus",(PyCFunction) SCA_JoystickSensor::sPyGetButtonStatus,        METH_VARARGS,(PY_METHODCHAR)GetButtonStatus_doc},
318         {NULL,NULL} //Sentinel
319 };
320
321 PyAttributeDef SCA_JoystickSensor::Attributes[] = {
322         KX_PYATTRIBUTE_SHORT_RW("index",0,JOYINDEX_MAX-1,true,SCA_JoystickSensor,m_joyindex),
323         KX_PYATTRIBUTE_INT_RW("threshold",0,32768,true,SCA_JoystickSensor,m_precision),
324         KX_PYATTRIBUTE_INT_RW("button",0,100,false,SCA_JoystickSensor,m_button),
325         KX_PYATTRIBUTE_INT_LIST_RW_CHECK("axis",0,3,true,SCA_JoystickSensor,m_axis,2,CheckAxis),
326         KX_PYATTRIBUTE_INT_LIST_RW_CHECK("hat",0,12,true,SCA_JoystickSensor,m_hat,2,CheckHat),
327         KX_PYATTRIBUTE_RO_FUNCTION("axisValues",        SCA_JoystickSensor, pyattr_get_axis_values),
328         KX_PYATTRIBUTE_RO_FUNCTION("axisSingle", SCA_JoystickSensor, pyattr_get_axis_single),
329         KX_PYATTRIBUTE_RO_FUNCTION("numAxis",           SCA_JoystickSensor, pyattr_get_num_axis),
330         KX_PYATTRIBUTE_RO_FUNCTION("numButtons",        SCA_JoystickSensor, pyattr_get_num_buttons),
331         KX_PYATTRIBUTE_RO_FUNCTION("numHats",           SCA_JoystickSensor, pyattr_get_num_hats),
332         KX_PYATTRIBUTE_RO_FUNCTION("connected",         SCA_JoystickSensor, pyattr_get_connected),
333         
334         { NULL }        //Sentinel
335 };
336
337 PyObject* SCA_JoystickSensor::py_getattro(PyObject *attr)
338 {
339         py_getattro_up(SCA_ISensor);
340 }
341
342 int SCA_JoystickSensor::py_setattro(PyObject *attr, PyObject *value) 
343 {
344         py_setattro_up(SCA_ISensor);
345 }
346
347
348 /* get index ---------------------------------------------------------- */
349 const char SCA_JoystickSensor::GetIndex_doc[] = 
350 "getIndex\n"
351 "\tReturns the joystick index to use.\n";
352 PyObject* SCA_JoystickSensor::PyGetIndex( PyObject* self ) {
353         ShowDeprecationWarning("getIndex()", "the index property");
354         return PyInt_FromLong(m_joyindex);
355 }
356
357
358 /* set index ---------------------------------------------------------- */
359 const char SCA_JoystickSensor::SetIndex_doc[] = 
360 "setIndex\n"
361 "\tSets the joystick index to use.\n";
362 PyObject* SCA_JoystickSensor::PySetIndex( PyObject* self, PyObject* value ) {
363         ShowDeprecationWarning("setIndex()", "the index property");
364         int index = PyInt_AsLong( value ); /* -1 on error, will raise an error in this case */
365         if (index < 0 || index >= JOYINDEX_MAX) {
366                 PyErr_SetString(PyExc_ValueError, "joystick index out of range or not an int");
367                 return NULL;
368         }
369         
370         m_joyindex = index;
371         Py_RETURN_NONE;
372 }
373
374 /* get axis  ---------------------------------------------------------- */
375 const char SCA_JoystickSensor::GetAxis_doc[] = 
376 "getAxis\n"
377 "\tReturns the current axis this sensor reacts to.\n";
378 PyObject* SCA_JoystickSensor::PyGetAxis( PyObject* self) {
379         ShowDeprecationWarning("getAxis()", "the axis property");
380         return Py_BuildValue("[ii]",m_axis, m_axisf);
381 }
382
383
384 /* set axis  ---------------------------------------------------------- */
385 const char SCA_JoystickSensor::SetAxis_doc[] = 
386 "setAxis\n"
387 "\tSets the current axis this sensor reacts to.\n";
388 PyObject* SCA_JoystickSensor::PySetAxis( PyObject* self, PyObject* args ) {
389         ShowDeprecationWarning("setAxis()", "the axis property");
390         
391         int axis,axisflag;
392         if(!PyArg_ParseTuple(args, "ii:setAxis", &axis, &axisflag)){
393                 return NULL;
394         }
395         m_axis = axis;
396         m_axisf = axisflag;
397         Py_RETURN_NONE;
398 }
399
400
401 /* get axis value ----------------------------------------------------- */
402 const char SCA_JoystickSensor::GetAxisValue_doc[] = 
403 "getAxisValue\n"
404 "\tReturns a list of the values for the current state of each axis.\n";
405 PyObject* SCA_JoystickSensor::PyGetAxisValue( PyObject* self) {
406         ShowDeprecationWarning("getAxisValue()", "the axisPosition property");
407         SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex);
408         
409         int axis_index= joy->GetNumberOfAxes();
410         PyObject *list= PyList_New(axis_index);
411         
412         while(axis_index--) {
413                 PyList_SET_ITEM(list, axis_index, PyInt_FromLong(joy->GetAxisPosition(axis_index)));
414         }
415         
416         return list;
417 }
418
419
420 /* get threshold  ----------------------------------------------------- */
421 const char SCA_JoystickSensor::GetThreshold_doc[] = 
422 "getThreshold\n"
423 "\tReturns the threshold of the axis.\n";
424 PyObject* SCA_JoystickSensor::PyGetThreshold( PyObject* self) {
425         ShowDeprecationWarning("getThreshold()", "the threshold property");
426         return PyInt_FromLong(m_precision);
427 }
428
429
430 /* set threshold  ----------------------------------------------------- */
431 const char SCA_JoystickSensor::SetThreshold_doc[] = 
432 "setThreshold\n"
433 "\tSets the threshold of the axis.\n";
434 PyObject* SCA_JoystickSensor::PySetThreshold( PyObject* self, PyObject* args ) {
435         ShowDeprecationWarning("setThreshold()", "the threshold property");
436         int thresh;
437         if(!PyArg_ParseTuple(args, "i:setThreshold", &thresh)){
438                 return NULL;
439         }
440         m_precision = thresh;
441         Py_RETURN_NONE;
442 }
443
444 /* get button  -------------------------------------------------------- */
445 const char SCA_JoystickSensor::GetButton_doc[] = 
446 "getButton\n"
447 "\tReturns the current button this sensor is checking.\n";
448 PyObject* SCA_JoystickSensor::PyGetButton( PyObject* self) {
449         ShowDeprecationWarning("getButton()", "the button property");
450         return PyInt_FromLong(m_button);
451 }
452
453 /* set button  -------------------------------------------------------- */
454 const char SCA_JoystickSensor::SetButton_doc[] = 
455 "setButton\n"
456 "\tSets the button the sensor reacts to.\n";
457 PyObject* SCA_JoystickSensor::PySetButton( PyObject* self, PyObject* value ) {
458         ShowDeprecationWarning("setButton()", "the button property");
459         int button = PyInt_AsLong(value);
460         if(button==-1 && PyErr_Occurred()) {
461                 PyErr_SetString(PyExc_ValueError, "expected an int");
462                 return NULL;
463         }
464         m_button = button;
465         Py_RETURN_NONE; 
466 }
467
468 /* get button value  -------------------------------------------------- */
469 const char SCA_JoystickSensor::GetButtonValue_doc[] = 
470 "getButtonValue\n"
471 "\tReturns a list containing the indicies of the current pressed state of each button.\n";
472 PyObject* SCA_JoystickSensor::PyGetButtonValue( PyObject* self) {
473         ShowDeprecationWarning("getButtonValue()", "getButtonActiveList");
474         return PyGetButtonActiveList(self);
475 }
476
477 /* get button active list  -------------------------------------------------- */
478 const char SCA_JoystickSensor::GetButtonActiveList_doc[] = 
479 "getButtonActiveList\n"
480 "\tReturns a list containing the indicies of the button currently pressed.\n";
481 PyObject* SCA_JoystickSensor::PyGetButtonActiveList( PyObject* self) {
482         SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex);
483         PyObject *ls = PyList_New(0);
484         PyObject *value;
485         int i;
486         
487         if(joy) {
488                 for (i=0; i < joy->GetNumberOfButtons(); i++) {
489                         if (joy->aButtonPressIsPositive(i)) {
490                                 value = PyInt_FromLong(i);
491                                 PyList_Append(ls, value);
492                                 Py_DECREF(value);
493                         }
494                 }
495         }
496         return ls;
497 }
498
499 /* get button status  -------------------------------------------------- */
500 const char SCA_JoystickSensor::GetButtonStatus_doc[] = 
501 "getButtonStatus(buttonIndex)\n"
502 "\tReturns a bool of the current pressed state of the specified button.\n";
503 PyObject* SCA_JoystickSensor::PyGetButtonStatus( PyObject* self, PyObject* args ) {
504         SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex);
505         int index;
506         
507         if(!PyArg_ParseTuple(args, "i:getButtonStatus", &index)){
508                 return NULL;
509         }
510         if(joy && index >= 0 && index < joy->GetNumberOfButtons()) {
511                 return PyBool_FromLong(joy->aButtonPressIsPositive(index) ? 1 : 0);
512         }
513         return PyBool_FromLong(0);
514 }
515
516 /* get hat      ----------------------------------------------------------- */
517 const char SCA_JoystickSensor::GetHat_doc[] = 
518 "getHat\n"
519 "\tReturns the current direction of the hat.\n";
520 PyObject* SCA_JoystickSensor::PyGetHat( PyObject* self ) {
521         ShowDeprecationWarning("getHat()", "the hat property");
522         return Py_BuildValue("[ii]",m_hat, m_hatf);
523 }
524
525
526 /* set hat      ----------------------------------------------------------- */
527 const char SCA_JoystickSensor::SetHat_doc[] = 
528 "setHat\n"
529 "\tSets the hat the sensor reacts to.\n";
530 PyObject* SCA_JoystickSensor::PySetHat( PyObject* self, PyObject* args ) {
531         ShowDeprecationWarning("setHat()", "the hat property");
532         int hat,hatflag;
533         if(!PyArg_ParseTuple(args, "ii:setHat", &hat, &hatflag)){
534                 return NULL;
535         }
536         m_hat = hat;
537         m_hatf = hatflag;
538         Py_RETURN_NONE;
539 }
540
541
542 /* get # of ----------------------------------------------------- */
543 const char SCA_JoystickSensor::NumberOfAxes_doc[] = 
544 "getNumAxes\n"
545 "\tReturns the number of axes .\n";
546 PyObject* SCA_JoystickSensor::PyNumberOfAxes( PyObject* self ) {
547         ShowDeprecationWarning("getNumAxes()", "the numAxis property");
548         SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex);
549         // when the joystick is null their is 0 exis still. dumb but scripters should use isConnected()
550         return PyInt_FromLong( joy ? joy->GetNumberOfAxes() : 0 );
551 }
552
553
554 const char SCA_JoystickSensor::NumberOfButtons_doc[] = 
555 "getNumButtons\n"
556 "\tReturns the number of buttons .\n";
557 PyObject* SCA_JoystickSensor::PyNumberOfButtons( PyObject* self ) {
558         ShowDeprecationWarning("getNumButtons()", "the numButtons property");
559         SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex);
560         return PyInt_FromLong( joy ? joy->GetNumberOfButtons() : 0 );
561 }
562
563
564 const char SCA_JoystickSensor::NumberOfHats_doc[] = 
565 "getNumHats\n"
566 "\tReturns the number of hats .\n";
567 PyObject* SCA_JoystickSensor::PyNumberOfHats( PyObject* self ) {
568         ShowDeprecationWarning("getNumHats()", "the numHats property");
569         SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex);
570         return PyInt_FromLong( joy ? joy->GetNumberOfHats() : 0 );
571 }
572
573 const char SCA_JoystickSensor::Connected_doc[] = 
574 "getConnected\n"
575 "\tReturns True if a joystick is connected at this joysticks index.\n";
576 PyObject* SCA_JoystickSensor::PyConnected( PyObject* self ) {
577         ShowDeprecationWarning("getConnected()", "the connected property");
578         SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex);
579         return PyBool_FromLong( joy ? joy->Connected() : 0 );
580 }
581
582
583 PyObject* SCA_JoystickSensor::pyattr_get_axis_values(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
584 {
585         SCA_JoystickSensor* self= static_cast<SCA_JoystickSensor*>(self_v);
586         SCA_Joystick *joy = self->m_pJoystickMgr->GetJoystickDevice(self->m_joyindex);
587         
588         int axis_index= joy->GetNumberOfAxes();
589         PyObject *list= PyList_New(axis_index);
590         
591         while(axis_index--) {
592                 PyList_SET_ITEM(list, axis_index, PyInt_FromLong(joy->GetAxisPosition(axis_index)));
593         }
594         
595         return list;
596 }
597
598 PyObject* SCA_JoystickSensor::pyattr_get_axis_single(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
599 {
600         SCA_JoystickSensor* self= static_cast<SCA_JoystickSensor*>(self_v);
601         SCA_Joystick *joy = self->m_pJoystickMgr->GetJoystickDevice(self->m_joyindex);
602         
603         if(self->m_joymode != KX_JOYSENSORMODE_AXIS_SINGLE) {
604                 PyErr_SetString(PyExc_TypeError, "joystick sensor is not an 'Single Axis' type");
605                 return NULL;
606         }
607         
608         return PyInt_FromLong(joy->GetAxisPosition(self->m_axis-1));
609 }
610
611 PyObject* SCA_JoystickSensor::pyattr_get_num_axis(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
612 {
613         SCA_JoystickSensor* self= static_cast<SCA_JoystickSensor*>(self_v);
614         SCA_Joystick *joy = self->m_pJoystickMgr->GetJoystickDevice(self->m_joyindex);
615         return PyInt_FromLong( joy ? joy->GetNumberOfAxes() : 0 );
616 }
617
618 PyObject* SCA_JoystickSensor::pyattr_get_num_buttons(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
619 {
620         SCA_JoystickSensor* self= static_cast<SCA_JoystickSensor*>(self_v);
621         SCA_Joystick *joy = self->m_pJoystickMgr->GetJoystickDevice(self->m_joyindex);
622         return PyInt_FromLong( joy ? joy->GetNumberOfButtons() : 0 );
623 }
624
625 PyObject* SCA_JoystickSensor::pyattr_get_num_hats(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
626 {
627         SCA_JoystickSensor* self= static_cast<SCA_JoystickSensor*>(self_v);
628         SCA_Joystick *joy = self->m_pJoystickMgr->GetJoystickDevice(self->m_joyindex);
629         return PyInt_FromLong( joy ? joy->GetNumberOfHats() : 0 );
630 }
631
632 PyObject* SCA_JoystickSensor::pyattr_get_connected(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
633 {
634         SCA_JoystickSensor* self= static_cast<SCA_JoystickSensor*>(self_v);
635         SCA_Joystick *joy = self->m_pJoystickMgr->GetJoystickDevice(self->m_joyindex);
636         return PyBool_FromLong( joy ? joy->Connected() : 0 );
637 }