From 6f82e1265546753ff80995a88647a25030b42f99 Mon Sep 17 00:00:00 2001 From: Alphalaneous <38200084+Alphalaneous@users.noreply.github.com> Date: Sun, 29 Dec 2024 21:17:37 -0500 Subject: [PATCH] After transition object and cache bugfix --- changelog.md | 4 ++++ mod.json | 2 +- src/UIModding.cpp | 10 ++++++++-- src/UIModding.h | 3 ++- src/Utils.h | 7 +++++-- src/main.cpp | 1 + src/nodes/CCDirector.h | 20 ++++++++++++++++++++ src/nodes/LoadingLayer.h | 9 +++++---- src/nodes/MenuLayer.h | 3 ++- 9 files changed, 48 insertions(+), 11 deletions(-) create mode 100644 src/nodes/CCDirector.h diff --git a/changelog.md b/changelog.md index f11487a..737bfda 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,7 @@ +## 1.8.6 +- Added "after-transition" object for layers in a scene, allowing for you to only make changes after the transition finishes (see wiki for more details) +- Fixed cache failing to be reset, resulting in missing textures when a pack is unapplied + ## 1.8.5 - Cleanup filesystem code - Fix a crash when there is an invalid path (hopefully) diff --git a/mod.json b/mod.json index 69cf920..68e9ef0 100644 --- a/mod.json +++ b/mod.json @@ -5,7 +5,7 @@ "android": "2.2074", "mac": "2.2074" }, - "version": "v1.8.5", + "version": "v1.8.6", "id": "alphalaneous.happy_textures", "name": "Happy Textures :3", "developer": "Alphalaneous", diff --git a/src/UIModding.cpp b/src/UIModding.cpp index 44626f3..79a69df 100644 --- a/src/UIModding.cpp +++ b/src/UIModding.cpp @@ -1524,7 +1524,7 @@ void UIModding::handleModifications(CCNode* node, matjson::Value nodeObject) { } } -void UIModding::doUICheck(CCNode* node) { +void UIModding::doUICheck(CCNode* node, bool afterTransition) { std::string nodeID = node->getID(); std::replace(nodeID.begin(), nodeID.end(), '/', '$'); @@ -1552,8 +1552,14 @@ void UIModding::doUICheck(CCNode* node) { name = fullPath.parent_path().parent_path().parent_path().filename().string(); name = utils::string::toLower(name); } - std::replace( name.begin(), name.end(), ' ', '-'); + std::replace(name.begin(), name.end(), ' ', '-'); + if (afterTransition) { + if (expandedValue.contains("after-transition") && expandedValue["after-transition"].isObject()) { + expandedValue = expandedValue["after-transition"]; + } + } + expandedValue["_pack-name"] = name.substr(0, name.find_last_of("."));; handleModifications(node, expandedValue); diff --git a/src/UIModding.h b/src/UIModding.h index 7c2b4d5..7f1f259 100644 --- a/src/UIModding.h +++ b/src/UIModding.h @@ -27,6 +27,7 @@ class UIModding { Ref removalQueue = CCArray::create(); bool doModify; bool finishedLoad; + bool initialScene = true; void recursiveModify(CCNode* node, matjson::Value elements); void setVisible(CCNode* node, matjson::Value attributes); @@ -65,7 +66,7 @@ class UIModding { unsigned int stringToBlendingMode(std::string value); void handleModifications(CCNode* node, matjson::Value nodeObject); void loadNodeFiles(); - void doUICheck(CCNode* node); + void doUICheck(CCNode* node, bool afterTransition = false); void doUICheckForType(std::string name, CCNode* node); std::vector getActivePacks(); void startFileListeners(); diff --git a/src/Utils.h b/src/Utils.h index 9432a23..594e098 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -186,8 +186,12 @@ namespace Utils { return dist(gen); } - static void clearActivePackCache() { + static void clearCaches() { UIModding::get()->activePackCache.clear(); + UIModding::get()->uiCache.clear(); + UIModding::get()->colorCache.clear(); + UIModding::get()->filenameCache.clear(); + UIModding::get()->textureToNameMap.clear(); } static std::vector getActivePacks() { @@ -237,7 +241,6 @@ namespace Utils { } static void reloadFileNames() { - UIModding::get()->filenameCache.clear(); for (std::filesystem::path packPath : Utils::getActivePacks()) { if (!std::filesystem::is_directory(packPath)) continue; for (const auto& entry : std::filesystem::recursive_directory_iterator(packPath)) { diff --git a/src/main.cpp b/src/main.cpp index 704b3d4..771938c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,4 +26,5 @@ #include "nodes/CCNode.h" #include "nodes/CCSprite.h" #include "nodes/CCSpriteBatchNode.h" +#include "nodes/CCDirector.h" #include "BackgroundColors.h" \ No newline at end of file diff --git a/src/nodes/CCDirector.h b/src/nodes/CCDirector.h new file mode 100644 index 0000000..5bbc1aa --- /dev/null +++ b/src/nodes/CCDirector.h @@ -0,0 +1,20 @@ +#pragma once + +#include +#include +#include "../UIModding.h" +#include "../Utils.h" +#include "../Macros.h" + +using namespace geode::prelude; + +class $modify(MyCCDirector, CCDirector) { + + void willSwitchToScene(CCScene* scene) { + CCDirector::willSwitchToScene(scene); + + for (CCNode* node : CCArrayExt(scene->getChildren())) { + UIModding::get()->doUICheck(node, true); + } + } +}; diff --git a/src/nodes/LoadingLayer.h b/src/nodes/LoadingLayer.h index 479eb69..8831b98 100644 --- a/src/nodes/LoadingLayer.h +++ b/src/nodes/LoadingLayer.h @@ -9,6 +9,11 @@ using namespace geode::prelude; class $modify(MyLoadingLayer, LoadingLayer) { + bool init(bool p0) { + Utils::clearCaches(); + return LoadingLayer::init(p0); + } + void loadAssets() { if (m_loadStep > 0) { @@ -17,12 +22,8 @@ class $modify(MyLoadingLayer, LoadingLayer) { } UIModding::get()->finishedLoad = false; - UIModding::get()->uiCache.clear(); - UIModding::get()->colorCache.clear(); - UIModding::get()->textureToNameMap.clear(); queueInMainThread([] { - Utils::clearActivePackCache(); Utils::reloadFileNames(); UIModding::get()->loadNodeFiles(); Config::get()->loadPackJsons(); diff --git a/src/nodes/MenuLayer.h b/src/nodes/MenuLayer.h index 6632f6d..d26acb9 100644 --- a/src/nodes/MenuLayer.h +++ b/src/nodes/MenuLayer.h @@ -55,7 +55,8 @@ class $modify(MyMenuLayer, MenuLayer) { if (Mod::get()->getSettingValue("hot-reload")) { UIModding::get()->startFileListeners(); } - UIModding::get()->doUICheck(this); + UIModding::get()->doUICheck(this, UIModding::get()->initialScene); + UIModding::get()->initialScene = false; } return true; }