diff --git a/Python/PRP/Modifier/pyModifier.cpp b/Python/PRP/Modifier/pyModifier.cpp index c391c67c..c093f98b 100644 --- a/Python/PRP/Modifier/pyModifier.cpp +++ b/Python/PRP/Modifier/pyModifier.cpp @@ -17,16 +17,75 @@ #include "pyModifier.h" #include +#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; diff --git a/Python/PRP/Modifier/pySingleModifier.cpp b/Python/PRP/Modifier/pySingleModifier.cpp index 98b0339f..9579fabc 100644 --- a/Python/PRP/Modifier/pySingleModifier.cpp +++ b/Python/PRP/Modifier/pySingleModifier.cpp @@ -16,6 +16,7 @@ #include "pyModifier.h" +#include "PRP/KeyedObject/pyKey.h" #include #include "PRP/pyCreatable.h" @@ -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; diff --git a/Python/PyHSPlasma.pyi b/Python/PyHSPlasma.pyi index bd1793bb..02f09a39 100644 --- a/Python/PyHSPlasma.pyi +++ b/Python/PyHSPlasma.pyi @@ -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] = ... @@ -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: ...