fix BGE bug #8668: Behavior of os.getcwd() is not consistent between operating systems

Add a function GameLogic.expandPath() that works like Blender.sys.expandpath() and is also available in the BlenderPlayer.
Fix the game actuator in the BlenderPlayer to work like in Blender: 
- try first to load the .blend from the current working directory
- if not found, try to load from the startup .blend or runtime base directory
This commit is contained in:
2008-05-11 18:45:30 +00:00
parent 6da415d406
commit 96486b356f
3 changed files with 66 additions and 5 deletions

View File

@@ -88,6 +88,10 @@
//#include "BPY_extern.h"
#endif
#include "BKE_utildefines.h"
#include "BKE_global.h"
#include "BLI_blenlib.h"
static void setSandbox(TPythonSecurityLevel level);
@@ -140,6 +144,32 @@ static PyObject* gPySetGravity(PyObject*,
return NULL;
}
static char gPyExpandPath_doc[] =
"(path) - Converts a blender internal path into a proper file system path.\n\
path - the string path to convert.\n\n\
Use / as directory separator in path\n\
You can use '//' at the start of the string to define a relative path;\n\
Blender replaces that string by the directory of the startup .blend or runtime\n\
file to make a full path name (doesn't change during the game, even if you load\n\
other .blend).\n\
The function also converts the directory separator to the local file system format.";
static PyObject* gPyExpandPath(PyObject*,
PyObject* args,
PyObject*)
{
char expanded[FILE_MAXDIR + FILE_MAXFILE];
char* filename;
if (PyArg_ParseTuple(args,"s",&filename))
{
BLI_strncpy(expanded, filename, FILE_MAXDIR + FILE_MAXFILE);
BLI_convertstringcode(expanded, G.sce);
return PyString_FromString(expanded);
}
return NULL;
}
static bool usedsp = false;
@@ -361,6 +391,7 @@ static PyObject *pyPrintExt(PyObject *,PyObject *,PyObject *)
static struct PyMethodDef game_methods[] = {
{"expandPath", (PyCFunction)gPyExpandPath, METH_VARARGS, gPyExpandPath_doc},
{"getCurrentController",
(PyCFunction) SCA_PythonController::sPyGetCurrentController,
METH_VARARGS, SCA_PythonController::sPyGetCurrentController__doc__},