|
1 | 1 | #pragma once |
2 | 2 |
|
3 | 3 | #include <Geode/Geode.hpp> |
4 | | -#include <Geode/modify/CCSprite.hpp> |
5 | | -#include <Geode/modify/CCSpriteWithHue.hpp> |
6 | | -#include "../Macros.h" |
7 | | - |
8 | | -class $modify(MyCCSpriteWithHue, CCSpriteWithHue) { |
9 | | - |
10 | | - static void onModify(auto& self) { |
11 | | - (void) self.setHookPriority("cocos2d::CCSpriteWithHue::initWithSpriteFrame", Priority::VeryEarly); |
12 | | - } |
13 | | - |
14 | | - bool initWithSpriteFrame(cocos2d::CCSpriteFrame* p0) { |
15 | | - std::string frameName = Utils::getSpriteName(p0); |
16 | | - |
17 | | - if (Utils::spriteExistsInPacks(frameName)) { |
18 | | - CCSprite* spr = CCSprite::create(frameName.c_str()); |
19 | | - auto spriteFrame = CCSpriteFrame::createWithTexture(spr->getTexture(), spr->getTextureRect()); |
20 | | - CCSpriteFrameCache::get()->addSpriteFrame(spriteFrame, frameName.c_str()); |
21 | | - return CCSpriteWithHue::initWithSpriteFrame(spriteFrame); |
| 4 | +#include <Geode/modify/CCSpriteFrameCache.hpp> |
| 5 | + |
| 6 | +class $modify(MyCCSpriteFrameCache, CCSpriteFrameCache) { |
| 7 | + CCSpriteFrame* spriteFrameByName(const char *pszName) { |
| 8 | + |
| 9 | + if (Utils::spriteExistsInPacks(pszName)) { |
| 10 | + CCTexture2D* pTexture = CCTextureCache::get()->addImage(pszName, false); |
| 11 | + if (pTexture){ |
| 12 | + CCRect rect = CCRectZero; |
| 13 | + rect.size = pTexture->getContentSize(); |
| 14 | + return CCSpriteFrame::createWithTexture(pTexture, rect); |
| 15 | + } |
22 | 16 | } |
23 | | - |
24 | | - return CCSpriteWithHue::initWithSpriteFrame(p0); |
25 | | - } |
26 | | -}; |
27 | | - |
28 | | -class $modify(MyCCSprite, CCSprite) { |
29 | | - |
30 | | - static void onModify(auto& self) { |
31 | | - (void) self.setHookPriority("cocos2d::CCSprite::initWithSpriteFrameName", Priority::VeryEarly); |
32 | | - (void) self.setHookPriority("cocos2d::CCSprite::createWithSpriteFrameName", Priority::VeryEarly); |
33 | | - (void) self.setHookPriority("cocos2d::CCSprite::setDisplayFrame", Priority::VeryEarly); |
34 | | - } |
35 | | - |
36 | | - void setDisplayFrame(CCSpriteFrame *pNewFrame) { |
37 | | - std::string frameName = Utils::getSpriteName(pNewFrame); |
38 | | - if (Utils::spriteExistsInPacks(frameName)) { |
39 | | - CCSprite* spr = CCSprite::create(frameName.c_str()); |
40 | | - auto spriteFrame = CCSpriteFrame::createWithTexture(spr->getTexture(), spr->getTextureRect()); |
41 | | - CCSpriteFrameCache::get()->addSpriteFrame(spriteFrame, frameName.c_str()); |
42 | | - return CCSprite::setDisplayFrame(spriteFrame); |
43 | | - } |
44 | | - CCSprite::setDisplayFrame(pNewFrame); |
45 | | - } |
46 | | - |
47 | | - bool initWithSpriteFrameName(const char *pszSpriteFrameName) { |
48 | | - std::string copy = pszSpriteFrameName; |
49 | | - |
50 | | - if (Utils::spriteExistsInPacks(copy)) { |
51 | | - CCSprite* spr = CCSprite::create(copy.c_str()); |
52 | | - auto spriteFrame = CCSpriteFrame::createWithTexture(spr->getTexture(), spr->getTextureRect()); |
53 | | - CCSpriteFrameCache::get()->addSpriteFrame(spriteFrame, copy.c_str()); |
54 | | - } |
55 | | - |
56 | | - return CCSprite::initWithSpriteFrameName(copy.c_str()); |
57 | | - } |
58 | | - |
59 | | - static CCSprite* createWithSpriteFrameName(const char *pszSpriteFrameName) { |
60 | | - std::string copy = pszSpriteFrameName; |
61 | | - |
62 | | - if (Utils::spriteExistsInPacks(copy)) { |
63 | | - |
64 | | - CCSprite* spr = CCSprite::create(copy.c_str()); |
65 | | - auto spriteFrame = CCSpriteFrame::createWithTexture(spr->getTexture(), spr->getTextureRect()); |
66 | | - CCSpriteFrameCache::get()->addSpriteFrame(spriteFrame, copy.c_str()); |
67 | | - } |
68 | | - |
69 | | - return CCSprite::createWithSpriteFrameName(copy.c_str()); |
| 17 | + return CCSpriteFrameCache::spriteFrameByName(pszName); |
70 | 18 | } |
71 | 19 | }; |
0 commit comments