diff --git a/Python/PyHSPlasma.pyi b/Python/PyHSPlasma.pyi index 4fea1822..c8200f9e 100644 --- a/Python/PyHSPlasma.pyi +++ b/Python/PyHSPlasma.pyi @@ -4654,7 +4654,9 @@ class plRenderTarget(plBitmap): width: int = ... class plResManager: - def __init__(self, version: int = pvUnknown) -> None: ... + preserveObjIDs: bool = ... + + def __init__(self, version: int = pvUnknown, preserveObjIDs: bool = False) -> None: ... def AddAge(self, age: plAgeInfo) -> None: ... def AddObject(self, location: plLocation, object: hsKeyedObject) -> None: ... def AddPage(self, page: plPageInfo) -> None: ... diff --git a/Python/ResManager/pyResManager.cpp b/Python/ResManager/pyResManager.cpp index 1ab22cb9..950dc7e2 100644 --- a/Python/ResManager/pyResManager.cpp +++ b/Python/ResManager/pyResManager.cpp @@ -28,11 +28,15 @@ PY_PLASMA_DEALLOC(ResManager) PY_PLASMA_INIT_DECL(ResManager) { + char* kwdlist[] = { "version", "preserveObjIDs", nullptr }; + int version = PlasmaVer::pvUnknown; - if (!PyArg_ParseTuple(args, "|i", &version)) + bool preserveObjIDs = false; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|ib", kwdlist, &version, &preserveObjIDs)) return -1; self->fThis->setVer((PlasmaVer)version); + self->fThis->setPreserveObjIDs(preserveObjIDs); return 0; } @@ -654,6 +658,13 @@ static PyMethodDef pyResManager_Methods[] = { PY_METHOD_TERMINATOR }; +PY_PROPERTY(bool, ResManager, preserveObjIDs, getPreserveObjIDs, setPreserveObjIDs) + +static PyGetSetDef pyResManager_GetSet[] = { + pyResManager_preserveObjIDs_getset, + PY_GETSET_TERMINATOR +}; + PY_PLASMA_TYPE(ResManager, plResManager, "Resource Manager") PY_PLASMA_TYPE_INIT(ResManager) @@ -662,6 +673,7 @@ PY_PLASMA_TYPE_INIT(ResManager) pyResManager_Type.tp_init = pyResManager___init__; pyResManager_Type.tp_new = pyResManager_new; pyResManager_Type.tp_methods = pyResManager_Methods; + pyResManager_Type.tp_getset = pyResManager_GetSet; if (PyType_CheckAndReady(&pyResManager_Type) < 0) return nullptr; diff --git a/core/ResManager/plResManager.cpp b/core/ResManager/plResManager.cpp index fdac103c..d05df664 100644 --- a/core/ResManager/plResManager.cpp +++ b/core/ResManager/plResManager.cpp @@ -71,7 +71,11 @@ plKey plResManager::readUoid(hsStream* S) k->readUoid(S); if (!k->getLocation().isValid()) return plKey(); - return AddKey(k); + + plKey newkey = AddKey(k); + if (preserveIDs) + newkey->setID(k->getID()); + return newkey; } void plResManager::writeKey(hsStream* S, const plKey& key) diff --git a/core/ResManager/plResManager.h b/core/ResManager/plResManager.h index 87936828..eaac7460 100644 --- a/core/ResManager/plResManager.h +++ b/core/ResManager/plResManager.h @@ -106,6 +106,24 @@ class HSPLASMA_EXPORT plResManager */ void setVer(PlasmaVer pv, bool force = false); + /** + * Set whether or not keyed object IDs should be preserved from + * PRPs that are read in. By default, key IDs are reordered to be + * consecutive when a PRP is read. This setting doesn't have any + * effect on data already loaded. + * \param preserve Preserve keyed object IDs + * \sa getPreserveObjIDs() + */ + void setPreserveObjIDs(bool preserve) { preserveIDs = preserve; } + + /** + * Get whether or not keyed object IDs are preserved from PRPs + * that are read in. By default, key IDs are reordered to be + * consecutive when a PRP is read. + * \sa setPreserveObjIDs() + */ + bool getPreserveObjIDs() const { return preserveIDs; } + /** * Return the version of data files this ResManager expects to * deal with. Used for reading or writing data to files only.