Skip to content

Commit 4463582

Browse files
committed
fix(list-fetcher, roulette-layer): Fix roulette showing same levels. Fix weird blink transition
1 parent 26cca94 commit 4463582

File tree

6 files changed

+47
-30
lines changed

6 files changed

+47
-30
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8-
# [4.0.0] - 2025-01-31
8+
## [4.0.1] - 2025-01-31
9+
10+
### Fixed
11+
12+
- Android crash
13+
- Roulette would only show the same levels from page 1
14+
- Weird blink transition when exiting Roulette layer
15+
16+
## [4.0.0] - 2025-01-31
917

1018
The GD-Roulette UI update, featuring new UI, new UI and even more new UI!
1119
This update took a lot of time, so if you like it and would like more, consider donating by clicking the gift box icon below :D

mod.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"android": "2.2074",
66
"mac": "2.2074"
77
},
8-
"version": "v4.0.0",
8+
"version": "v4.0.1",
99
"id": "spaghettdev.gd-roulette",
1010
"name": "GD-Roulette",
1111
"developer": "SpaghettDev",

src/listfetcher/ListFetcher.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@ ListFetcher::ListFetcher()
1818

1919
matjson::Value ListFetcher::normalListCacheFunction()
2020
{
21+
matjson::Value defaultObj{};
22+
2123
for (const auto& difficulty : {
2224
GJDifficulty::Easy, GJDifficulty::Normal, GJDifficulty::Hard,
2325
GJDifficulty::Harder, GJDifficulty::Insane, static_cast<GJDifficulty>(-2),
2426
GJDifficulty::DemonEasy, GJDifficulty::DemonMedium, GJDifficulty::Demon,
2527
GJDifficulty::DemonInsane, GJDifficulty::DemonExtreme
2628
}) {
29+
defaultObj[fmt::format("{}", static_cast<int>(difficulty))] = 100;
30+
2731
WebRequestQueue::get().enqueue(WebRequestQueue::Request{
2832
web::WebRequest()
2933
.userAgent("")
@@ -58,7 +62,7 @@ matjson::Value ListFetcher::normalListCacheFunction()
5862

5963
WebRequestQueue::get().flush();
6064

61-
return {};
65+
return defaultObj;
6266
}
6367

6468
void ListFetcher::getRandomNormalListLevel(GJDifficulty difficulty, geode::Result<level_pair_t>& result)

src/managers/CacheManager.hpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ struct CacheManager : public SingletonBase<CacheManager>
5353
void save();
5454

5555
template <CMKey key>
56-
[[nodiscard]] const CMKeyTrait<key>::type& getValue()
56+
[[nodiscard]] CMKeyTrait<key>::type getValue()
5757
{
58-
if (auto cached = m_cache.get<matjson::Value>(getKeyString<key>()); cached.isOk())
58+
if (auto cached = m_cache.get<matjson::Value>(getKeyString<key>()); cached.isOkAnd([](const matjson::Value& v) { return v.contains("time") && v.contains("value"); }))
5959
{
6060
auto time = cached.unwrap().template get<std::uint64_t>("time").unwrapOr(0);
6161

@@ -65,22 +65,20 @@ struct CacheManager : public SingletonBase<CacheManager>
6565
else
6666
setValue<key>(callCacheFunction<key>());
6767

68-
if (auto res = m_cache[getKeyString<key>()]["value"].template as<typename CMKeyTrait<key>::type>())
69-
return res.unwrap();
70-
else
71-
{
72-
setValue<key>(callCacheFunction<key>());
73-
return m_cache[getKeyString<key>()]["value"].template as<typename CMKeyTrait<key>::type>().unwrap();
74-
}
68+
return std::move(
69+
m_cache[getKeyString<key>()]["value"].template as<typename CMKeyTrait<key>::type>().unwrap()
70+
);
7571
}
7672

7773
template <CMKey key, typename R, typename P>
7874
[[nodiscard]] R getValue(P keyName, R defaultValue = {}) requires(std::is_same_v<typename CMKeyTrait<key>::type, matjson::Value> && std::is_default_constructible_v<R>)
7975
{
80-
if constexpr (std::is_enum_v<P>)
81-
return getValue<key>()[fmt::format("{}", static_cast<int>(keyName))].template as<R>().unwrapOr(defaultValue);
76+
using result_t = std::conditional_t<std::is_same_v<R, int>, std::uint64_t, R>;
77+
78+
if constexpr (std::is_enum_v<P> || std::is_integral_v<P>)
79+
return getValue<key>()[fmt::format("{}", static_cast<int>(keyName))].template as<result_t>().unwrapOr(defaultValue);
8280
else
83-
return getValue<key>()[keyName].template as<R>().unwrapOr(defaultValue);
81+
return getValue<key>()[keyName].template as<result_t>().unwrapOr(defaultValue);
8482
}
8583

8684
template <CMKey key>
@@ -102,9 +100,8 @@ struct CacheManager : public SingletonBase<CacheManager>
102100
}
103101

104102
template <CMKey key>
105-
void appendValue(const std::string& keyName, const CMKeyTrait<key>::type& value) requires(
106-
std::is_same_v<typename CMKeyTrait<key>::type, matjson::Value>
107-
)
103+
void appendValue(const std::string& keyName, const CMKeyTrait<key>::type& value)
104+
requires(std::is_same_v<typename CMKeyTrait<key>::type, matjson::Value>)
108105
{
109106
m_cache[getKeyString<key>()]["time"] = rl::utils::getUnixEpoch();
110107
m_cache[getKeyString<key>()]["value"][keyName] = value;

src/roulette/RLRouletteLayer.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -547,21 +547,23 @@ bool RLRouletteLayer::init()
547547

548548
void RLRouletteLayer::onClose(CCObject*)
549549
{
550+
auto& rlm = RouletteManager::get();
551+
550552
if (RouletteManager::get().isPlaying)
551553
{
552554
m_confirmation_layer = RLConfirmationAlertLayer::create({
553555
"Woah there!",
554556
"Would you like to <cr>quit</c> or <co>pause</c> the roulette?",
555557
[&](auto cl) {
556-
RouletteManager::get().gameTimer.pause();
557-
RouletteManager::get().saveState();
558-
RouletteManager::get().isPlaying = false;
559-
RouletteManager::get().isPaused = true;
558+
rlm.gameTimer.pause();
559+
rlm.saveState();
560+
rlm.isPlaying = false;
561+
rlm.isPaused = true;
560562

561563
onClose(nullptr);
562564
},
563565
[&](auto cl) {
564-
RouletteManager::get().reset();
566+
rlm.reset();
565567

566568
onClose(nullptr);
567569
},
@@ -573,8 +575,8 @@ void RLRouletteLayer::onClose(CCObject*)
573575
else
574576
{
575577
this->setKeypadEnabled(false);
576-
this->removeFromParentAndCleanup(true);
577-
RouletteManager::get().rouletteLayer = nullptr;
578+
this->setKeyboardEnabled(false);
579+
rlm.rouletteLayer = nullptr;
578580

579581
CCDirector::sharedDirector()->popSceneWithTransition(
580582
.5f, PopTransition::kPopTransitionFade
@@ -706,11 +708,12 @@ void RLRouletteLayer::onPlayButton(CCObject*)
706708
return;
707709

708710
LevelInfoLayer* layer;
709-
const auto& level = m_level.unwrap();
710711

711-
if (level.first.levelID != 0)
712+
if (m_level.isOkAnd([](const auto& lvl) { return lvl.first.levelID != 0; }))
712713
{
713-
layer = LevelInfoLayer::create(rl::utils::createLevelFromResponse(level), false);
714+
const auto& lvl = m_level.unwrap();
715+
716+
layer = LevelInfoLayer::create(rl::utils::createLevelFromResponse(lvl), false);
714717
layer->downloadLevel();
715718
}
716719
else
@@ -1032,6 +1035,8 @@ void RLRouletteLayer::onListChanged()
10321035
// set roulette button exclamation mark
10331036
void RLRouletteLayer::onExitTransitionDidStart()
10341037
{
1038+
BaseCustomLayer::onExitTransitionDidStart();
1039+
10351040
if (auto nextScene = static_cast<CCScene*>(CCDirector::sharedDirector()->m_pobScenesStack->firstObject()))
10361041
{
10371042
CCMenuItemSpriteExtra* rouletteButton = nullptr;
@@ -1073,6 +1078,8 @@ void RLRouletteLayer::onExitTransitionDidStart()
10731078

10741079
void RLRouletteLayer::onEnterTransitionDidFinish()
10751080
{
1081+
BaseCustomLayer::onEnterTransitionDidFinish();
1082+
10761083
auto& rlm = RouletteManager::get();
10771084

10781085
if (!rlm.isPlaying || !rlm.hasEnteredPlayLayer)

src/utils/utils.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace rl
2020
{
2121
namespace impl
2222
{
23-
inline static std::random_device rand_device;
23+
inline static std::random_device rand_device{};
2424
inline static std::mt19937 rand_generator(rand_device());
2525
}
2626

@@ -34,7 +34,8 @@ namespace rl
3434
* @tparam T type of number, floating type or integer type
3535
*/
3636
template <typename T1, typename T2>
37-
inline T2 randomNumber(T1 min, T2 max) requires (std::is_arithmetic_v<T1> && std::is_arithmetic_v<T2> && std::is_convertible_v<T1, T2>)
37+
inline T2 randomNumber(T1 min, T2 max)
38+
requires(std::is_arithmetic_v<T1> && std::is_arithmetic_v<T2> && std::is_convertible_v<T1, T2>)
3839
{
3940
static_assert(
4041
(std::is_integral_v<T1> && std::is_integral_v<T2>) ||

0 commit comments

Comments
 (0)