Skip to content

Commit

Permalink
Add PtFindLayer.
Browse files Browse the repository at this point in the history
Yas, another helper.
  • Loading branch information
Hoikas committed Nov 11, 2024
1 parent 5d02d97 commit d1da38e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Scripts/Python/plasma/Plasma.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ def PtFindImage(name: str) -> Iterable[ptImage]:
"""Find an already loaded image by name"""
...

def PtFindLayer(name: str, age: str = "", page: str = "") -> Optional[ptLayer]:
"""Find a layer by name"""
...

def PtFindSceneobject(name,ageName):
"""This will try to find a sceneobject based on its name and what age its in
- it will return a ptSceneObject if found- if not found then a NameError exception will happen"""
Expand Down
1 change: 1 addition & 0 deletions Sources/Plasma/FeatureLib/pfPython/cyPythonInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,7 @@ void PythonInterface::AddPlasmaMethods(PyObject* m)
pyGUIDialog::AddPlasmaMethods(m);
pyImage::AddPlasmaMethods(m);
pyJournalBook::AddPlasmaMethods(m);
pyLayer::AddPlasmaMethods(m);
pySDLModifier::AddPlasmaMethods(m);
pySpawnPointInfo::AddPlasmaMethods(m);
}
Expand Down
9 changes: 9 additions & 0 deletions Sources/Plasma/FeatureLib/pfPython/pyLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ You can contact Cyan Worlds, Inc. by email [email protected]
#include "pyImage.h"

#include "plMessage/plLayRefMsg.h"
#include "plResMgr/plKeyFinder.h"

void pyLayer::setKey(pyKey& layerKey) // only for python glue, do NOT call
{
Expand Down Expand Up @@ -85,3 +86,11 @@ PyObject* pyLayer::GetTexture() const

PYTHON_RETURN_NONE;
}

PyObject* pyLayer::Find(const ST::string& name, const ST::string& age, const ST::string& page)
{
plKey foundKey = plKeyFinder::Instance().StupidSearch(age, page, plLayer::Index(), name);
if (foundKey)
return pyLayer::New(std::move(foundKey));
PYTHON_RETURN_NONE;
}
3 changes: 3 additions & 0 deletions Sources/Plasma/FeatureLib/pfPython/pyLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class pyLayer
PYTHON_CLASS_CONVERT_FROM_DEFINITION(pyLayer); // converts a PyObject to a pyLayer (throws error if not correct type)

static void AddPlasmaClasses(PyObject* m);
static void AddPlasmaMethods(PyObject* m);

void setKey(pyKey& layerKey);

Expand All @@ -120,6 +121,8 @@ class pyLayer
// For Python access
void SetTexture(plBitmap* image);
PyObject* GetTexture() const;

static PyObject* Find(const ST::string& name, const ST::string& age, const ST::string& page);
};

#endif // pyLayer_h
22 changes: 22 additions & 0 deletions Sources/Plasma/FeatureLib/pfPython/pyLayerGlue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,25 @@ void pyLayer::AddPlasmaClasses(PyObject* m)
PYTHON_CLASS_IMPORT(m, ptLayer);
PYTHON_CLASS_IMPORT_END(m);
}

PYTHON_GLOBAL_METHOD_DEFINITION_WKEY(PtFindLayer, args, kwds, "Params: name\nFind a layer by name.")
{
const char* kwdlist[]{"name", "age", "page", nullptr};
ST::string name, age, page;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&|O&O&", const_cast<char**>(kwdlist),
PyUnicode_STStringConverter, &name,
PyUnicode_STStringConverter, &age,
PyUnicode_STStringConverter, &page)) {
PyErr_SetString(PyExc_TypeError, "PtFindLayer expects a string and two optional strings");
PYTHON_RETURN_ERROR;
}

return pyLayer::Find(name, age, page);
}

void pyLayer::AddPlasmaMethods(PyObject* m)
{
PYTHON_START_GLOBAL_METHOD_TABLE(ptLayer)
PYTHON_GLOBAL_METHOD_WKEY(PtFindLayer)
PYTHON_END_GLOBAL_METHOD_TABLE(m, ptLayer)
}

0 comments on commit d1da38e

Please sign in to comment.