Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alphalaneous committed Dec 26, 2024
1 parent fee2b75 commit b9a7d48
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/UIModding.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class UIModding {
std::map<std::string, matjson::Value> uiCache;
std::map<std::string, ColorData> colorCache;
std::map<std::string, std::string> randomSprites;
std::vector<std::string> activePackCache;
std::unordered_map<std::string, bool> filenameCache;

std::vector<FileWatcher*> listeners;
Ref<CCArray> removalQueue = CCArray::create();
Expand Down
28 changes: 12 additions & 16 deletions src/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,13 @@ namespace Utils {
return dist(gen);
}

static std::vector<std::string> activePackCache;
static std::unordered_map<std::string, bool> filenameCache;

static void clearActivePackCache() {
activePackCache.clear();
UIModding::get()->activePackCache.clear();
}

static std::vector<std::string> getActivePacks() {
return activePackCache;

/*if (!activePackCache.empty()) return activePackCache;
if (!UIModding::get()->activePackCache.empty()) return UIModding::get()->activePackCache;

Mod* textureLoader = Loader::get()->getLoadedMod("geode.texture-loader");
if (textureLoader) {
Expand All @@ -194,36 +190,36 @@ namespace Utils {
std::filesystem::path pathFs{path};
path = (textureLoader->getSaveDir() / "unzipped" / pathFs.filename()).string();
}
activePackCache.push_back(path + "/");
UIModding::get()->activePackCache.push_back(path + "/");
}
}
}

#ifdef GEODE_IS_ANDROID
std::string resourcesDir = fmt::format("{}{}", CCFileUtils::sharedFileUtils()->getAndroidPath(), "\\Resources\\");
std::string resourcesDir = fmt::format("{}{}", CCFileUtils::sharedFileUtils()->getAndroidPath(), "/Resources/");
#else
std::string resourcesDir = fmt::format("{}{}", CCFileUtils::sharedFileUtils()->getWritablePath2(), "\\Resources\\");
std::string resourcesDir = fmt::format("{}{}", CCFileUtils::sharedFileUtils()->getWritablePath2(), "/Resources/");
#endif
activePackCache.push_back(resourcesDir);
UIModding::get()->activePackCache.push_back(resourcesDir);

return activePackCache;*/
return UIModding::get()->activePackCache;
}

static void reloadFileNames() {
filenameCache.clear();
UIModding::get()->filenameCache.clear();
for (std::string packPath : Utils::getActivePacks()) {
for (const auto& entry : std::filesystem::recursive_directory_iterator(packPath)) {
/*if (entry.is_regular_file()) {
if (entry.is_regular_file()) {
std::string pathStr = entry.path().string();
std::string subStr = pathStr.substr(packPath.size());
filenameCache[utils::string::replace(subStr, "\\", "/")] = true;
}*/
UIModding::get()->filenameCache[utils::string::replace(subStr, "\\", "/")] = true;
}
}
}
}

static bool spriteExistsInPacks(std::string fileName) {
return filenameCache[fileName];
return UIModding::get()->filenameCache[fileName];
}

static CCNode* getChildByTypeName(CCNode* node, int index, std::string name) {
Expand Down

0 comments on commit b9a7d48

Please sign in to comment.