[Bf-python] game object property access
Thomas Dyar
tdyar at MIT.EDU
Mon Sep 15 20:04:46 CEST 2003
Hi,
I implemented a getGameProperties() method on the Object class that returns
a dictionary of property name, value pairs. I am open to design suggestions
for more functionality, but right now I just wanted python GUI's to be able
to read some of the game engine settings, not necessarily write them. Any
comments? Should it be committed? :)
Object.h file needs this line added:
#include <DNA_property_types.h>
Object.c additions:
static PyObject *Object_getGameProperties (BPy_Object *self);
static PyMethodDef BPy_Object_methods[] = {
...
{"getGameProperties", (PyCFunction)Object_getGameProperties, METH_NOARGS,
"Returns dictionary of game properties and their values"},
...
}
static PyObject *Object_getGameProperties (BPy_Object *self)
{
PyObject *key, *val;
PyObject *propertyDict = PyDict_New();
bProperty *prop;
prop= self->object->prop.first;
while(prop) {
key = Py_BuildValue("s", prop->name);
if(prop->type==PROP_BOOL) {
val = Py_BuildValue("b", prop->data);
}
else if(prop->type==PROP_INT){
val = Py_BuildValue("i", (int)prop->data);
}
else if(prop->type==PROP_FLOAT || prop->type==PROP_TIME){
val = Py_BuildValue("f", *((float*)&prop->data));
}
else if(prop->type==PROP_STRING){
val = Py_BuildValue("s", prop->poin);
}
PyDict_SetItem( propertyDict, key, val);
prop= prop->next;
}
return propertyDict;
}
Tom
More information about the Bf-python
mailing list