Skip to content

Commit caa66ea

Browse files
authored
Update SwelvyBG.cpp
1 parent f72763c commit caa66ea

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

src/SwelvyBG.cpp

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ bool SwelvyBG::init(float widthmult, float hightmult, float minspeed, float maxs
77
return false;
88

99
this->setID("SwelvyBG");
10-
10+
1111
auto winSize = CCDirector::get()->getWinSize();
1212
this->setContentSize(winSize);
1313
this->setAnchorPoint({ 0.f, 0.f });
@@ -19,14 +19,19 @@ bool SwelvyBG::init(float widthmult, float hightmult, float minspeed, float maxs
1919

2020
float y = m_obContentSize.height + 5;
2121
int idx = 0;
22-
22+
2323
// Retrieve the color offset setting
2424
auto mod = Mod::get();
25-
ccColor3B colorOffset = {255, 0, 0}; // Default color offset
25+
ccColor3B colorOffset = { 0, 0, 0 }; // Default offset is zero (no adjustment)
26+
bool enableColor = false;
27+
2628
if (mod) {
27-
auto colorSetting = mod->getSettingValue<std::string>("color");
28-
if (!colorSetting.empty()) {
29-
sscanf(colorSetting.c_str(), "%hhu,%hhu,%hhu", &colorOffset.r, &colorOffset.g, &colorOffset.b);
29+
enableColor = mod->getSettingValue<bool>("enable-color");
30+
if (enableColor) {
31+
auto colorSetting = mod->getSettingValue<std::string>("color");
32+
if (!colorSetting.empty()) {
33+
sscanf(colorSetting.c_str(), "%hhu,%hhu,%hhu", &colorOffset.r, &colorOffset.g, &colorOffset.b);
34+
}
3035
}
3136
}
3237

@@ -37,14 +42,17 @@ bool SwelvyBG::init(float widthmult, float hightmult, float minspeed, float maxs
3742
{ ccc3(213, 105, 133), "geode.loader/swelve-layer2.png" },
3843
{ ccc3(173, 84, 146), "geode.loader/swelve-layer1.png" },
3944
{ ccc3(113, 74, 154), "geode.loader/swelve-layer0.png" },
40-
}) { if (Mod::get()->getSettingValue<bool>("enable-color")) {
41-
// Apply the color offset
42-
ccColor3B adjustedColor = {
43-
static_cast<GLubyte>(std::min(255, layer.first.r + colorOffset.r)),
44-
static_cast<GLubyte>(std::min(255, layer.first.g + colorOffset.g)),
45-
static_cast<GLubyte>(std::min(255, layer.first.b + colorOffset.b))
46-
}
47-
};
45+
}) {
46+
ccColor3B adjustedColor = layer.first;
47+
48+
if (enableColor) {
49+
// Apply the color offset
50+
adjustedColor = {
51+
static_cast<GLubyte>(std::min(255, layer.first.r + colorOffset.r)),
52+
static_cast<GLubyte>(std::min(255, layer.first.g + colorOffset.g)),
53+
static_cast<GLubyte>(std::min(255, layer.first.b + colorOffset.b))
54+
};
55+
}
4856

4957
float speed = dis(gen);
5058
if (sign(gen) == 0) {
@@ -62,17 +70,17 @@ bool SwelvyBG::init(float widthmult, float hightmult, float minspeed, float maxs
6270
sprite->getTexture()->setTexParameters(&params);
6371
sprite->setTextureRect(rect);
6472
sprite->setAnchorPoint({ 0, 1 });
65-
sprite->setContentSize({winSize.width * widthmult, sprite->getContentSize().height});
73+
sprite->setContentSize({ winSize.width * widthmult, sprite->getContentSize().height });
6674
sprite->setColor(adjustedColor);
67-
sprite->setPosition({0, y});
75+
sprite->setPosition({ 0, y });
6876
sprite->schedule(schedule_selector(SwelvyBG::updateSpritePosition));
6977
sprite->setUserObject("speed", CCFloat::create(speed));
7078
this->addChild(sprite);
7179

7280
y -= m_obContentSize.height / 6;
7381
idx += 1;
74-
7582
}
83+
7684
return true;
7785
}
7886

@@ -84,20 +92,20 @@ void SwelvyBG::updateSpritePosition(float dt) {
8492
auto rect = sprite->getTextureRect();
8593

8694
float dX = rect.origin.x - speed * dt;
87-
if(dX >= std::abs(width)) {
95+
if (dX >= std::abs(width)) {
8896
dX = 0;
8997
}
9098

91-
rect.origin = CCPoint{dX, 0};
99+
rect.origin = CCPoint{ dX, 0 };
92100
sprite->setTextureRect(rect);
93101
}
94102

95-
SwelvyBG* SwelvyBG::create(float widthmult, float m, float minspeed, float maxspeed) {
103+
SwelvyBG* SwelvyBG::create(float widthmult, float hightmult, float minspeed, float maxspeed) {
96104
auto ret = new SwelvyBG();
97-
if (ret->init(widthmult,m,minspeed,maxspeed)) {
105+
if (ret->init(widthmult, hightmult, minspeed, maxspeed)) {
98106
ret->autorelease();
99107
return ret;
100108
}
101109
delete ret;
102110
return nullptr;
103-
}
111+
}

0 commit comments

Comments
 (0)