11#include " SwelvyBG.hpp"
2+ #include " ccTypes.h"
23#include < Geode/loader/Mod.hpp>
34#include < random>
45
@@ -21,29 +22,24 @@ bool SwelvyBG::init(float widthmult, float hightmult, float minspeed, float maxs
2122 float y = m_obContentSize.height + 5 ;
2223 int idx = 0 ;
2324
24- bool enableColor = Mod::get ()->getSettingValue <bool >(" enable-color" );
25+ bool enableColor = Mod::get ()->getSettingValue <bool >(" color-enable" );
26+ log::debug (" Color feature enabled: {}" , enableColor);
2527
2628 auto createLayer = [&](ccColor3B color, const char * texturePath) {
2729 ccColor3B adjustedColor = color;
2830
29- if (enableColor) {
30- // Construct the setting key dynamically
31- std::string settingKey = " color-" + std::to_string (idx);
32- auto colorSetting = Mod::get ()->getSettingValue <std::string>(settingKey);
33-
34- if (!colorSetting.empty ()) {
35- auto res = cc3bFromHexString (colorSetting);
36- if (res.isOk ()) adjustedColor = res.unwrap ();
37- }
38- }
39-
4031 float speed = dis (gen);
4132 if (sign (gen) == 0 ) {
4233 speed = -speed;
4334 }
4435 ccTexParams params = {GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_CLAMP_TO_EDGE};
4536
4637 auto sprite = CCSprite::create (texturePath);
38+ if (!sprite) {
39+ log::debug (" Failed to load texture: {}" , texturePath);
40+ return ;
41+ }
42+
4743 auto rect = sprite->getTextureRect ();
4844 sprite->setUserObject (" width" , CCFloat::create (rect.size .width * widthmult));
4945 rect.size = CCSize{winSize.width * widthmult, rect.size .height * hightmult};
@@ -60,6 +56,8 @@ bool SwelvyBG::init(float widthmult, float hightmult, float minspeed, float maxs
6056 sprite->setUserObject (" speed" , CCFloat::create (speed));
6157 this ->addChild (sprite);
6258
59+ log::debug (" Created layer {} with color ({}, {}, {})" , layerID, adjustedColor.r , adjustedColor.g , adjustedColor.b );
60+
6361 y -= m_obContentSize.height / 6 ;
6462 idx += 1 ;
6563 };
@@ -76,6 +74,7 @@ bool SwelvyBG::init(float widthmult, float hightmult, float minspeed, float maxs
7674 createLayer (layer.first , layer.second );
7775 }
7876 } else {
77+ log::debug (" Color feature disabled. Using default colors." );
7978 for (auto layer : std::initializer_list<std::pair<ccColor3B, const char *>> {
8079 { ccc3 (244 , 212 , 142 ), " geode.loader/swelve-layer3.png" },
8180 { ccc3 (245 , 174 , 125 ), " geode.loader/swelve-layer0.png" },
@@ -92,19 +91,33 @@ bool SwelvyBG::init(float widthmult, float hightmult, float minspeed, float maxs
9291}
9392
9493void SwelvyBG::updateSpritePosition (float dt) {
95- auto speed = typeinfo_cast<CCFloat*>(this ->getUserObject (" speed" ))->getValue ();
96- auto width = typeinfo_cast<CCFloat*>(this ->getUserObject (" width" ))->getValue ();
94+ auto speedObj = typeinfo_cast<CCFloat*>(this ->getUserObject (" speed" ));
95+ auto widthObj = typeinfo_cast<CCFloat*>(this ->getUserObject (" width" ));
96+
97+ if (!speedObj || !widthObj) {
98+ log::debug (" Sprite missing required user objects: speed or width" );
99+ return ;
100+ }
101+
102+ float speed = speedObj->getValue ();
103+ float width = widthObj->getValue ();
97104
98105 auto sprite = typeinfo_cast<CCSprite*>(this );
99- auto rect = sprite->getTextureRect ();
106+ if (!sprite) {
107+ log::debug (" Failed to cast object to CCSprite in updateSpritePosition" );
108+ return ;
109+ }
100110
111+ auto rect = sprite->getTextureRect ();
101112 float dX = rect.origin .x - speed * dt;
102113 if (dX >= std::abs (width)) {
103114 dX = 0 ;
104115 }
105116
106117 rect.origin = CCPoint{ dX, 0 };
107118 sprite->setTextureRect (rect);
119+
120+ // log::debug("Updated sprite {} position: dX={}, speed={}, width={}", sprite->getID(), dX, speed, width);
108121}
109122
110123SwelvyBG* SwelvyBG::create (float widthmult, float hightmult, float minspeed, float maxspeed) {
@@ -114,5 +127,6 @@ SwelvyBG* SwelvyBG::create(float widthmult, float hightmult, float minspeed, flo
114127 return ret;
115128 }
116129 delete ret;
130+ log::debug (" Failed to create SwelvyBG instance" );
117131 return nullptr ;
118- }
132+ }
0 commit comments