Skip to content

Commit 6b4d95a

Browse files
committed
fix performance (maybe)
1 parent 51a56e6 commit 6b4d95a

File tree

3 files changed

+97
-98
lines changed

3 files changed

+97
-98
lines changed

changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# v1.2.19
2+
- Fix performance issues with the bg color (Thanks camila!)
13
# v1.2.18
24
- Added opacity scale for your child backgrounds
35
- Fixed bug that all backgrounds colours were changed (even without activating the feature)

mod.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"geode": "2.0.0",
3-
"version": "v1.2.18",
3+
"version": "v1.2.19",
44
"gd": {
55
"win": "2.204",
66
"android": "2.205"

src/main.cpp

Lines changed: 94 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -279,111 +279,108 @@ class $modify(CCScheduler) { // GD Protocol part
279279
// Backgrounds
280280
class $modify(CCSprite) {
281281
bool isGradient;
282-
bool initWithFile(char const* name) {
283-
if (!CCSprite::initWithFile(name)) return false;
284-
285-
if (!strcmp(name, "GJ_gradientBG.png")) {
286-
m_fields->isGradient = true;
287-
}
288-
return true;
289-
}
290-
void setColor(const ccColor3B& color) {
291-
CCSprite::setColor(color);
292-
auto scene = CCDirector::sharedDirector()->getRunningScene();
293-
if (scene->getChildrenCount() == 0) return;
294-
auto layer = scene->getChildren()->objectAtIndex(0);
295-
std::string layerName = misc::getNodeName(layer);
282+
static CCSprite* create(char const* name) {
283+
auto ret = CCSprite::create(name);
284+
if (ret == nullptr) return ret;
285+
// better code, thanks camila!
286+
if (!strcmp(name, "GJ_gradientBG.png") && Mod::get()->getSettingValue<bool>("activate-background")) {
287+
Loader::get()->queueInMainThread([=] {
288+
if (ret->getColor() == ccc3(0, 102, 255)) {
289+
auto scene = CCDirector::sharedDirector()->getRunningScene();
290+
if (scene->getChildrenCount() == 0) return;
291+
auto layer = scene->getChildren()->objectAtIndex(0);
292+
std::string layerName = misc::getNodeName(layer);
293+
ret->setColor(Mod::get()->getSettingValue<ccColor3B>("background"));
294+
}
295+
});
296296

297-
if (m_fields->isGradient && Mod::get()->getSettingValue<bool>("activate-background")) {
298-
if (color.r == 0 && color.g == 102 && color.b == 255) {
299-
CCSprite::setColor(Mod::get()->getSettingValue<ccColor3B>("background"));
300-
}
301297
}
298+
return ret;
302299
}
303300
};
304301

305302
// Child background
306303
class $modify(CCScale9Sprite) {
307-
bool isGradient;
308-
bool initWithFile(char const* name, CCRect rect) {
309-
if (!CCScale9Sprite::initWithFile(name, rect)) return false;
310-
311-
if (!strcmp(name, "square02b_001.png") || !strcmp(name, "square02b_small.png")) {
312-
if (Mod::get()->getSettingValue<bool>("activate-background")) {
313-
m_fields->isGradient = true;
314-
}
315-
}
316-
return true;
317-
}
318-
319-
void setColor(const ccColor3B& color) {
320-
CCScale9Sprite::setColor(color);
321-
if (m_fields->isGradient && (CCScale9Sprite::getColor().r == 0 && CCScale9Sprite::getColor().g == 56 && CCScale9Sprite::getColor().b == 141)) {
322-
ccColor3B new_color = Mod::get()->getSettingValue<ccColor3B>("child-background");
323-
if (Mod::get()->getSettingValue<bool>("syncBGcolor")) {
324-
new_color = Mod::get()->getSettingValue<ccColor3B>("background");
325-
}
326-
if (Mod::get()->getSettingValue<bool>("addChildBDGradient")) {
327-
new_color = cocos2d::ccColor3B(new_color.r * 0.79, new_color.g * 0.79, new_color.b * 0.79);
328-
}
329-
if (Mod::get()->getSettingValue<bool>("bgchild-transparency")) {
330-
int opacity = Mod::get()->getSettingValue<int64_t>("bgchild-transparency-scroll");
331-
CCScale9Sprite::setOpacity(opacity);
332-
}
333-
CCScale9Sprite::setColor(new_color);
334-
} else if (m_fields->isGradient && (CCScale9Sprite::getColor().r == 0 && CCScale9Sprite::getColor().g == 39 && CCScale9Sprite::getColor().b == 98)) {
335-
ccColor3B new_color = Mod::get()->getSettingValue<ccColor3B>("child-background");
336-
if (Mod::get()->getSettingValue<bool>("syncBGcolor")) {
337-
new_color = Mod::get()->getSettingValue<ccColor3B>("background");
338-
}
339-
if (Mod::get()->getSettingValue<bool>("addChildBDGradient")) {
340-
new_color = cocos2d::ccColor3B(new_color.r * 0.71, new_color.g * 0.71, new_color.b * 0.71);
341-
}
342-
if (Mod::get()->getSettingValue<bool>("bgchild-transparency")) {
343-
int opacity = Mod::get()->getSettingValue<int64_t>("bgchild-transparency-scroll");
344-
CCScale9Sprite::setOpacity(opacity);
345-
}
346-
CCScale9Sprite::setColor(new_color);
347-
} else if (m_fields->isGradient && (CCScale9Sprite::getColor().r == 0 && CCScale9Sprite::getColor().g == 46 && CCScale9Sprite::getColor().b == 117)) {
348-
ccColor3B new_color = Mod::get()->getSettingValue<ccColor3B>("child-background");
349-
if (Mod::get()->getSettingValue<bool>("syncBGcolor")) {
350-
new_color = Mod::get()->getSettingValue<ccColor3B>("background");
351-
}
352-
if (Mod::get()->getSettingValue<bool>("addChildBDGradient")) {
353-
new_color = cocos2d::ccColor3B(new_color.r * 0.74, new_color.g * 0.74, new_color.b * 0.74);
354-
}
355-
if (Mod::get()->getSettingValue<bool>("bgchild-transparency")) {
356-
int opacity = Mod::get()->getSettingValue<int64_t>("bgchild-transparency-scroll");
357-
CCScale9Sprite::setOpacity(opacity);
358-
}
359-
CCScale9Sprite::setColor(new_color);
360-
} else if (m_fields->isGradient && (CCScale9Sprite::getColor().r == 0 && CCScale9Sprite::getColor().g == 36 && CCScale9Sprite::getColor().b == 91)) {
361-
ccColor3B new_color = Mod::get()->getSettingValue<ccColor3B>("child-background");
362-
if (Mod::get()->getSettingValue<bool>("syncBGcolor")) {
363-
new_color = Mod::get()->getSettingValue<ccColor3B>("background");
364-
}
365-
if (Mod::get()->getSettingValue<bool>("addChildBDGradient")) {
366-
new_color = cocos2d::ccColor3B(new_color.r * 0.70, new_color.g * 0.70, new_color.b * 0.70);
367-
}
368-
if (Mod::get()->getSettingValue<bool>("bgchild-transparency")) {
369-
int opacity = Mod::get()->getSettingValue<int64_t>("bgchild-transparency-scroll");
370-
CCScale9Sprite::setOpacity(opacity);
371-
}
372-
CCScale9Sprite::setColor(new_color);
373-
} else if (m_fields->isGradient && (CCScale9Sprite::getColor().r == 0 && CCScale9Sprite::getColor().g == 31 && CCScale9Sprite::getColor().b == 79)) {
374-
ccColor3B new_color = Mod::get()->getSettingValue<ccColor3B>("child-background");
375-
if (Mod::get()->getSettingValue<bool>("syncBGcolor")) {
376-
new_color = Mod::get()->getSettingValue<ccColor3B>("background");
377-
}
378-
if (Mod::get()->getSettingValue<bool>("addChildBDGradient")) {
379-
new_color = cocos2d::ccColor3B(new_color.r * 0.67, new_color.g * 0.67, new_color.b * 0.67);
380-
}
381-
if (Mod::get()->getSettingValue<bool>("bgchild-transparency")) {
382-
int opacity = Mod::get()->getSettingValue<int64_t>("bgchild-transparency-scroll");
383-
CCScale9Sprite::setOpacity(opacity);
384-
}
385-
CCScale9Sprite::setColor(new_color);
304+
/*
305+
cocos2d::extension::CCScale9Sprite::create
306+
("square02b_001.png",(CCRect)(CCSize *)&local_44);
307+
*/
308+
static cocos2d::extension::CCScale9Sprite* create(char const* name, CCRect rect) {
309+
auto ret = cocos2d::extension::CCScale9Sprite::create(name, rect);
310+
if (ret == nullptr) return ret;
311+
// better code, thanks camila!
312+
if ((!strcmp(name, "square02b_001.png") || !strcmp(name, "square02b_small.png")) && Mod::get()->getSettingValue<bool>("activate-background")) {
313+
Loader::get()->queueInMainThread([=] {
314+
// jouca waht
315+
if (ret->getColor() == ccc3(0, 56, 141)) {
316+
ccColor3B new_color = Mod::get()->getSettingValue<ccColor3B>("child-background");
317+
if (Mod::get()->getSettingValue<bool>("syncBGcolor")) {
318+
new_color = Mod::get()->getSettingValue<ccColor3B>("background");
319+
}
320+
if (Mod::get()->getSettingValue<bool>("addChildBDGradient")) {
321+
new_color = cocos2d::ccColor3B(new_color.r * 0.79, new_color.g * 0.79, new_color.b * 0.79);
322+
}
323+
if (Mod::get()->getSettingValue<bool>("bgchild-transparency")) {
324+
int opacity = Mod::get()->getSettingValue<int64_t>("bgchild-transparency-scroll");
325+
ret->setOpacity(opacity);
326+
}
327+
ret->setColor(new_color);
328+
} else if (ret->getColor() == ccc3(0, 39, 98)) {
329+
ccColor3B new_color = Mod::get()->getSettingValue<ccColor3B>("child-background");
330+
if (Mod::get()->getSettingValue<bool>("syncBGcolor")) {
331+
new_color = Mod::get()->getSettingValue<ccColor3B>("background");
332+
}
333+
if (Mod::get()->getSettingValue<bool>("addChildBDGradient")) {
334+
new_color = cocos2d::ccColor3B(new_color.r * 0.71, new_color.g * 0.71, new_color.b * 0.71);
335+
}
336+
if (Mod::get()->getSettingValue<bool>("bgchild-transparency")) {
337+
int opacity = Mod::get()->getSettingValue<int64_t>("bgchild-transparency-scroll");
338+
ret->setOpacity(opacity);
339+
}
340+
ret->setColor(new_color);
341+
} else if (ret->getColor() == ccc3(0, 46, 117)) {
342+
ccColor3B new_color = Mod::get()->getSettingValue<ccColor3B>("child-background");
343+
if (Mod::get()->getSettingValue<bool>("syncBGcolor")) {
344+
new_color = Mod::get()->getSettingValue<ccColor3B>("background");
345+
}
346+
if (Mod::get()->getSettingValue<bool>("addChildBDGradient")) {
347+
new_color = cocos2d::ccColor3B(new_color.r * 0.74, new_color.g * 0.74, new_color.b * 0.74);
348+
}
349+
if (Mod::get()->getSettingValue<bool>("bgchild-transparency")) {
350+
int opacity = Mod::get()->getSettingValue<int64_t>("bgchild-transparency-scroll");
351+
ret->setOpacity(opacity);
352+
}
353+
ret->setColor(new_color);
354+
} else if (ret->getColor() == ccc3(0, 36, 91)) {
355+
ccColor3B new_color = Mod::get()->getSettingValue<ccColor3B>("child-background");
356+
if (Mod::get()->getSettingValue<bool>("syncBGcolor")) {
357+
new_color = Mod::get()->getSettingValue<ccColor3B>("background");
358+
}
359+
if (Mod::get()->getSettingValue<bool>("addChildBDGradient")) {
360+
new_color = cocos2d::ccColor3B(new_color.r * 0.70, new_color.g * 0.70, new_color.b * 0.70);
361+
}
362+
if (Mod::get()->getSettingValue<bool>("bgchild-transparency")) {
363+
int opacity = Mod::get()->getSettingValue<int64_t>("bgchild-transparency-scroll");
364+
ret->setOpacity(opacity);
365+
}
366+
ret->setColor(new_color);
367+
} else if (ret->getColor() == ccc3(0, 31, 79)) {
368+
ccColor3B new_color = Mod::get()->getSettingValue<ccColor3B>("child-background");
369+
if (Mod::get()->getSettingValue<bool>("syncBGcolor")) {
370+
new_color = Mod::get()->getSettingValue<ccColor3B>("background");
371+
}
372+
if (Mod::get()->getSettingValue<bool>("addChildBDGradient")) {
373+
new_color = cocos2d::ccColor3B(new_color.r * 0.67, new_color.g * 0.67, new_color.b * 0.67);
374+
}
375+
if (Mod::get()->getSettingValue<bool>("bgchild-transparency")) {
376+
int opacity = Mod::get()->getSettingValue<int64_t>("bgchild-transparency-scroll");
377+
ret->setOpacity(opacity);
378+
}
379+
ret->setColor(new_color);
380+
}
381+
});
386382
}
383+
return ret;
387384
}
388385
};
389386

0 commit comments

Comments
 (0)