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>2009-01-02 20:43:56 +0300
committerBenoit Bolsee <benoit.bolsee@online.be>2009-01-02 20:43:56 +0300
commitcc569504d0468ec19a1018ea804aa418c134cb0f (patch)
tree732f5d6fe3d742f63dae5f6e899aea566ae52b0f /source/gameengine/GameLogic/SCA_RandomActuator.cpp
parentabd4934d1aeceafaa2fc242f00db0ba53a7e24db (diff)
BGE API Cleanup: update the python attribute definition framework.
* Value clamping to min/max is now supported as an option for integer, float and string attribute (for string clamping=trim to max length) * Post check function now take PyAttributeDef parameter so that more generic function can be written. * Definition of SCA_ILogicBrick::CheckProperty() function to check that a string attribute contains a valid property name of the parent game object. * Definition of enum attribute vi KX_PYATTRIBUTE_ENUM... macros. Enum are handled just like integer but to be totally paranoid, the sizeof() of the enum member is check at run time to match integer size. * More bricks updated to use the framework.
Diffstat (limited to 'source/gameengine/GameLogic/SCA_RandomActuator.cpp')
-rw-r--r--source/gameengine/GameLogic/SCA_RandomActuator.cpp61
1 files changed, 21 insertions, 40 deletions
diff --git a/source/gameengine/GameLogic/SCA_RandomActuator.cpp b/source/gameengine/GameLogic/SCA_RandomActuator.cpp
index 8dd405c3d82..840b95d559a 100644
--- a/source/gameengine/GameLogic/SCA_RandomActuator.cpp
+++ b/source/gameengine/GameLogic/SCA_RandomActuator.cpp
@@ -361,57 +361,38 @@ PyMethodDef SCA_RandomActuator::Methods[] = {
{NULL,NULL} //Sentinel
};
+PyAttributeDef SCA_RandomActuator::Attributes[] = {
+ KX_PYATTRIBUTE_FLOAT_RO("para1",SCA_RandomActuator,m_parameter1),
+ KX_PYATTRIBUTE_FLOAT_RO("para2",SCA_RandomActuator,m_parameter2),
+ KX_PYATTRIBUTE_ENUM_RO("distribution",SCA_RandomActuator,m_distribution),
+ KX_PYATTRIBUTE_STRING_RW_CHECK("property",0,100,false,SCA_RandomActuator,m_propname,CheckProperty),
+ { NULL } //Sentinel
+};
+
PyObject* SCA_RandomActuator::_getattr(const STR_String& attr) {
+ PyObject* object = _getattr_self(Attributes, this, attr);
+ if (object != NULL)
+ return object;
if (attr == "seed") {
return PyInt_FromLong(m_base->GetSeed());
}
- if (attr == "para1") {
- return PyFloat_FromDouble(m_parameter1);
- }
- if (attr == "para2") {
- return PyFloat_FromDouble(m_parameter2);
- }
- if (attr == "distribution") {
- return PyInt_FromLong(m_distribution);
- }
- if (attr == "property") {
- return PyString_FromString(m_propname);
- }
_getattr_up(SCA_IActuator);
}
int SCA_RandomActuator::_setattr(const STR_String& attr, PyObject *value)
{
- if (attr == "para1") {
- PyErr_SetString(PyExc_AttributeError, "para1 is read only");
- }
- if (attr == "para2") {
- PyErr_SetString(PyExc_AttributeError, "para2 is read only");
- }
- if (attr == "distribution") {
- PyErr_SetString(PyExc_AttributeError, "distribution is read only");
- }
- if (PyInt_Check(value)) {
- int ival = PyInt_AsLong(value);
- if (attr == "seed") {
+ int ret = _setattr_self(Attributes, this, attr, value);
+ if (ret >= 0)
+ return ret;
+ if (attr == "seed") {
+ if (PyInt_Check(value)) {
+ int ival = PyInt_AsLong(value);
m_base->SetSeed(ival);
+ return 0;
+ } else {
+ PyErr_SetString(PyExc_TypeError, "expected an integer");
+ return 1;
}
- return 0;
- }
- 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;
- }
- }
}
return SCA_IActuator::_setattr(attr, value);
}