Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Bolsee <benoit.bolsee@online.be>2008-12-29 19:36:58 +0300
committerBenoit Bolsee <benoit.bolsee@online.be>2008-12-29 19:36:58 +0300
commit1c663bbc7e53cda1fe35579302574b0d98aa8db3 (patch)
tree4c0d3be6453932c01a9dc0fee0f820275cd6701d /source/gameengine/GameLogic/SCA_PythonController.cpp
parentd91daaa5f690645153adf647c371262c9c6cb009 (diff)
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.
Diffstat (limited to 'source/gameengine/GameLogic/SCA_PythonController.cpp')
-rw-r--r--source/gameengine/GameLogic/SCA_PythonController.cpp24
1 files changed, 23 insertions, 1 deletions
diff --git a/source/gameengine/GameLogic/SCA_PythonController.cpp b/source/gameengine/GameLogic/SCA_PythonController.cpp
index c354ab39747..e879481a444 100644
--- a/source/gameengine/GameLogic/SCA_PythonController.cpp
+++ b/source/gameengine/GameLogic/SCA_PythonController.cpp
@@ -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);
}