Skip to content

Commit

Permalink
update, feat(goal): Update to Geode v4.0.1 and allow resuming of a ro…
Browse files Browse the repository at this point in the history
…und of roulette
  • Loading branch information
SpaghettDev committed Nov 24, 2024
1 parent 7148cea commit 7137ec7
Show file tree
Hide file tree
Showing 13 changed files with 490 additions and 196 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [3.0.0] - 2024-11-24

### Added

- Resuming round of roulette after game shutdown
- Exclamation Mark when a round of roulette is paused

### Changed

- Target Geode v4.0.1
- How target percentage is displayed: it is now always the current goal, not the current percentage + 1

## [2.1.0] - 2024-06-15

### Changed
Expand Down
15 changes: 7 additions & 8 deletions mod.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
{
"geode": "3.0.0-beta.4",
"geode": "4.0.1",
"gd": {
"win": "2.206",
"android": "2.206",
"mac": "2.206"
"win": "2.2074",
"android": "2.2074",
"mac": "2.2074"
},
"version": "v2.1.0",
"version": "v3.0.0",
"id": "spaghettdev.gd-roulette",
"name": "GD-Roulette",
"developer": "SpaghettDev",
"description": "An in-game level roulette.",
"repository": "https://github.com/SpaghettDev/GD-Roulette",
"links": {
"community": "https://discord.gg/3bShQb6Jz3",
"source": "https://github.com/SpaghettDev/GD-Roulette"
Expand All @@ -27,12 +26,12 @@
"dependencies": [
{
"id": "geode.node-ids",
"version": ">=v1.12.0",
"version": ">=v1.17.0",
"importance": "required"
}
],
"tags": [
"Interface", "Online"
"interface", "online"
],
"settings": {
"max-skips": {
Expand Down
56 changes: 26 additions & 30 deletions src/layers/CreatorLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ class $modify(RouletteButton, CreatorLayer)
{
void onRouletteButton(CCObject*)
{
g_rouletteManager.rouletteLayer = RLRouletteLayer::create();
if (g_rouletteManager.rouletteLayer)
if (g_rouletteManager.rouletteLayer = RLRouletteLayer::create(); g_rouletteManager.rouletteLayer)
g_rouletteManager.rouletteLayer->show();

if (auto exMark = this->getChildByID("center-left-menu"_spr)->getChildByID("roulette-button"_spr)->getChildByID("exclamation-mark"))
exMark->removeFromParent();
}

bool init()
Expand All @@ -20,34 +22,28 @@ class $modify(RouletteButton, CreatorLayer)

auto winSize = CCDirector::sharedDirector()->getWinSize();

if(Mod::get()->getSettingValue<bool>("use-big-button") && Loader::get()->isModLoaded("alphalaneous.pages_api")) {
if(auto menu = getChildByID("creator-buttons-menu")) {
auto spr = CCSprite::create("RL_btn_big.png"_spr);
spr->setScale(0.842);
auto rouletteButton = CCMenuItemSpriteExtra::create(
spr,
this,
menu_selector(RouletteButton::onRouletteButton)
);
rouletteButton->setID("roulette-button"_spr);
menu->addChild(rouletteButton);
}
}
else {
if(auto menu = getChildByID("exit-menu")) {
auto spr = CircleButtonSprite::createWithSprite("RL_btn_001.png"_spr, 1.0f, CircleBaseColor::Green, CircleBaseSize::Small);

auto rouletteButton = CCMenuItemSpriteExtra::create(
spr,
this,
menu_selector(RouletteButton::onRouletteButton)
);
rouletteButton->setID("roulette-button"_spr);
menu->addChild(rouletteButton);
typeinfo_cast<AxisLayout*>(menu->getLayout())->setAxisReverse(true);
menu->updateLayout();
}
}
auto centerLeftMenu = CCMenu::create();
centerLeftMenu->setPosition({
this->getChildByID("exit-menu")->getPositionX(),
CCDirector::sharedDirector()->getWinSize().height / 2.f
});
centerLeftMenu->setID("center-left-menu"_spr);
this->addChild(centerLeftMenu);

auto spr = CircleButtonSprite::createWithSprite("RL_btn_001.png"_spr, 1.0f, CircleBaseColor::Green, CircleBaseSize::Small);
spr->setScale(1.1f);

auto rouletteButton = CCMenuItemSpriteExtra::create(
spr,
this,
menu_selector(RouletteButton::onRouletteButton)
);
rouletteButton->setID("roulette-button"_spr);
rouletteButton->setLayout(AnchorLayout::create());
centerLeftMenu->addChild(rouletteButton);

if (g_rouletteManager.gameState.levelID != 0)
g_rouletteManager.addExclamationMark(rouletteButton);

return true;
}
Expand Down
8 changes: 4 additions & 4 deletions src/layers/LevelInfoLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class $modify(LevelInfoLayer)
{
if (!LevelInfoLayer::init(level, p1)) return false;

if (g_rouletteManager.isPlaying && level->m_levelID.value() == g_rouletteManager.currentLevelID)
if (g_rouletteManager.isPlaying && level->m_levelID.value() == g_rouletteManager.gameState.levelID)
{
CCLabelBMFont* normalPercentageLabel = static_cast<CCLabelBMFont*>(this->getChildByID("normal-mode-percentage"));

Expand All @@ -20,7 +20,7 @@ class $modify(LevelInfoLayer)
float goalOffset = normalPercentageLabel->getContentWidth() / 2;

auto goalPercentage = CCLabelBMFont::create(
fmt::format("({}%)", g_rouletteManager.levelPercentageGoal).c_str(),
fmt::format("({}%)", g_rouletteManager.currentPercentageGoal).c_str(),
"bigFont.fnt"
);
goalPercentage->setPosition({ normalPercentageLabel->getPositionX() + goalOffset, normalPercentageLabel->getPositionY() });
Expand All @@ -39,11 +39,11 @@ class $modify(LevelInfoLayer)
if (
g_rouletteManager.isPlaying &&
g_rouletteManager.rouletteLayer &&
this->m_level->m_levelID.value() == g_rouletteManager.currentLevelID
this->m_level->m_levelID.value() == g_rouletteManager.gameState.levelID
)
static_cast<CCLabelBMFont*>(
g_rouletteManager.rouletteLayer->playing_menu->getChildByID("percentage-text")
)->setString(fmt::format("{}%", g_rouletteManager.levelPercentageGoal).c_str());
)->setString(fmt::format("{}%", g_rouletteManager.currentPercentageGoal).c_str());

LevelInfoLayer::onBack(sender);
}
Expand Down
6 changes: 3 additions & 3 deletions src/layers/PauseLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class $modify(PauseLayer)
{
PauseLayer::customSetup();

const PlayLayer* playLayer = GameManager::sharedState()->getPlayLayer();
const auto* playLayer = GameManager::sharedState()->getPlayLayer();

if (g_rouletteManager.isPlaying && playLayer->m_level->m_levelID.value() == g_rouletteManager.currentLevelID)
if (g_rouletteManager.isPlaying && playLayer->m_level->m_levelID.value() == g_rouletteManager.gameState.levelID)
{
CCLabelBMFont* normalPercentageLabel = static_cast<CCLabelBMFont*>(this->getChildByID("normal-progress-label"));

Expand All @@ -21,7 +21,7 @@ class $modify(PauseLayer)
float goalOffset = normalPercentageLabel->getContentWidth() / 2 + 7.f;

auto goalPercentage = CCLabelBMFont::create(
fmt::format("({}%)", g_rouletteManager.levelPercentageGoal).c_str(),
fmt::format("({}%)", g_rouletteManager.currentPercentageGoal).c_str(),
"bigFont.fnt"
);
goalPercentage->setPosition({ normalPercentageLabel->getPositionX() + goalOffset, normalPercentageLabel->getPositionY() });
Expand Down
22 changes: 11 additions & 11 deletions src/layers/PlayLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@ class $modify(PlayLayerPause, PlayLayer)
#endif // GEODE_IS_MACOS
if (
g_rouletteManager.isPlaying &&
this->m_level->m_levelID == g_rouletteManager.currentLevelID &&
this->m_level->m_levelID == g_rouletteManager.gameState.levelID &&
!this->m_isPracticeMode &&
percentage >= g_rouletteManager.levelPercentageGoal
percentage >= g_rouletteManager.gameState.levelPercentageGoal
) {
if (currentDelta > .2f/* && !this->m_player1->m_isDead*/)
{
g_rouletteManager.hasFinishedPreviousLevel = true;
g_rouletteManager.currentLevelPercentage = percentage;
g_rouletteManager.levelPercentageGoal = percentage + 1;
g_rouletteManager.numLevels++;
g_rouletteManager.gameState.hasReachedGoal = true;
g_rouletteManager.gameState.levelPercentage = percentage;
g_rouletteManager.gameState.levelPercentageGoal = percentage + 1;
g_rouletteManager.gameState.numLevels++;

if (Mod::get()->getSettingValue<bool>("auto-pause"))
{
Expand All @@ -99,13 +99,13 @@ class $modify(PlayLayerPause, PlayLayer)
{
if (
g_rouletteManager.isPlaying &&
this->m_level->m_levelID == g_rouletteManager.currentLevelID &&
this->m_level->m_levelID == g_rouletteManager.gameState.levelID &&
!this->m_isPracticeMode
) {
g_rouletteManager.hasFinishedPreviousLevel = true;
g_rouletteManager.currentLevelPercentage = 100;
g_rouletteManager.levelPercentageGoal = 100;
g_rouletteManager.numLevels++;
g_rouletteManager.gameState.hasReachedGoal = true;
g_rouletteManager.gameState.levelPercentage = 100;
g_rouletteManager.gameState.levelPercentageGoal = 100;
g_rouletteManager.gameState.numLevels++;
}

PlayLayer::levelComplete();
Expand Down
42 changes: 32 additions & 10 deletions src/listfetcher/ListFetcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,29 @@ void ListFetcher::getRandomDemonListLevel(level_pair_t& level, std::string& erro

const auto& jsonResp = resp.unwrap();

if (jsonResp.is_null())
if (jsonResp.isNull() || !jsonResp.isArray())
{
error = "Pointercrate API returned null. Try again later.";
error = "Pointercrate API returned null or non-array. Try again later.";
is_fetching = false;
return;
}

const auto array = jsonResp.asArray().unwrap();

int randomIndex;
do {
randomIndex = rl::utils::randomInt(0, jsonResp.as_array().size() - 1);
} while (jsonResp[randomIndex]["level_id"].is_null());
randomIndex = rl::utils::randomInt(0, array.size() - 1);
} while (array[randomIndex]["level_id"].isNull());

int levelId = array[randomIndex].template get<int>("level_id").unwrapOr(-1);

if (levelId == -1)
{
error = "Pointercrate API returned non-number 'level_id'. Contact developer to fix this.";
is_fetching = false;
return;
}

int levelId = jsonResp[randomIndex].template get<int>("level_id");
getLevelInfo(levelId, level, error);
}
else if (e->isCancelled())
Expand Down Expand Up @@ -150,19 +160,29 @@ void ListFetcher::getRandomChallengeListLevel(level_pair_t& level, std::string&

const auto& jsonResp = resp.unwrap();

if (jsonResp.is_null() || !jsonResp.is_array())
if (jsonResp.isNull() || !jsonResp.isArray())
{
error = "Challenge List API returned null. Try again later.";
error = "Challenge List API returned null or non-array. Try again later.";
is_fetching = false;
return;
}

const auto& array = jsonResp.asArray().unwrap();

int randomIndex;
do {
randomIndex = rl::utils::randomInt(0, jsonResp.as_array().size() - 1);
} while (jsonResp[randomIndex]["level_id"].is_null());
randomIndex = rl::utils::randomInt(0, array.size() - 1);
} while (array[randomIndex]["level_id"].isNull());

int levelId = array[randomIndex].template get<int>("level_id").unwrapOr(-1);

if (levelId == -1)
{
error = "Challenge List API returned non-number 'level_id'. Contact developer to fix this.";
is_fetching = false;
return;
}

int levelId = jsonResp[randomIndex].template get<int>("level_id");
getLevelInfo(levelId, level, error);
}
else if (e->isCancelled())
Expand Down Expand Up @@ -253,6 +273,8 @@ void ListFetcher::getRandomGDListLevel(int listID, level_pair_t& level, std::str

void ListFetcher::getLevelInfo(int levelID, level_pair_t& level, std::string& error)
{
is_fetching = true;

m_listener2.bind([&](web::WebTask::Event* e) {
if (web::WebResponse* res = e->getValue())
{
Expand Down
20 changes: 11 additions & 9 deletions src/roulette/layers/RLRouletteInfoLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ bool RLRouletteInfoLayer::init()
);
idButton->setVisible(
rl::utils::getIndexOf(
g_rouletteManager.getFromSaveContainer("selected-list-array").as_array(), true
DataManager::get<DMArrayKey::SELECTED_LIST_ARRAY>().asVector(), true
) == 3
);
{
Expand Down Expand Up @@ -121,24 +121,26 @@ void RLRouletteInfoLayer::onClose(CCObject*)
void RLRouletteInfoLayer::onToggleButton(CCObject* sender)
{
auto button = static_cast<CCMenuItemToggler*>(sender);
auto prevIdx = rl::utils::getIndexOf(g_rouletteManager.getFromSaveContainer("selected-list-array").as_array(), true);
auto prevIdx = rl::utils::getIndexOf(
DataManager::get<DMArrayKey::SELECTED_LIST_ARRAY>().asVector(), true
);
const auto demonDifficultyButton = static_cast<RLDifficultyNode*>(
g_rouletteManager.rouletteLayer->getDifficultyButton(GJDifficulty::Demon)->getChildByID("sprite-node")
);

// yeah...
auto changeListWrapper = [&](const std::function<void()>& f) {
g_rouletteManager.getFromSaveContainer("selected-list-array").as_array().at(button->getTag()) = false;
g_rouletteManager.getFromSaveContainer("selected-list-array").as_array().at(0) = true;
DataManager::set<DMArrayKey::SELECTED_LIST_ARRAY>(button->getTag(), false);
DataManager::set<DMArrayKey::SELECTED_LIST_ARRAY>(0, true);

f();

g_rouletteManager.getFromSaveContainer("selected-list-array").as_array().at(0) = false;
g_rouletteManager.getFromSaveContainer("selected-list-array").as_array().at(button->getTag()) = true;
DataManager::set<DMArrayKey::SELECTED_LIST_ARRAY>(0, false);
DataManager::set<DMArrayKey::SELECTED_LIST_ARRAY>(button->getTag(), true);
};

g_rouletteManager.getFromSaveContainer("selected-list-array").as_array().at(prevIdx) = false;
g_rouletteManager.getFromSaveContainer("selected-list-array").as_array().at(button->getTag()) = true;
DataManager::set<DMArrayKey::SELECTED_LIST_ARRAY>(prevIdx, false);
DataManager::set<DMArrayKey::SELECTED_LIST_ARRAY>(button->getTag(), true);

m_buttonMenu->getChildByID("list-id-button")->setVisible(button->getTag() == 3);

Expand Down Expand Up @@ -297,7 +299,7 @@ CCMenuItemToggler* RLRouletteInfoLayer::createToggler(int tag, const std::string
button->setSizeMult(1.2f);
button->setTag(tag);
button->setVisible(visible);
button->toggle(g_rouletteManager.getFromSaveContainer("selected-list-array").as_array().at(tag).as<bool>());
button->toggle(DataManager::get<DMArrayKey::SELECTED_LIST_ARRAY>().at<bool>(tag));
button->setID(nodeID);
m_buttonMenu->addChild(button);

Expand Down
Loading

0 comments on commit 7137ec7

Please sign in to comment.