diff options
Diffstat (limited to 'source/gameengine/Ketsji/KX_PythonInit.cpp')
-rw-r--r-- | source/gameengine/Ketsji/KX_PythonInit.cpp | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 7dec4e4f97f..675cf3c09f6 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -38,8 +38,8 @@ extern "C" { #include "bpy_internal_import.h" /* from the blender python api, but we want to import text too! */ - #include "Mathutils.h" // Blender.Mathutils module copied here so the blenderlayer can use. - #include "Geometry.h" // Blender.Geometry module copied here so the blenderlayer can use. + #include "mathutils.h" // Blender.Mathutils module copied here so the blenderlayer can use. + #include "geometry.h" // Blender.Geometry module copied here so the blenderlayer can use. #include "bgl.h" #include "marshal.h" /* python header for loading/saving dicts */ @@ -73,6 +73,8 @@ extern "C" { #include "SCA_PropertySensor.h" #include "SCA_RandomActuator.h" #include "SCA_KeyboardSensor.h" /* IsPrintable, ToCharacter */ +#include "SCA_PythonKeyboard.h" +#include "SCA_PythonMouse.h" #include "KX_ConstraintActuator.h" #include "KX_IpoActuator.h" #include "KX_SoundActuator.h" @@ -1280,6 +1282,13 @@ PyObject* initGameLogic(KX_KetsjiEngine *engine, KX_Scene* scene) // quick hack PyDict_SetItemString(d, "globalDict", item=PyDict_New()); Py_DECREF(item); + // Add keyboard and mouse attributes to this module + SCA_PythonKeyboard* pykeyb = new SCA_PythonKeyboard(gp_KetsjiEngine->GetKeyboardDevice()); + PyDict_SetItemString(d, "keyboard", pykeyb->NewProxy(true)); + + SCA_PythonMouse* pymouse = new SCA_PythonMouse(gp_KetsjiEngine->GetMouseDevice(), gp_Canvas); + PyDict_SetItemString(d, "mouse", pymouse->NewProxy(true)); + ErrorObject = PyUnicode_FromString("GameLogic.error"); PyDict_SetItemString(d, "error", ErrorObject); Py_DECREF(ErrorObject); @@ -1622,7 +1631,7 @@ PyObject *KXpy_import(PyObject *self, PyObject *args) /* quick hack for GamePython modules TODO: register builtin modules properly by ExtendInittab */ if (!strcmp(name, "GameLogic") || !strcmp(name, "GameKeys") || !strcmp(name, "PhysicsConstraints") || - !strcmp(name, "Rasterizer") || !strcmp(name, "Mathutils") || !strcmp(name, "bgl") || !strcmp(name, "Geometry")) { + !strcmp(name, "Rasterizer") || !strcmp(name, "mathutils") || !strcmp(name, "bgl") || !strcmp(name, "geometry")) { return PyImport_ImportModuleEx(name, globals, locals, fromlist); } @@ -1978,7 +1987,7 @@ void setupGamePython(KX_KetsjiEngine* ketsjiengine, KX_Scene* startscene, Main * #endif /* could be done a lot more nicely, but for now a quick way to get bge.* working */ - PyRun_SimpleString("__import__('sys').modules['bge']=[mod for mod in (type(__builtins__)('bge'), ) if mod.__dict__.update({'logic':__import__('GameLogic'), 'render':__import__('Rasterizer'), 'keys':__import__('GameKeys'), 'constraints':__import__('PhysicsConstraints'), 'types':__import__('GameTypes')}) is None][0]"); + PyRun_SimpleString("__import__('sys').modules['bge']=[mod for mod in (type(__builtins__)('bge'), ) if mod.__dict__.update({'logic':__import__('GameLogic'), 'render':__import__('Rasterizer'), 'events':__import__('GameKeys'), 'constraints':__import__('PhysicsConstraints'), 'types':__import__('GameTypes')}) is None][0]"); } static struct PyModuleDef Rasterizer_module_def = { @@ -2257,6 +2266,15 @@ PyObject* initGameKeys() KX_MACRO_addTypesToDict(d, PAGEDOWNKEY, SCA_IInputDevice::KX_PAGEDOWNKEY); KX_MACRO_addTypesToDict(d, ENDKEY, SCA_IInputDevice::KX_ENDKEY); + // MOUSE + KX_MACRO_addTypesToDict(d, LEFTMOUSE, SCA_IInputDevice::KX_LEFTMOUSE); + KX_MACRO_addTypesToDict(d, MIDDLEMOUSE, SCA_IInputDevice::KX_MIDDLEMOUSE); + KX_MACRO_addTypesToDict(d, RIGHTMOUSE, SCA_IInputDevice::KX_RIGHTMOUSE); + KX_MACRO_addTypesToDict(d, WHEELUPMOUSE, SCA_IInputDevice::KX_WHEELUPMOUSE); + KX_MACRO_addTypesToDict(d, WHEELDOWNMOUSE, SCA_IInputDevice::KX_WHEELDOWNMOUSE); + KX_MACRO_addTypesToDict(d, MOUSEX, SCA_IInputDevice::KX_MOUSEX); + KX_MACRO_addTypesToDict(d, MOUSEY, SCA_IInputDevice::KX_MOUSEY); + // Check for errors if (PyErr_Occurred()) { |