Skip to content

Commit 1392615

Browse files
committed
feat(difficulty): Add Demon difficulty
1 parent 9d42802 commit 1392615

File tree

7 files changed

+47
-28
lines changed

7 files changed

+47
-28
lines changed

src/custom_layers/RLDifficultySelectLayer.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "RLDifficultySelectLayer.hpp"
2+
#include "../utils.hpp"
23

34
RLDifficultySelectLayer* RLDifficultySelectLayer::create(const RLDifficultySelectInfo& dsi)
45
{
@@ -26,15 +27,19 @@ bool RLDifficultySelectLayer::init(const RLDifficultySelectInfo& dsi)
2627

2728
difficulty_buttons_menu = CCMenu::create();
2829
difficulty_buttons_menu->setID("difficulty-buttons");
30+
difficulty_buttons_menu->setContentSize({ 380.f, 180.f });
31+
difficulty_buttons_menu->setLayout(
32+
AxisLayout::create()
33+
->setGap(15.f)
34+
->setGrowCrossAxis(true)
35+
);
2936
m_mainLayer->addChild(difficulty_buttons_menu, 11);
3037

3138

32-
for (int i = 0; i < m_dsi.difficulties.size(); i++)
39+
for (const auto& difficulty : m_dsi.difficulties)
3340
{
34-
const auto difficulty = m_dsi.difficulties.at(i);
35-
3641
auto difficultySprite = CCSprite::createWithSpriteFrameName(
37-
fmt::format("difficulty_{0:0{1}}_btn2_001.png", static_cast<int>(difficulty), 2).c_str()
42+
rl::constants::difficulty_to_sprite.at(difficulty).data()
3843
);
3944
difficultySprite->setScale(1.2f);
4045
auto difficultyButton = CCMenuItemSpriteExtra::create(
@@ -44,12 +49,15 @@ bool RLDifficultySelectLayer::init(const RLDifficultySelectInfo& dsi)
4449
);
4550
if (m_dsi.selectedDifficulty != difficulty)
4651
difficultyButton->setColor({ 125, 125, 125 });
47-
difficultyButton->setPosition({ -125.f + i * 60.f, 7.f });
52+
difficultyButton->setLayoutOptions(AxisLayoutOptions::create());
4853
difficultyButton->setTag(static_cast<int>(difficulty));
4954
difficulty_buttons_menu->addChild(difficultyButton);
5055
}
5156

5257

58+
difficulty_buttons_menu->updateLayout();
59+
60+
5361
auto title = CCLabelBMFont::create(m_dsi.title.data(), "bigFont.fnt");
5462
title->setPosition({ .0f, 70.f });
5563
m_buttonMenu->addChild(title);

src/custom_layers/RLDifficultySelectLayer.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22
#include <string_view>
3-
#include <array>
3+
#include <vector>
44
#include <functional>
55

66
#include <Geode/Enums.hpp>
@@ -12,7 +12,7 @@ class RLDifficultySelectLayer;
1212
struct RLDifficultySelectInfo
1313
{
1414
std::string_view title;
15-
std::array<GJDifficulty, 5> difficulties;
15+
std::vector<GJDifficulty> difficulties;
1616
GJDifficulty selectedDifficulty;
1717
std::function<void(GJDifficulty, GJDifficulty)> onSelectDifficulty;
1818
std::function<void(RLDifficultySelectLayer*)> onOk = nullptr;

src/listfetcher/ListFetcher.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,12 @@ void ListFetcher::getRandomNormalListLevel(GJDifficulty difficulty, level_pair_t
7474
.bodyString(
7575
fmt::format("secret={}&type={}&star={}&page={}&len={}{}",
7676
GJ_SECRET, 0, 1,
77-
rl::utils::randomInt(1, m_cNormalListMaxPage[static_cast<int>(difficulty) - 1]),
77+
rl::utils::randomInt(
78+
1,
79+
difficulty == static_cast<GJDifficulty>(-2)
80+
? m_cNormalListMaxPage[5]
81+
: m_cNormalListMaxPage[static_cast<int>(difficulty) - 1]
82+
),
7883
GJ_LEN_QUERY, getDifficultyQuery(difficulty)
7984
)
8085
)

src/listfetcher/ListFetcher.hpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,29 @@ class ListFetcher
2828

2929
// TODO: move to rl::constants
3030
inline static const std::map<GJDifficulty, int> m_cDemonDiffToFilter{
31+
{ static_cast<GJDifficulty>(-2), 0 },
3132
{ GJDifficulty::DemonEasy, 1 },
3233
{ GJDifficulty::DemonMedium, 2 },
3334
{ GJDifficulty::Demon, 3 },
3435
{ GJDifficulty::DemonInsane, 4 },
3536
{ GJDifficulty::DemonExtreme, 5 }
3637
};
3738
// these are only for rated Tiny to XL levels
38-
inline static const std::array<int, 10> m_cNormalListMaxPage{
39-
74, // Easy
40-
173, // Normal
41-
1031, // Hard
42-
1308, // Harder
43-
543, // Insane
44-
45-
142, // Hard Demon
46-
187, // Easy Demon
47-
205, // Medium Demon
48-
99, // Insane Demon
49-
90 // Extreme Demon
39+
// TODO: fetch dynamically
40+
inline static const std::array<int, 11> m_cNormalListMaxPage{
41+
84, // Easy
42+
189, // Normal
43+
1156, // Hard
44+
1497, // Harder
45+
634, // Insane
46+
47+
803, // Demon
48+
49+
148, // Hard Demon
50+
210, // Easy Demon
51+
229, // Medium Demon
52+
109, // Insane Demon
53+
108 // Extreme Demon
5054
};
5155
inline static const int m_cDemonListMaxPage = 490;
5256

src/roulette/layers/RLRouletteLayer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ void RLRouletteLayer::onPlusButton(CCObject*)
455455
{
456456
m_demon_select_layer = RLDifficultySelectLayer::create({
457457
"Demon Filter",
458-
{ GJDifficulty::DemonEasy, GJDifficulty::DemonMedium, GJDifficulty::Demon, GJDifficulty::DemonInsane, GJDifficulty::DemonExtreme },
458+
{ static_cast<GJDifficulty>(-2), GJDifficulty::DemonEasy, GJDifficulty::DemonMedium, GJDifficulty::Demon, GJDifficulty::DemonInsane, GJDifficulty::DemonExtreme },
459459
m_selected_demon_difficulty,
460460
[&](GJDifficulty currentDifficulty, GJDifficulty previousDifficulty)
461461
{

src/roulette/manager/DataManager.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ namespace DataManager
6767
if constexpr (key == DMArrayKey::DIFFICULTY_ARRAY)
6868
return { 6, { true, false, false, false, false, false } };
6969
else if constexpr (key == DMArrayKey::DEMON_DIFFICULTY_ARRAY)
70-
return { 5, { true, false, false, false, false, false } };
70+
return { 6, { false, true, false, false, false, false, false } };
7171
else if constexpr (key == DMArrayKey::SELECTED_LIST_ARRAY)
7272
return { 4, { true, false, false, false } };
7373

src/utils.hpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ namespace rl
267267
{ GJDifficulty::Demon, 5 }
268268
};
269269

270-
inline const std::array<GJDifficulty, 5> idx_to_demon_diff{
270+
inline const std::array<GJDifficulty, 6> idx_to_demon_diff{
271+
static_cast<GJDifficulty>(-2),
271272
GJDifficulty::DemonEasy,
272273
GJDifficulty::DemonMedium,
273274
GJDifficulty::Demon,
@@ -276,11 +277,12 @@ namespace rl
276277
};
277278

278279
inline const std::map<GJDifficulty, int> demon_diff_to_idx{
279-
{ GJDifficulty::DemonEasy, 0 },
280-
{ GJDifficulty::DemonMedium, 1 },
281-
{ GJDifficulty::Demon, 2 },
282-
{ GJDifficulty::DemonInsane, 3 },
283-
{ GJDifficulty::DemonExtreme, 4 }
280+
{ static_cast<GJDifficulty>(-2), 0 },
281+
{ GJDifficulty::DemonEasy, 1 },
282+
{ GJDifficulty::DemonMedium, 2 },
283+
{ GJDifficulty::Demon, 3 },
284+
{ GJDifficulty::DemonInsane, 4 },
285+
{ GJDifficulty::DemonExtreme, 5 }
284286
};
285287
}
286288
}

0 commit comments

Comments
 (0)