From 83c6af80057dca16b8ea1efbf4d31ba4eb6a6660 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 16 Nov 2024 17:26:49 -0500 Subject: [PATCH] Allow `ptLayer.setTexture()` for unloaded images. This is useful for setting textures that are in global PRPs. --- Sources/Plasma/FeatureLib/pfPython/pyImage.cpp | 7 ------- Sources/Plasma/FeatureLib/pfPython/pyLayer.cpp | 4 ++-- Sources/Plasma/FeatureLib/pfPython/pyLayer.h | 2 +- Sources/Plasma/FeatureLib/pfPython/pyLayerGlue.cpp | 2 +- 4 files changed, 4 insertions(+), 11 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfPython/pyImage.cpp b/Sources/Plasma/FeatureLib/pfPython/pyImage.cpp index 43b291fb33..8e29eb9d4a 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyImage.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/pyImage.cpp @@ -42,7 +42,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "pyImage.h" -#include #include #include @@ -209,12 +208,6 @@ PyObject* pyImage::Find(const ST::string& name) { std::vector foundKeys; plKeyFinder::Instance().ReallyStupidSubstringSearch(name, plMipmap::Index(), foundKeys); - // Remove anything that isn't loaded - they aren't useful in Python code - std::remove_if( - foundKeys.begin(), - foundKeys.end(), - [](const plKey& key) { return key->ObjectIsLoaded() == nullptr; } - ); PyObject* tup = PyTuple_New(foundKeys.size()); for (size_t i = 0; i < foundKeys.size(); ++i) diff --git a/Sources/Plasma/FeatureLib/pfPython/pyLayer.cpp b/Sources/Plasma/FeatureLib/pfPython/pyLayer.cpp index 9ecc390758..9304ec13fe 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyLayer.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/pyLayer.cpp @@ -66,13 +66,13 @@ plLayer* pyLayer::GetLayer() const return plLayer::ConvertNoRef(fLayerKey->ObjectIsLoaded()); } -void pyLayer::SetTexture(plBitmap* image) +void pyLayer::SetTexture(const plKey& image) { plLayer* layer = GetLayer(); if (image) { plLayRefMsg* refMsg = new plLayRefMsg(fLayerKey, plRefMsg::kOnReplace, 0, plLayRefMsg::kTexture); - hsgResMgr::ResMgr()->AddViaNotify(image->GetKey(), refMsg, plRefFlags::kActiveRef); + hsgResMgr::ResMgr()->AddViaNotify(image, refMsg, plRefFlags::kActiveRef); } } diff --git a/Sources/Plasma/FeatureLib/pfPython/pyLayer.h b/Sources/Plasma/FeatureLib/pfPython/pyLayer.h index 3768ba387c..c8dbd64c4a 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyLayer.h +++ b/Sources/Plasma/FeatureLib/pfPython/pyLayer.h @@ -119,7 +119,7 @@ class pyLayer plLayer* GetLayer() const; // For Python access - void SetTexture(plBitmap* image); + void SetTexture(const plKey& image); PyObject* GetTexture() const; static PyObject* Find(const ST::string& name, const ST::string& age, const ST::string& page); diff --git a/Sources/Plasma/FeatureLib/pfPython/pyLayerGlue.cpp b/Sources/Plasma/FeatureLib/pfPython/pyLayerGlue.cpp index dccdcffd31..d89917c510 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyLayerGlue.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/pyLayerGlue.cpp @@ -87,7 +87,7 @@ PYTHON_METHOD_DEFINITION(ptLayer, setTexture, args) PYTHON_RETURN_ERROR; } - self->fThis->SetTexture(pyImage::ConvertFrom(imageObj)->GetImage()); + self->fThis->SetTexture(pyImage::ConvertFrom(imageObj)->GetKey()); PYTHON_RETURN_NONE; }