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_PropertyActuator.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_PropertyActuator.cpp')
-rw-r--r--source/gameengine/GameLogic/SCA_PropertyActuator.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/source/gameengine/GameLogic/SCA_PropertyActuator.cpp b/source/gameengine/GameLogic/SCA_PropertyActuator.cpp
index 3b541e87f02..f8509fe380e 100644
--- a/source/gameengine/GameLogic/SCA_PropertyActuator.cpp
+++ b/source/gameengine/GameLogic/SCA_PropertyActuator.cpp
@@ -245,17 +245,48 @@ PyParentObject SCA_PropertyActuator::Parents[] = {
};
PyMethodDef SCA_PropertyActuator::Methods[] = {
+ //Deprecated functions ------>
{"setProperty", (PyCFunction) SCA_PropertyActuator::sPySetProperty, METH_VARARGS, (PY_METHODCHAR)SetProperty_doc},
{"getProperty", (PyCFunction) SCA_PropertyActuator::sPyGetProperty, METH_VARARGS, (PY_METHODCHAR)GetProperty_doc},
{"setValue", (PyCFunction) SCA_PropertyActuator::sPySetValue, METH_VARARGS, (PY_METHODCHAR)SetValue_doc},
{"getValue", (PyCFunction) SCA_PropertyActuator::sPyGetValue, METH_VARARGS, (PY_METHODCHAR)GetValue_doc},
+ //<----- Deprecated
{NULL,NULL} //Sentinel
};
PyObject* SCA_PropertyActuator::_getattr(const STR_String& attr) {
+ if (attr == "property") {
+ return PyString_FromString(m_propname);
+ }
+ if (attr == "value") {
+ return PyString_FromString(m_exprtxt);
+ }
_getattr_up(SCA_IActuator);
}
+int SCA_PropertyActuator::_setattr(const STR_String& attr, PyObject *value) {
+ if (PyString_Check(value)) {
+ char* sval = PyString_AsString(value);
+ if (attr == "property") {
+ CValue* prop = GetParent()->FindIdentifier(sval);
+ bool error = prop->IsError();
+ prop->Release();
+ if (!prop->IsError()) {
+ m_propname = sval;
+ return 0;
+ } else {
+ PyErr_SetString(PyExc_ValueError, "string does not correspond to a property");
+ return 1;
+ }
+ }
+ if (attr == "value") {
+ m_exprtxt = sval;
+ return 0;
+ }
+ }
+ return SCA_IActuator::_setattr(attr, value);
+}
+
/* 1. setProperty */
const char SCA_PropertyActuator::SetProperty_doc[] =
"setProperty(name)\n"
@@ -264,6 +295,7 @@ const char SCA_PropertyActuator::SetProperty_doc[] =
"\tof this name, the call is ignored.\n";
PyObject* SCA_PropertyActuator::PySetProperty(PyObject* self, PyObject* args, PyObject* kwds)
{
+ ShowDeprecationWarning("setProperty()", "the 'property' property");
/* Check whether the name exists first ! */
char *nameArg;
if (!PyArg_ParseTuple(args, "s", &nameArg)) {
@@ -288,6 +320,7 @@ const char SCA_PropertyActuator::GetProperty_doc[] =
"\tReturn the property on which the actuator operates.\n";
PyObject* SCA_PropertyActuator::PyGetProperty(PyObject* self, PyObject* args, PyObject* kwds)
{
+ ShowDeprecationWarning("getProperty()", "the 'property' property");
return PyString_FromString(m_propname);
}
@@ -300,6 +333,7 @@ const char SCA_PropertyActuator::SetValue_doc[] =
"\t action is ignored.\n";
PyObject* SCA_PropertyActuator::PySetValue(PyObject* self, PyObject* args, PyObject* kwds)
{
+ ShowDeprecationWarning("setValue()", "the value property");
char *valArg;
if(!PyArg_ParseTuple(args, "s", &valArg)) {
return NULL;
@@ -316,6 +350,7 @@ const char SCA_PropertyActuator::GetValue_doc[] =
"\tReturns the value with which the actuator operates.\n";
PyObject* SCA_PropertyActuator::PyGetValue(PyObject* self, PyObject* args, PyObject* kwds)
{
+ ShowDeprecationWarning("getValue()", "the value property");
return PyString_FromString(m_exprtxt);
}