Browse Source

Better object searching

Bartek Bok 13 years ago committed by Adam Johnson
parent
commit
8261074f22
  1. 17
      Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp
  2. 1
      Sources/Plasma/FeatureLib/pfPython/cyMisc.h
  3. 12
      Sources/Plasma/FeatureLib/pfPython/cyMiscGlue3.cpp

17
Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp

@ -222,6 +222,23 @@ PyObject* cyMisc::FindSceneObject(const plString& name, const char* ageName)
return pySceneObject::New(key);
}
PyObject* cyMisc::FindSceneObjects(const plString& name)
{
// assume that we won't find the sceneobject (key is equal to nil)
std::vector<plKey> keys;
if ( !name.IsNull() )
plKeyFinder::Instance().ReallyStupidSubstringSearch(name, plSceneObject::Index(), keys);
PyObject* result = PyList_New(keys.size());
for (size_t i=0; i < keys.size(); i++)
PyList_SET_ITEM(result, i, pySceneObject::New(keys[i]));
return result;
}
PyObject* cyMisc::FindActivator(const plString& name)
{
plKey key = nil;

1
Sources/Plasma/FeatureLib/pfPython/cyMisc.h

@ -147,6 +147,7 @@ public:
// optionally propagate over the net
//
static PyObject* FindSceneObject(const plString& name, const char* ageName); // returns pySceneObject
static PyObject* FindSceneObjects(const plString& name);
static PyObject* FindActivator(const plString& name); // returns pyKey
/////////////////////////////////////////////////////////////////////////////

12
Sources/Plasma/FeatureLib/pfPython/cyMiscGlue3.cpp

@ -190,6 +190,17 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtFindSceneobject, args, "Params: name,ageName\n
return cyMisc::FindSceneObject(plString::FromUtf8(name), ageName);
}
PYTHON_GLOBAL_METHOD_DEFINITION(PtFindSceneobjects, args, "Params: name\nThis will try to find a any sceneobject containing string in name")
{
char* name = NULL;
if (!PyArg_ParseTuple(args, "s", &name))
{
PyErr_SetString(PyExc_TypeError, "PtFindSceneobject expects string");
PYTHON_RETURN_ERROR;
}
return cyMisc::FindSceneObjects(plString::FromUtf8(name));
}
PYTHON_GLOBAL_METHOD_DEFINITION(PtFindActivator, args, "Params: name\nThis will try to find an activator based on its name\n"
"- it will return a ptKey if found"
"- it will return None if not found")
@ -700,6 +711,7 @@ void cyMisc::AddPlasmaMethods3(std::vector<PyMethodDef> &methods)
PYTHON_GLOBAL_METHOD(methods, PtClearTimerCallbacks);
PYTHON_GLOBAL_METHOD(methods, PtFindSceneobject);
PYTHON_GLOBAL_METHOD(methods, PtFindSceneobjects);
PYTHON_GLOBAL_METHOD(methods, PtFindActivator);
PYTHON_BASIC_GLOBAL_METHOD(methods, PtClearCameraStack);
PYTHON_GLOBAL_METHOD(methods, PtWasLocallyNotified);

Loading…
Cancel
Save