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.
This commit is contained in:
Benoit Bolsee
2008-12-29 16:36:58 +00:00
parent d91daaa5f6
commit 1c663bbc7e
37 changed files with 1184 additions and 249 deletions

View File

@@ -233,9 +233,11 @@ PyMethodDef SCA_PythonController::Methods[] = {
{"getActuator", (PyCFunction) SCA_PythonController::sPyGetActuator, METH_O, (PY_METHODCHAR)SCA_PythonController::GetActuator_doc},
{"getSensors", (PyCFunction) SCA_PythonController::sPyGetSensors, METH_NOARGS, (PY_METHODCHAR)SCA_PythonController::GetSensors_doc},
{"getSensor", (PyCFunction) SCA_PythonController::sPyGetSensor, METH_O, (PY_METHODCHAR)SCA_PythonController::GetSensor_doc},
{"getScript", (PyCFunction) SCA_PythonController::sPyGetScript, METH_NOARGS},
{"setScript", (PyCFunction) SCA_PythonController::sPySetScript, METH_O},
//Deprecated functions ------>
{"getScript", (PyCFunction) SCA_PythonController::sPyGetScript, METH_NOARGS},
{"getState", (PyCFunction) SCA_PythonController::sPyGetState, METH_NOARGS},
//<----- Deprecated
{NULL,NULL} //Sentinel
};
@@ -329,9 +331,27 @@ void SCA_PythonController::Trigger(SCA_LogicManager* logicmgr)
PyObject* SCA_PythonController::_getattr(const STR_String& attr)
{
if (attr == "script") {
return PyString_FromString(m_scriptText);
}
if (attr == "state") {
return PyInt_FromLong(m_statemask);
}
_getattr_up(SCA_IController);
}
int SCA_PythonController::_setattr(const STR_String& attr, PyObject *value)
{
if (attr == "script") {
PyErr_SetString(PyExc_AttributeError, "script is read only, use setScript() to update the script");
return 1;
}
if (attr == "state") {
PyErr_SetString(PyExc_AttributeError, "state is read only");
return 1;
}
return SCA_IController::_setattr(attr, value);
}
PyObject* SCA_PythonController::PyGetActuators(PyObject* self)
@@ -420,6 +440,7 @@ SCA_PythonController::PyGetSensors(PyObject* self)
/* 1. getScript */
PyObject* SCA_PythonController::PyGetScript(PyObject* self)
{
ShowDeprecationWarning("getScript()", "the script property");
return PyString_FromString(m_scriptText);
}
@@ -443,6 +464,7 @@ PyObject* SCA_PythonController::PySetScript(PyObject* self, PyObject* value)
/* 1. getScript */
PyObject* SCA_PythonController::PyGetState(PyObject* self)
{
ShowDeprecationWarning("getState()", "the state property");
return PyInt_FromLong(m_statemask);
}