Skip to content

Commit 82983b0

Browse files
committed
RLDifficultyNode refactor and stuff
1 parent 2b7751e commit 82983b0

File tree

8 files changed

+203
-119
lines changed

8 files changed

+203
-119
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010
### Added
1111

1212
- `#include` directives to the `/custom_layers`
13+
- Platform name to `RLRouletteInfoLayer`
14+
- `RLDifficultyNode` supports epic, legendary and mythic now
15+
- `rl::utils::getFeatureStateFromResponse`
1316

1417
### Changed
1518

@@ -25,6 +28,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2528

2629
- Empty list id crash on Android (probably)
2730
- Show options sprite being set even if the info icon was never clicked
31+
- `RLDifficultyNode::setColor` being weird
32+
- Difficulty not being highlighted when changing the list multiple times
2833

2934
## [2.0.1] - 2024-03-03
3035

Lines changed: 83 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#include "RLDifficultyNode.hpp"
22
#include "../utils.hpp"
33

4-
RLDifficultyNode* RLDifficultyNode::create(GJDifficulty difficulty, bool featured, bool epic)
4+
RLDifficultyNode* RLDifficultyNode::create(const DifficultyInfo& di)
55
{
6-
auto ret = new RLDifficultyNode();
6+
auto* ret = new RLDifficultyNode();
77

8-
if (ret && ret->init(difficulty, featured, epic))
8+
if (ret && ret->init(di))
99
ret->autorelease();
1010
else
1111
{
@@ -16,15 +16,33 @@ RLDifficultyNode* RLDifficultyNode::create(GJDifficulty difficulty, bool feature
1616
return ret;
1717
}
1818

19-
bool RLDifficultyNode::init(GJDifficulty difficulty, bool featured, bool epic)
19+
RLDifficultyNode* RLDifficultyNode::create(GJDifficulty difficulty)
20+
{
21+
auto* ret = new RLDifficultyNode();
22+
23+
if (ret && ret->init({ difficulty, RL_FEATURE_STATE::NONE }))
24+
ret->autorelease();
25+
else
26+
{
27+
delete ret;
28+
ret = nullptr;
29+
}
30+
31+
return ret;
32+
}
33+
34+
bool RLDifficultyNode::init(const DifficultyInfo& di)
2035
{
2136
if (!CCNodeRGBA::init()) return false;
37+
38+
m_difficulty_info = di;
39+
40+
this->setCascadeColorEnabled(true);
41+
this->setCascadeOpacityEnabled(true);
2242

23-
m_difficulty_info = { difficulty, featured, epic };
24-
m_color = { 255, 255, 255 };
2543

2644
m_difficulty_sprite = CCSprite::createWithSpriteFrameName(
27-
rl::constants::difficulty_to_sprite.at(difficulty).data()
45+
rl::constants::difficulty_to_sprite.at(m_difficulty_info.difficulty).data()
2846
);
2947
m_difficulty_sprite->setID("difficulty-sprite");
3048
this->addChild(m_difficulty_sprite);
@@ -34,74 +52,85 @@ bool RLDifficultyNode::init(GJDifficulty difficulty, bool featured, bool epic)
3452
this->setContentSize(targetContentSize);
3553
m_difficulty_sprite->setPosition(targetContentSize / 2);
3654

37-
if (featured)
55+
switch (m_difficulty_info.feature_state)
3856
{
39-
m_featured_sprite = CCSprite::createWithSpriteFrameName("GJ_featuredCoin_001.png");
40-
m_featured_sprite->setPosition(m_difficulty_sprite->getPosition());
41-
m_featured_sprite->setID("featured-sprite");
42-
this->addChild(m_featured_sprite, -1);
57+
case RL_FEATURE_STATE::FEATURED:
58+
case RL_FEATURE_STATE::EPIC:
59+
case RL_FEATURE_STATE::LEGENDARY:
60+
case RL_FEATURE_STATE::MYTHIC:
61+
m_feature_sprite = CCSprite::createWithSpriteFrameName(
62+
rl::constants::feature_state_to_sprite.at(m_difficulty_info.feature_state).data()
63+
);
64+
break;
65+
66+
default:
67+
m_feature_sprite = nullptr;
68+
break;
4369
}
4470

45-
if (epic)
71+
if (m_feature_sprite)
4672
{
47-
m_epic_sprite = CCSprite::createWithSpriteFrameName("GJ_epicCoin_001.png");
48-
m_epic_sprite->setPosition(m_difficulty_sprite->getPosition());
49-
m_epic_sprite->setID("epic-sprite");
50-
this->addChild(m_epic_sprite, -1);
73+
m_feature_sprite->setPosition(m_difficulty_sprite->getPosition());
74+
m_feature_sprite->setID("feature-sprite");
75+
this->addChild(m_feature_sprite, -1);
5176
}
5277

5378
return true;
5479
}
5580

56-
void RLDifficultyNode::setColor(const ccColor3B& color)
57-
{
58-
log::debug("called with r:{} g:{} b:{}", color.r, color.g, color.b);
59-
m_difficulty_sprite->setColor(color);
60-
if (m_featured_sprite)
61-
m_featured_sprite->setColor(color);
62-
if (m_epic_sprite)
63-
m_epic_sprite->setColor(color);
64-
65-
m_color = color;
66-
}
67-
6881
// basically RLDifficultyNode::init but without the call to CCNodeRGBA::init and some extra checks
69-
void RLDifficultyNode::setDifficulty(GJDifficulty difficulty, bool featured, bool epic)
82+
void RLDifficultyNode::setDifficulty(const DifficultyInfo& di)
7083
{
71-
if (m_difficulty_info == DifficultyInfo{ difficulty, featured, epic }) return;
84+
if (m_difficulty_info == di) return;
7285

73-
for (auto* node : CCArrayExt<CCSprite*>(this->getChildren()))
74-
node->removeFromParent();
86+
if (m_difficulty_info.difficulty != di.difficulty)
87+
{
88+
m_difficulty_sprite->removeFromParent();
7589

76-
m_difficulty_sprite = CCSprite::createWithSpriteFrameName(
77-
rl::constants::difficulty_to_sprite.at(difficulty).data()
78-
);
79-
m_difficulty_sprite->setColor(m_color);
80-
m_difficulty_sprite->setID("difficulty-sprite");
81-
this->addChild(m_difficulty_sprite);
90+
m_difficulty_sprite = CCSprite::createWithSpriteFrameName(
91+
rl::constants::difficulty_to_sprite.at(di.difficulty).data()
92+
);
93+
m_difficulty_sprite->setID("difficulty-sprite");
94+
this->addChild(m_difficulty_sprite);
95+
}
8296

8397
// man this codebase is getting worse by the minute
8498
// TODO: find a better way :despair:
8599
if (this->getParent() && typeinfo_cast<CCMenuItemSpriteExtra*>(this->getParent()))
86100
m_difficulty_sprite->setPosition(this->getContentSize() / 2);
87101

88-
if (featured)
102+
if (m_difficulty_info.feature_state != di.feature_state)
89103
{
90-
m_featured_sprite = CCSprite::createWithSpriteFrameName("GJ_featuredCoin_001.png");
91-
m_featured_sprite->setColor(m_color);
92-
m_featured_sprite->setPosition(m_difficulty_sprite->getPosition());
93-
m_featured_sprite->setID("featured-sprite");
94-
this->addChild(m_featured_sprite, -1);
104+
if (m_feature_sprite)
105+
m_feature_sprite->removeFromParent();
106+
107+
switch (di.feature_state)
108+
{
109+
case RL_FEATURE_STATE::FEATURED:
110+
case RL_FEATURE_STATE::EPIC:
111+
case RL_FEATURE_STATE::LEGENDARY:
112+
case RL_FEATURE_STATE::MYTHIC:
113+
m_feature_sprite = CCSprite::createWithSpriteFrameName(
114+
rl::constants::feature_state_to_sprite.at(di.feature_state).data()
115+
);
116+
break;
117+
118+
default:
119+
m_feature_sprite = nullptr;
120+
break;
121+
}
122+
123+
if (m_feature_sprite)
124+
{
125+
m_feature_sprite->setID("feature-sprite");
126+
this->addChild(m_feature_sprite, -1);
127+
}
95128
}
96129

97-
if (epic)
98-
{
99-
m_epic_sprite = CCSprite::createWithSpriteFrameName("GJ_epicCoin_001.png");
100-
m_epic_sprite->setColor(m_color);
101-
m_epic_sprite->setPosition(m_difficulty_sprite->getPosition());
102-
m_epic_sprite->setID("epic-sprite");
103-
this->addChild(m_epic_sprite, -1);
104-
}
130+
m_difficulty_info = di;
131+
}
105132

106-
m_difficulty_info = { difficulty, featured, epic };
133+
void RLDifficultyNode::setDifficulty(GJDifficulty difficulty)
134+
{
135+
setDifficulty({ difficulty, RL_FEATURE_STATE::NONE });
107136
}

src/custom_nodes/RLDifficultyNode.hpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,36 @@
66

77
using namespace geode::prelude;
88

9+
enum class RL_FEATURE_STATE
10+
{
11+
NONE = -1,
12+
FEATURED,
13+
EPIC,
14+
LEGENDARY,
15+
MYTHIC
16+
};
17+
918
class RLDifficultyNode : public CCNodeRGBA
1019
{
1120
private:
1221
struct DifficultyInfo
1322
{
1423
GJDifficulty difficulty;
15-
bool featured;
16-
bool epic;
24+
RL_FEATURE_STATE feature_state = RL_FEATURE_STATE::NONE;
1725

1826
bool operator==(const DifficultyInfo&) const = default;
1927
} m_difficulty_info;
2028

2129
CCSprite* m_difficulty_sprite;
22-
CCSprite* m_featured_sprite;
23-
CCSprite* m_epic_sprite;
24-
ccColor3B m_color;
30+
CCSprite* m_feature_sprite;
2531

2632
public:
27-
static RLDifficultyNode* create(GJDifficulty, bool = false, bool = false);
28-
bool init(GJDifficulty, bool = false, bool = false);
33+
static RLDifficultyNode* create(const DifficultyInfo&);
34+
static RLDifficultyNode* create(GJDifficulty);
35+
bool init(const DifficultyInfo&);
2936

30-
// TODO: fix this setColor fuckery
31-
void setColor(const ccColor3B&) override;
37+
void setDifficulty(const DifficultyInfo&);
38+
void setDifficulty(GJDifficulty);
3239

33-
void setDifficulty(GJDifficulty, bool = false, bool = false);
3440
const DifficultyInfo& getDifficultyInfo() const { return m_difficulty_info; };
3541
};

src/listfetcher/ListFetcher.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class ListFetcher
2222
inline static constexpr std::string_view DEMONLIST_URL = "https://pointercrate.com/api/v2/demons/listed";
2323
inline static constexpr std::string_view CHALLENGELIST_URL = "https://challengelist.gd/api/v1/demons";
2424

25+
// TODO: move to rl::constants
2526
inline static const std::map<GJDifficulty, int> m_cDemonDiffToFilter{
2627
{ GJDifficulty::DemonEasy, 1 },
2728
{ GJDifficulty::DemonMedium, 2 },

src/roulette/layers/RLRouletteInfoLayer.cpp

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
using namespace geode::prelude;
1212

13+
GJDifficulty RLRouletteInfoLayer::m_previous_roulette_difficulty = static_cast<GJDifficulty>(-3);
14+
1315
RLRouletteInfoLayer* RLRouletteInfoLayer::create()
1416
{
1517
auto ret = new RLRouletteInfoLayer();
@@ -92,11 +94,13 @@ bool RLRouletteInfoLayer::init()
9294

9395

9496
auto versionText = CCLabelBMFont::create(
95-
#ifdef RWDI_MODE
96-
("Version " + Mod::get()->getVersion().toString(true) + " dev").c_str(),
97+
#if defined(RWDI_MODE) && defined(GEODE_PLATFORM_SHORT_IDENTIFIER)
98+
fmt::format("Version: {} ({} dev)", Mod::get()->getVersion().toString(true), GEODE_PLATFORM_SHORT_IDENTIFIER).c_str(),
99+
#elif defined(GEODE_PLATFORM_SHORT_IDENTIFIER)
100+
fmt::format("Version: {} ({})", Mod::get()->getVersion().toString(true), GEODE_PLATFORM_SHORT_IDENTIFIER).c_str(),
97101
#else
98-
("Version " + Mod::get()->getVersion().toString(true)).c_str(),
99-
#endif // RWDI_MODE
102+
fmt::format("Version: {} (how)", Mod::get()->getVersion().toString(true)).c_str(),
103+
#endif
100104
"bigFont.fnt"
101105
);
102106
versionText->setPosition({ .0f, -94.f });
@@ -113,15 +117,27 @@ void RLRouletteInfoLayer::onClose(CCObject*)
113117
this->removeFromParentAndCleanup(true);
114118
}
115119

116-
// TODO: save the buttons' colors' states
117120
void RLRouletteInfoLayer::onToggleButton(CCObject* sender)
118121
{
119122
auto button = static_cast<CCMenuItemToggler*>(sender);
120123
auto prevIdx = rl::utils::getIndexOf(g_rouletteManager.getFromSaveContainer("selected-list-array").as_array(), true);
121124
const auto demonDifficultyButton = static_cast<RLDifficultyNode*>(
122-
g_rouletteManager.rouletteLayer->getDifficultyButton(GJDifficulty::Demon)->getNormalImage()
125+
g_rouletteManager.rouletteLayer->getDifficultyButton(GJDifficulty::Demon)->getChildByID("sprite-node")
123126
);
124127

128+
// yeah...
129+
auto changeListWrapper = [&](const std::function<void()>& f) {
130+
g_rouletteManager.getFromSaveContainer("selected-list-array").as_array().at(button->getTag()) = false;
131+
g_rouletteManager.getFromSaveContainer("selected-list-array").as_array().at(prevIdx) = false;
132+
g_rouletteManager.getFromSaveContainer("selected-list-array").as_array().at(0) = true;
133+
134+
f();
135+
136+
g_rouletteManager.getFromSaveContainer("selected-list-array").as_array().at(0) = false;
137+
g_rouletteManager.getFromSaveContainer("selected-list-array").as_array().at(prevIdx) = false;
138+
g_rouletteManager.getFromSaveContainer("selected-list-array").as_array().at(button->getTag()) = true;
139+
};
140+
125141
g_rouletteManager.getFromSaveContainer("selected-list-array").as_array().at(prevIdx) = false;
126142
g_rouletteManager.getFromSaveContainer("selected-list-array").as_array().at(button->getTag()) = true;
127143

@@ -130,46 +146,60 @@ void RLRouletteInfoLayer::onToggleButton(CCObject* sender)
130146
for (int i = 0; i < 4; i++)
131147
static_cast<CCMenuItemToggler*>(m_buttonMenu->getChildByTag(i))->toggle(false);
132148

149+
if (m_previous_roulette_difficulty == static_cast<GJDifficulty>(-3))
150+
m_previous_roulette_difficulty = g_rouletteManager.previousDifficulty;
151+
133152
// purely visual, "toggles" the difficulty face based on the selected list
134153
// (demon for demon list, insane for challenge list, and previous difficulty for normal list, easy for gd list because 🔥)
135154
if (button->getID() == "normal-list")
136155
{
137-
g_rouletteManager.rouletteLayer->setDifficultyButtonColor(GJDifficulty::Insane, { 125, 125, 125 });
138-
g_rouletteManager.rouletteLayer->setDifficultyButtonColor(GJDifficulty::Demon, { 125, 125, 125 });
139-
g_rouletteManager.rouletteLayer->setDifficultyButtonColor(g_rouletteManager.previousDifficulty, { 255, 255, 255 });
156+
changeListWrapper([&] {
157+
g_rouletteManager.rouletteLayer->onDifficultyButton(
158+
g_rouletteManager.rouletteLayer->getDifficultyButton(m_previous_roulette_difficulty)
159+
);
160+
});
161+
162+
m_previous_roulette_difficulty = static_cast<GJDifficulty>(-3);
140163
}
141164
else if (button->getID() == "demon-list")
142165
{
143-
g_rouletteManager.rouletteLayer->setDifficultyButtonColor(g_rouletteManager.previousDifficulty, { 125, 125, 125 });
144-
g_rouletteManager.rouletteLayer->setDifficultyButtonColor(GJDifficulty::Insane, { 125, 125, 125 });
145-
g_rouletteManager.rouletteLayer->setDifficultyButtonColor(GJDifficulty::Demon, { 255, 255, 255 });
166+
changeListWrapper([&] {
167+
g_rouletteManager.rouletteLayer->onDifficultyButton(
168+
g_rouletteManager.rouletteLayer->getDifficultyButton(GJDifficulty::Demon)
169+
);
170+
});
146171
demonDifficultyButton->setDifficulty(GJDifficulty::DemonExtreme);
147172
}
148173
else if (button->getID() == "challenge-list")
149174
{
150-
g_rouletteManager.rouletteLayer->setDifficultyButtonColor(g_rouletteManager.previousDifficulty, { 125, 125, 125 });
151-
g_rouletteManager.rouletteLayer->setDifficultyButtonColor(GJDifficulty::Insane, { 255, 255, 255 });
152-
g_rouletteManager.rouletteLayer->setDifficultyButtonColor(GJDifficulty::Demon, { 125, 125, 125 });
175+
changeListWrapper([&] {
176+
g_rouletteManager.rouletteLayer->onDifficultyButton(
177+
g_rouletteManager.rouletteLayer->getDifficultyButton(GJDifficulty::Insane)
178+
);
179+
});
153180
demonDifficultyButton->setDifficulty(static_cast<GJDifficulty>(-2));
154181
}
155182
else if (button->getID() == "gd-list")
156183
{
157184
// TODO: set the list's difficulty ... somehow?
158185

159-
g_rouletteManager.rouletteLayer->setDifficultyButtonColor(g_rouletteManager.previousDifficulty, { 125, 125, 125 });
160-
g_rouletteManager.rouletteLayer->setDifficultyButtonColor(GJDifficulty::Insane, { 125, 125, 125 });
161-
g_rouletteManager.rouletteLayer->setDifficultyButtonColor(GJDifficulty::Demon, { 125, 125, 125 });
186+
changeListWrapper([&] {
187+
g_rouletteManager.rouletteLayer->onDifficultyButton(
188+
g_rouletteManager.rouletteLayer->getDifficultyButton(GJDifficulty::Easy)
189+
);
190+
g_rouletteManager.rouletteLayer->getDifficultyButton(GJDifficulty::Easy)->setColor({ 125, 125, 125 });
191+
});
162192
demonDifficultyButton->setDifficulty(static_cast<GJDifficulty>(-2));
163193
}
164194

165195
if (button->getID() != "normal-list")
166196
g_rouletteManager.rouletteLayer->main_menu->getChildByID("demon-plus-button")->setVisible(false);
167-
else if (g_rouletteManager.previousDifficulty == GJDifficulty::Demon)
197+
else if (m_previous_roulette_difficulty == GJDifficulty::Demon)
168198
g_rouletteManager.rouletteLayer->main_menu->getChildByID("demon-plus-button")->setVisible(true);
169199

170200
if (button->getID() == "normal-list")
171201
demonDifficultyButton->setDifficulty(
172-
g_rouletteManager.previousDifficulty == GJDifficulty::Demon
202+
m_previous_roulette_difficulty == GJDifficulty::Demon
173203
? g_rouletteManager.previousDemonDifficulty
174204
: static_cast<GJDifficulty>(-2)
175205
);

0 commit comments

Comments
 (0)