Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Alphalaneous committed Dec 28, 2024
1 parent 7230167 commit 94ed951
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## 1.8.5
- Cleanup filesystem code
- Fix a crash when there is an invalid path (hopefully)
- Fix an issue with CCSpriteWithHue. Do note that changing the wraith textures is still broken and has inconsistent behavior
- Fix an issue with CCSpriteWithHue

## 1.8.4
- Actually fix loading individual sprites from init
Expand Down
3 changes: 1 addition & 2 deletions src/UIModding.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ class UIModding {
std::map<std::string, std::string> randomSprites;
std::vector<std::filesystem::path> activePackCache;
std::unordered_map<std::string, bool> filenameCache;
std::unordered_map<std::string, bool> spritesChanged;
std::unordered_map<CCSpriteFrame*, std::string> frameToNameMap;
std::unordered_map<CCTexture2D*, std::string> textureToNameMap;

std::vector<FileWatcher*> listeners;
Ref<CCArray> removalQueue = CCArray::create();
Expand Down
10 changes: 6 additions & 4 deletions src/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,13 @@ namespace Utils {
}

static std::string getSpriteName(CCSpriteFrame* spriteFrame) {
if (UIModding::get()->frameToNameMap.contains(spriteFrame)) return UIModding::get()->frameToNameMap[spriteFrame];
if (UIModding::get()->textureToNameMap.contains(spriteFrame->getTexture())) {
return UIModding::get()->textureToNameMap[spriteFrame->getTexture()];
}

for (auto [key, frame] : CCDictionaryExt<std::string, CCSpriteFrame*>(CCSpriteFrameCache::sharedSpriteFrameCache()->m_pSpriteFrames)) {
if (spriteFrame == frame) {
UIModding::get()->frameToNameMap[spriteFrame] = key;
if (spriteFrame->getTexture() == frame->getTexture() && frame->getRect() == spriteFrame->getRect()) {
UIModding::get()->textureToNameMap[spriteFrame->getTexture()] = key;
return key;
}
}
Expand Down Expand Up @@ -241,7 +244,6 @@ namespace Utils {
if (entry.is_regular_file()) {
std::string pathStr = entry.path().string();
std::string subStr = pathStr.substr(packPath.string().size() + 1);
log::info("subStr: {}", subStr);
UIModding::get()->filenameCache[qualityToNormal(utils::string::replace(subStr, "\\", "/"))] = true;
}
}
Expand Down
10 changes: 4 additions & 6 deletions src/nodes/CCSprite.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class $modify(MyCCSpriteWithHue, CCSpriteWithHue) {
bool initWithSpriteFrame(cocos2d::CCSpriteFrame* p0) {
std::string frameName = Utils::getSpriteName(p0);

if (Utils::spriteExistsInPacks(frameName) && !UIModding::get()->spritesChanged[frameName]) {
if (Utils::spriteExistsInPacks(frameName)) {
CCSprite* spr = CCSprite::create(frameName.c_str());
auto spriteFrame = CCSpriteFrame::createWithTexture(spr->getTexture(), spr->getTextureRect());
CCSpriteFrameCache::get()->addSpriteFrame(spriteFrame, frameName.c_str());
UIModding::get()->spritesChanged[frameName] = true;
return CCSpriteWithHue::initWithSpriteFrame(spriteFrame);
}

return CCSpriteWithHue::initWithSpriteFrame(p0);
Expand All @@ -33,23 +33,21 @@ class $modify(MyCCSprite, CCSprite) {
}

bool initWithSpriteFrameName(const char *pszSpriteFrameName) {
if (Utils::spriteExistsInPacks(pszSpriteFrameName) && !UIModding::get()->spritesChanged[pszSpriteFrameName]) {
if (Utils::spriteExistsInPacks(pszSpriteFrameName)) {

CCSprite* spr = CCSprite::create(pszSpriteFrameName);
auto spriteFrame = CCSpriteFrame::createWithTexture(spr->getTexture(), spr->getTextureRect());
CCSpriteFrameCache::get()->addSpriteFrame(spriteFrame, pszSpriteFrameName);
UIModding::get()->spritesChanged[pszSpriteFrameName] = true;
}
return CCSprite::initWithSpriteFrameName(pszSpriteFrameName);
}

static CCSprite* createWithSpriteFrameName(const char *pszSpriteFrameName) {
if (Utils::spriteExistsInPacks(pszSpriteFrameName) && !UIModding::get()->spritesChanged[pszSpriteFrameName]) {
if (Utils::spriteExistsInPacks(pszSpriteFrameName)) {

CCSprite* spr = CCSprite::create(pszSpriteFrameName);
auto spriteFrame = CCSpriteFrame::createWithTexture(spr->getTexture(), spr->getTextureRect());
CCSpriteFrameCache::get()->addSpriteFrame(spriteFrame, pszSpriteFrameName);
UIModding::get()->spritesChanged[pszSpriteFrameName] = true;
}

return CCSprite::createWithSpriteFrameName(pszSpriteFrameName);
Expand Down
3 changes: 1 addition & 2 deletions src/nodes/LoadingLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ class $modify(MyLoadingLayer, LoadingLayer) {
UIModding::get()->finishedLoad = false;
UIModding::get()->uiCache.clear();
UIModding::get()->colorCache.clear();
UIModding::get()->spritesChanged.clear();
UIModding::get()->frameToNameMap.clear();
UIModding::get()->textureToNameMap.clear();

queueInMainThread([] {
Utils::clearActivePackCache();
Expand Down

0 comments on commit 94ed951

Please sign in to comment.