Skip to content

Commit

Permalink
After transition object and cache bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Alphalaneous committed Dec 30, 2024
1 parent 94ed951 commit 6f82e12
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 11 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 8 additions & 2 deletions src/UIModding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(), '/', '$');
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/UIModding.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class UIModding {
Ref<CCArray> removalQueue = CCArray::create();
bool doModify;
bool finishedLoad;
bool initialScene = true;

void recursiveModify(CCNode* node, matjson::Value elements);
void setVisible(CCNode* node, matjson::Value attributes);
Expand Down Expand Up @@ -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<std::filesystem::path> getActivePacks();
void startFileListeners();
Expand Down
7 changes: 5 additions & 2 deletions src/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::filesystem::path> getActivePacks() {
Expand Down Expand Up @@ -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)) {
Expand Down
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@
#include "nodes/CCNode.h"
#include "nodes/CCSprite.h"
#include "nodes/CCSpriteBatchNode.h"
#include "nodes/CCDirector.h"
#include "BackgroundColors.h"
20 changes: 20 additions & 0 deletions src/nodes/CCDirector.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include <Geode/Geode.hpp>
#include <Geode/modify/CCDirector.hpp>
#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<CCNode*>(scene->getChildren())) {
UIModding::get()->doUICheck(node, true);
}
}
};
9 changes: 5 additions & 4 deletions src/nodes/LoadingLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/nodes/MenuLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class $modify(MyMenuLayer, MenuLayer) {
if (Mod::get()->getSettingValue<bool>("hot-reload")) {
UIModding::get()->startFileListeners();
}
UIModding::get()->doUICheck(this);
UIModding::get()->doUICheck(this, UIModding::get()->initialScene);
UIModding::get()->initialScene = false;
}
return true;
}
Expand Down

0 comments on commit 6f82e12

Please sign in to comment.