Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose modifier targets to Python. #293

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions Python/PRP/Modifier/pyModifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,75 @@
#include "pyModifier.h"

#include <PRP/Modifier/plModifier.h>
#include "PRP/KeyedObject/pyKey.h"
#include "PRP/Object/pySynchedObject.h"
#include "PRP/pyCreatable.h"

PY_PLASMA_NEW_MSG(Modifier, "plModifier is abstract")

PY_METHOD_VA(Modifier, addTarget,
"Params: key\n"
"Add referenced scene object")
{
pyKey* key;
if (!PyArg_ParseTuple(args, "O", &key)) {
PyErr_SetString(PyExc_TypeError, "addTarget expects a plKey");
return nullptr;
}
if (!pyKey_Check((PyObject*)key)) {
PyErr_SetString(PyExc_TypeError, "addTarget expects a plKey");
return nullptr;
}
self->fThis->addTarget(*key->fThis);
Py_RETURN_NONE;
}

PY_METHOD_VA(Modifier, removeTarget,
"Params: key\n"
"Remove scene object from target list")
{
pyKey* key;
if (!PyArg_ParseTuple(args, "O", &key)) {
PyErr_SetString(PyExc_TypeError, "removeTarget expects a plKey");
return nullptr;
}
if (!pyKey_Check((PyObject*)key)) {
PyErr_SetString(PyExc_TypeError, "removeTarget expects a plKey");
return nullptr;
}
self->fThis->removeTarget(*key->fThis);
Py_RETURN_NONE;
}

static PyMethodDef pyModifier_Methods[] = {
pyModifier_addTarget_method,
pyModifier_removeTarget_method,
PY_METHOD_TERMINATOR
};

PY_GETSET_GETTER_DECL(Modifier, targets)
{
PyObject* tup = PyTuple_New(self->fThis->getTargetsCount());
for (size_t i = 0; i < self->fThis->getTargetsCount(); ++i)
PyTuple_SET_ITEM(tup, i, pyPlasma_convert(self->fThis->getTarget(i)));
return tup;
}

PY_PROPERTY_SETTER_MSG(Modifier, targets, "To add targets, use addTarget()")
PY_PROPERTY_GETSET_DECL(Modifier, targets)

static PyGetSetDef pyModifier_GetSet[] = {
pyModifier_targets_getset,
PY_GETSET_TERMINATOR
};

PY_PLASMA_TYPE(Modifier, plModifier, "plModifier wrapper")

PY_PLASMA_TYPE_INIT(Modifier)
{
pyModifier_Type.tp_new = pyModifier_new;
pyModifier_Type.tp_methods = pyModifier_Methods;
pyModifier_Type.tp_getset = pyModifier_GetSet;
pyModifier_Type.tp_base = &pySynchedObject_Type;
if (PyType_CheckAndReady(&pyModifier_Type) < 0)
return nullptr;
Expand Down
15 changes: 15 additions & 0 deletions Python/PRP/Modifier/pySingleModifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "pyModifier.h"

#include "PRP/KeyedObject/pyKey.h"
#include <PRP/Modifier/plModifier.h>
#include "PRP/pyCreatable.h"

Expand Down Expand Up @@ -52,12 +53,26 @@ static PyMethodDef pySingleModifier_Methods[] = {
PY_METHOD_TERMINATOR
};

PY_GETSET_GETTER_DECL(SingleModifier, target)
{
return pyPlasma_convert(self->fThis->getTarget(0));
}

PY_PROPERTY_WRITE(plKey, SingleModifier, target, addTarget)
PY_PROPERTY_GETSET_DECL(SingleModifier, target)

static PyGetSetDef pySingleModifier_GetSet[] = {
pySingleModifier_target_getset,
PY_GETSET_TERMINATOR
};

PY_PLASMA_TYPE(SingleModifier, plSingleModifier, "plSingleModifier wrapper")

PY_PLASMA_TYPE_INIT(SingleModifier)
{
pySingleModifier_Type.tp_new = pySingleModifier_new;
pySingleModifier_Type.tp_methods = pySingleModifier_Methods;
pySingleModifier_Type.tp_getset = pySingleModifier_GetSet;
pySingleModifier_Type.tp_base = &pyModifier_Type;
if (PyType_CheckAndReady(&pySingleModifier_Type) < 0)
return nullptr;
Expand Down
7 changes: 6 additions & 1 deletion Python/PyHSPlasma.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4144,7 +4144,10 @@ class plMobileOccluder(plOccluder):
worldToLocal: hsMatrix44 = ...

class plModifier(plSynchedObject):
...
targets: Sequence[plKey[plSceneObject]] = ...

def addTarget(self, key: plKey[plSceneObject]) -> None: ...
def removeTarget(self, key: plKey[plSceneObject]) -> None: ...

class plMsgForwarder(hsKeyedObject):
forwardKeys: Sequence[plKey] = ...
Expand Down Expand Up @@ -5016,6 +5019,8 @@ class plSimulationMsg(plMessage):
...

class plSingleModifier(plModifier):
target: Optional[plKey[plSceneObject]] = ...

def getFlag(self, flag: int) -> bool: ...
def setFlag(self, flag: int, value: bool) -> None: ...

Expand Down
Loading