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:
authorCampbell Barton <ideasman42@gmail.com>2009-06-29 16:06:46 +0400
committerCampbell Barton <ideasman42@gmail.com>2009-06-29 16:06:46 +0400
commit9a7ea9664e27679935adaea3093630d7a6a30b5d (patch)
tree96d706f511e571c490f33a4b1702a48c53033723 /source/gameengine/Expressions/Value.cpp
parent7ca31bb171b2c94f8e9b928990363a42af8716fb (diff)
BGE PyAPI support for subclassing any BGE game type from python, scripters define extra functions on gameObjects.
Adding a UI to set the type on startup can be added easily. # ---- class myPlayer(GameTypes.KX_GameObject): def die(self): # ... do stuff ... self.endObject() # make an instance player = myPlayer(gameOb) # gameOb is made invalid now. player.die() # ---- One limitation (which could also be an advantage), is making the subclass instance will return that subclass everywhere, you cant have 2 different subclasses of the same BGE data at once.
Diffstat (limited to 'source/gameengine/Expressions/Value.cpp')
-rw-r--r--source/gameengine/Expressions/Value.cpp21
1 files changed, 7 insertions, 14 deletions
diff --git a/source/gameengine/Expressions/Value.cpp b/source/gameengine/Expressions/Value.cpp
index a9b44495495..d8c81f56f66 100644
--- a/source/gameengine/Expressions/Value.cpp
+++ b/source/gameengine/Expressions/Value.cpp
@@ -54,15 +54,17 @@ PyTypeObject CValue::Type = {
py_base_repr,
0,
0,0,0,0,0,
- NULL, //py_base_getattro,
- NULL, //py_base_setattro,
+ NULL,
+ NULL,
0,
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
0,0,0,0,0,0,0,
Methods,
0,
0,
- &PyObjectPlus::Type
+ &PyObjectPlus::Type,
+ 0,0,0,0,0,0,
+ py_base_new
};
PyMethodDef CValue::Methods[] = {
@@ -613,18 +615,9 @@ CValue* CValue::ConvertPythonToValue(PyObject* pyobj, const char *error_prefix)
{
vallie = new CStringValue(_PyUnicode_AsString(pyobj),"");
} else
- if (BGE_PROXY_CHECK_TYPE(pyobj)) /* Note, dont let these get assigned to GameObject props, must check elsewhere */
+ if (PyObject_TypeCheck(pyobj, &CValue::Type)) /* Note, dont let these get assigned to GameObject props, must check elsewhere */
{
- if (BGE_PROXY_REF(pyobj) && PyObject_TypeCheck((PyObject *)BGE_PROXY_REF(pyobj), &CValue::Type))
- {
- vallie = (static_cast<CValue *>(BGE_PROXY_REF(pyobj)))->AddRef();
- } else {
-
- if(BGE_PROXY_REF(pyobj)) /* this is not a CValue */
- PyErr_Format(PyExc_TypeError, "%sgame engine python type cannot be used as a property", error_prefix);
- else /* PyObjectPlus_Proxy has been removed, cant use */
- PyErr_Format(PyExc_SystemError, "%s"BGE_PROXY_ERROR_MSG, error_prefix);
- }
+ vallie = (static_cast<CValue *>(BGE_PROXY_REF(pyobj)))->AddRef();
} else
{
/* return an error value from the caller */