From 8261074f22fe92844cbbe22a0705bd445e363033 Mon Sep 17 00:00:00 2001 From: Bartek Bok Date: Wed, 25 Jul 2012 23:39:09 +0200 Subject: [PATCH] Better object searching --- Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp | 17 +++++++++++++++++ Sources/Plasma/FeatureLib/pfPython/cyMisc.h | 1 + .../Plasma/FeatureLib/pfPython/cyMiscGlue3.cpp | 12 ++++++++++++ 3 files changed, 30 insertions(+) diff --git a/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp b/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp index 2d2b8fc3..33cef6d5 100644 --- a/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp +++ b/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 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; diff --git a/Sources/Plasma/FeatureLib/pfPython/cyMisc.h b/Sources/Plasma/FeatureLib/pfPython/cyMisc.h index ef0fc7a0..9f2c6024 100644 --- a/Sources/Plasma/FeatureLib/pfPython/cyMisc.h +++ b/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 ///////////////////////////////////////////////////////////////////////////// diff --git a/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue3.cpp b/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue3.cpp index 71313789..98710749 100644 --- a/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue3.cpp +++ b/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 &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);