@@ -21,65 +21,116 @@ bool SwelvyBG::init(float widthmult, float hightmult, float minspeed, float maxs
2121 float y = m_obContentSize.height + 5 ;
2222 int idx = 0 ;
2323
24- // Retrieve the color offset setting
25- auto mod = Mod::get ();
26- ccColor3B colorOffset = { 0 , 0 , 0 }; // Default offset is zero (no adjustment)
27- bool enableColor = false ;
28-
29- if (mod) {
30- enableColor = mod->getSettingValue <bool >(" enable-color" );
31- if (enableColor) {
32- auto colorSetting = mod->getSettingValue <std::string>(" color" );
33- if (!colorSetting.empty ()) {
34- sscanf_s (colorSetting.c_str (), " %hhu,%hhu,%hhu" , &colorOffset.r , &colorOffset.g , &colorOffset.b );
24+ bool enableColor = Mod::get ()->getSettingValue <bool >(" enable-color" );
25+
26+ if (enableColor) {
27+ for (auto layer : std::initializer_list<std::pair<ccColor3B, const char *>> {
28+ { Mod::get ()->getSettingValue <cocos2d::ccColor3B>(" color-0" ), " geode.loader/swelve-layer3.png" },
29+ { Mod::get ()->getSettingValue <cocos2d::ccColor3B>(" color-1" ), " geode.loader/swelve-layer0.png" },
30+ { Mod::get ()->getSettingValue <cocos2d::ccColor3B>(" color-2" ), " geode.loader/swelve-layer1.png" },
31+ { Mod::get ()->getSettingValue <cocos2d::ccColor3B>(" color-3" ), " geode.loader/swelve-layer2.png" },
32+ { Mod::get ()->getSettingValue <cocos2d::ccColor3B>(" color-4" ), " geode.loader/swelve-layer1.png" },
33+ { Mod::get ()->getSettingValue <cocos2d::ccColor3B>(" color-5" ), " geode.loader/swelve-layer0.png" },
34+ }) {
35+ ccColor3B adjustedColor = layer.first ;
36+
37+ if (enableColor) {
38+ // Construct the setting key dynamically
39+ std::string settingKey = " color-" + std::to_string (idx);
40+ auto colorSetting = Mod::get ()->getSettingValue <std::string>(settingKey);
41+
42+ if (!colorSetting.empty ()) {
43+ unsigned int r, g, b;
44+ if (sscanf_s (colorSetting.c_str (), " %u,%u,%u" , &r, &g, &b) == 3 ) {
45+ adjustedColor = {
46+ static_cast <GLubyte>(std::min (255u , r)),
47+ static_cast <GLubyte>(std::min (255u , g)),
48+ static_cast <GLubyte>(std::min (255u , b))
49+ };
50+ }
51+ }
3552 }
36- }
37- }
3853
39- for (auto layer : std::initializer_list<std::pair<ccColor3B, const char *>> {
40- { ccc3 (244 , 212 , 142 ), " geode.loader/swelve-layer3.png" },
41- { ccc3 (245 , 174 , 125 ), " geode.loader/swelve-layer0.png" },
42- { ccc3 (236 , 137 , 124 ), " geode.loader/swelve-layer1.png" },
43- { ccc3 (213 , 105 , 133 ), " geode.loader/swelve-layer2.png" },
44- { ccc3 (173 , 84 , 146 ), " geode.loader/swelve-layer1.png" },
45- { ccc3 (113 , 74 , 154 ), " geode.loader/swelve-layer0.png" },
46- }) {
47- ccColor3B adjustedColor = layer.first ;
48-
49- if (enableColor) {
50- // Apply the color offset
51- adjustedColor = {
52- static_cast <GLubyte>(std::min (255 , layer.first .r + colorOffset.r )),
53- static_cast <GLubyte>(std::min (255 , layer.first .g + colorOffset.g )),
54- static_cast <GLubyte>(std::min (255 , layer.first .b + colorOffset.b ))
55- };
54+ float speed = dis (gen);
55+ if (sign (gen) == 0 ) {
56+ speed = -speed;
57+ }
58+ ccTexParams params = {GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_CLAMP_TO_EDGE};
59+
60+ auto sprite = CCSprite::create (layer.second );
61+ auto rect = sprite->getTextureRect ();
62+ sprite->setUserObject (" width" , CCFloat::create (rect.size .width * widthmult));
63+ rect.size = CCSize{winSize.width * widthmult, rect.size .height * hightmult};
64+
65+ std::string layerID = fmt::format (" layer-{}" , idx);
66+ sprite->setID (layerID);
67+ sprite->getTexture ()->setTexParameters (¶ms);
68+ sprite->setTextureRect (rect);
69+ sprite->setAnchorPoint ({ 0 , 1 });
70+ sprite->setContentSize ({ winSize.width * widthmult, sprite->getContentSize ().height });
71+ sprite->setColor (adjustedColor);
72+ sprite->setPosition ({ 0 , y });
73+ sprite->schedule (schedule_selector (SwelvyBG::updateSpritePosition));
74+ sprite->setUserObject (" speed" , CCFloat::create (speed));
75+ this ->addChild (sprite);
76+
77+ y -= m_obContentSize.height / 6 ;
78+ idx += 1 ;
5679 }
80+ } else {
81+ for (auto layer : std::initializer_list<std::pair<ccColor3B, const char *>> {
82+ { ccc3 (244 , 212 , 142 ), " geode.loader/swelve-layer3.png" },
83+ { ccc3 (245 , 174 , 125 ), " geode.loader/swelve-layer0.png" },
84+ { ccc3 (236 , 137 , 124 ), " geode.loader/swelve-layer1.png" },
85+ { ccc3 (213 , 105 , 133 ), " geode.loader/swelve-layer2.png" },
86+ { ccc3 (173 , 84 , 146 ), " geode.loader/swelve-layer1.png" },
87+ { ccc3 (113 , 74 , 154 ), " geode.loader/swelve-layer0.png" },
88+ }) {
89+ ccColor3B adjustedColor = layer.first ;
90+
91+ if (enableColor) {
92+ // Construct the setting key dynamically
93+ std::string settingKey = " color-" + std::to_string (idx);
94+ auto colorSetting = Mod::get ()->getSettingValue <std::string>(settingKey);
95+
96+ if (!colorSetting.empty ()) {
97+ unsigned int r, g, b;
98+ if (sscanf_s (colorSetting.c_str (), " %u,%u,%u" , &r, &g, &b) == 3 ) {
99+ adjustedColor = {
100+ static_cast <GLubyte>(std::min (255u , r)),
101+ static_cast <GLubyte>(std::min (255u , g)),
102+ static_cast <GLubyte>(std::min (255u , b))
103+ };
104+ }
105+ }
106+ }
57107
58- float speed = dis (gen);
59- if (sign (gen) == 0 ) {
60- speed = -speed;
108+ float speed = dis (gen);
109+ if (sign (gen) == 0 ) {
110+ speed = -speed;
111+ }
112+ ccTexParams params = {GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_CLAMP_TO_EDGE};
113+
114+ auto sprite = CCSprite::create (layer.second );
115+ auto rect = sprite->getTextureRect ();
116+ sprite->setUserObject (" width" , CCFloat::create (rect.size .width * widthmult));
117+ rect.size = CCSize{winSize.width * widthmult, rect.size .height * hightmult};
118+
119+ std::string layerID = fmt::format (" layer-{}" , idx);
120+ sprite->setID (layerID);
121+ sprite->getTexture ()->setTexParameters (¶ms);
122+ sprite->setTextureRect (rect);
123+ sprite->setAnchorPoint ({ 0 , 1 });
124+ sprite->setContentSize ({ winSize.width * widthmult, sprite->getContentSize ().height });
125+ sprite->setColor (adjustedColor);
126+ sprite->setPosition ({ 0 , y });
127+ sprite->schedule (schedule_selector (SwelvyBG::updateSpritePosition));
128+ sprite->setUserObject (" speed" , CCFloat::create (speed));
129+ this ->addChild (sprite);
130+
131+ y -= m_obContentSize.height / 6 ;
132+ idx += 1 ;
61133 }
62- ccTexParams params = {GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_CLAMP_TO_EDGE};
63-
64- auto sprite = CCSprite::create (layer.second );
65- auto rect = sprite->getTextureRect ();
66- sprite->setUserObject (" width" , CCFloat::create (rect.size .width * widthmult));
67- rect.size = CCSize{winSize.width * widthmult, rect.size .height * hightmult};
68-
69- std::string layerID = fmt::format (" layer-{}" , idx);
70- sprite->setID (layerID);
71- sprite->getTexture ()->setTexParameters (¶ms);
72- sprite->setTextureRect (rect);
73- sprite->setAnchorPoint ({ 0 , 1 });
74- sprite->setContentSize ({ winSize.width * widthmult, sprite->getContentSize ().height });
75- sprite->setColor (adjustedColor);
76- sprite->setPosition ({ 0 , y });
77- sprite->schedule (schedule_selector (SwelvyBG::updateSpritePosition));
78- sprite->setUserObject (" speed" , CCFloat::create (speed));
79- this ->addChild (sprite);
80-
81- y -= m_obContentSize.height / 6 ;
82- idx += 1 ;
83134 }
84135
85136 return true ;
@@ -109,4 +160,4 @@ SwelvyBG* SwelvyBG::create(float widthmult, float hightmult, float minspeed, flo
109160 }
110161 delete ret;
111162 return nullptr ;
112- }
163+ }
0 commit comments