Skip to content

Commit

Permalink
Made auto pause an option, added some IDs to nodes and more.
Browse files Browse the repository at this point in the history
mfw i commit only part of the changed
  • Loading branch information
SpaghettDev committed Feb 7, 2024
1 parent c9557bd commit 34712e2
Show file tree
Hide file tree
Showing 13 changed files with 139 additions and 93 deletions.
23 changes: 23 additions & 0 deletions ABOUT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# GD-Roulette

A Geometry Dash Level Roulette.

## Features

- Normal List (regular levels ranging from Easy to Extreme Demon)
- Demon List
- Challenge List
- Skip levels you can't beat
- Auto pause after reaching the goal percentage (can be disabled)

## How To Play

Simply choose the list you want to play levels from (the default is normal list), select a difficulty, and press Start!
A random level of the chosen difficulty will be given to you and you will need to achieve a certain percentage in said level (starts from 1%, and increments by 1 after each level beaten).
Normally, you're supposed to get to get the goal percentage, and not higher. Unfortunately, some levels don't have a way to die at said percentage, so the goal will automatically be your death percentage + 1.

After reaching/surpassing the goal percentage in a round of roulette, the game will automatically pause after you die. This can be disabled in the mod's Geode settings.

If a level is too hard, you can click on the Skip button, which will subtract 1 skip from your skips. You can set the number of skips you are allowed to use during a round of roulette in the roulette's settings (accessible from the info icon in the roulette while not playing it, or from the Geode mod settings).

And that's pretty much it! Have fun rouletting!
26 changes: 25 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,30 @@ 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/).

## [1.6.1-beta.1] - 2024-02-07

### Added

- Auto pause option
- Some IDs to layers that are modified

### Changed

- Target Geode 2.0.0-beta.16
- Some `static_cast`s to `as`
- CHANGELOG.md layout to "Added", "Changed" then "Fixed"
- Target any Node-IDs version that matches or is greater than 1.3.0
- Changed some for loops to getChildByID
- Renamed RouletteManager::lastLevelID to currentLevelID
- Renamed RouletteManager::lastLevelPercentage to currentLevelPercentage
- Removed Node-IDs dependency in CMakeLists.txt
- Removed RouletteManager::levelCreatorName
- Renamed about.md to ABOUT.md

### Fixed

- Goal percentage appearing in a level that isn't the current roulette level

## [1.6.0-beta.4] - 2024-02-06

### Fixed
Expand All @@ -13,7 +37,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [1.6.0-beta.3] - 2024-02-04

### Added
### Changed

- Geode 2.0.0-beta.15 support

Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ endif()

add_subdirectory($ENV{GEODE_SDK} ${CMAKE_CURRENT_BINARY_DIR}/geode)

setup_geode_mod(${PROJECT_NAME} EXTERNALS geode.node-ids:1.1.4)
setup_geode_mod(${PROJECT_NAME})

# Warnings as errors
set_property(TARGET ${PROJECT_NAME} PROPERTY COMPILE_WARNING_AS_ERROR ON)
Expand Down
12 changes: 9 additions & 3 deletions mod.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"geode": "2.0.0-beta.15",
"geode": "2.0.0-beta.16",
"gd": {
"win": "2.204",
"android": "2.205"
},
"version": "v1.6.0-beta.4",
"version": "v1.6.1-beta.1",
"id": "spaghettdev.gd-roulette",
"name": "GD-Roulette",
"developer": "SpaghettDev",
Expand All @@ -22,7 +22,7 @@
"dependencies": [
{
"id": "geode.node-ids",
"version": "v1.1.4",
"version": ">=v1.1.4",
"importance": "required"
}
],
Expand All @@ -44,6 +44,12 @@
"default": 3,
"max": 9999,
"min": 0
},
"auto-pause": {
"name": "Auto Pause",
"description": "Enable or disable auto pausing after getting the goal percentage during a round of roulette.",
"type": "bool",
"default": true
}
}
}
2 changes: 1 addition & 1 deletion src/custom_layers/ConfirmationLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ bool ConfirmationAlertLayer::init()

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

auto bg = static_cast<cocos2d::extension::CCScale9Sprite*>(
auto bg = as<cocos2d::extension::CCScale9Sprite*>(
m_mainLayer->getChildren()->objectAtIndex(0)
);
auto bgContentSize = bg->getContentSize();
Expand Down
6 changes: 3 additions & 3 deletions src/custom_layers/IntegerInputLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void IntegerInputLayer::onClose(CCObject*)
try
{
m_integer = std::stoi(
static_cast<CCTextInputNode*>(m_buttonMenu->getChildByTag(1))->getString()
as<CCTextInputNode*>(m_buttonMenu->getChildByTag(1))->getString()
);

}
Expand All @@ -115,7 +115,7 @@ void IntegerInputLayer::keyDown(enumKeyCodes key)

void IntegerInputLayer::onLeftButton(CCObject*)
{
const auto inputNode = static_cast<CCTextInputNode*>(m_buttonMenu->getChildByTag(1));
const auto inputNode = as<CCTextInputNode*>(m_buttonMenu->getChildByTag(1));

try
{
Expand All @@ -135,7 +135,7 @@ void IntegerInputLayer::onLeftButton(CCObject*)

void IntegerInputLayer::onRightButton(CCObject*)
{
const auto inputNode = static_cast<CCTextInputNode*>(m_buttonMenu->getChildByTag(1));
const auto inputNode = as<CCTextInputNode*>(m_buttonMenu->getChildByTag(1));

try
{
Expand Down
1 change: 1 addition & 0 deletions src/layers/CreatorLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class $modify(RouletteButton, CreatorLayer)
rouletteSprite->setPosition({ 22.25f, 23.75f });
rouletteButton->addChild(rouletteSprite);
rouletteButton->setPosition({ 25.f, 160.f });
rouletteButton->setID("roulette-button"_spr);

menu->addChild(rouletteButton);

Expand Down
26 changes: 19 additions & 7 deletions src/layers/LevelInfoLayer.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <list>

#include "../roulette/manager/RouletteManager.hpp"
#include "../roulette/layers/RouletteLayer.hpp"

Expand All @@ -6,15 +8,20 @@

using namespace geode::prelude;

// not a field because the field dtor crashes the game idk why
std::list<int> levelIDs{};

class $modify(LevelInfoLayer)
{
bool init(GJGameLevel* level, bool p1)
{
if (!LevelInfoLayer::init(level, p1)) return false;

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

CCLabelBMFont* normalPercentageLabel = as<CCLabelBMFont*>(this->getChildByID("normal-mode-percentage"));
float goalOffset = .0f;

// wtf v2
Expand All @@ -25,16 +32,15 @@ class $modify(LevelInfoLayer)
else
goalOffset = 39.f;

if (normalPercentageLabel == nullptr) return true;

auto goalPercentage = CCLabelBMFont::create(
fmt::format("({}%)", static_cast<int>(g_rouletteManager.levelPercentageGoal)).c_str(),
fmt::format("({}%)", g_rouletteManager.levelPercentageGoal).c_str(),
"bigFont.fnt"
);
goalPercentage->setPosition({ normalPercentageLabel->getPositionX() + goalOffset, normalPercentageLabel->getPositionY() });
goalPercentage->setScale(.4f);
goalPercentage->setColor({ 125, 125, 125 });
goalPercentage->setZOrder(3);
goalPercentage->setID("goal-progress-label"_spr);
this->addChild(goalPercentage);
}

Expand All @@ -43,13 +49,19 @@ class $modify(LevelInfoLayer)

void onBack(CCObject* sender)
{
if (g_rouletteManager.rouletteLayer)
if (levelIDs.size() != 1)
levelIDs.pop_back();

if (g_rouletteManager.isPlayingRoulette && g_rouletteManager.rouletteLayer && levelIDs.back() == g_rouletteManager.currentLevelID)
{
static_cast<CCLabelBMFont*>(
as<CCLabelBMFont*>(
g_rouletteManager.rouletteLayer->m_pPlayingMenu->getChildByTag(20)
)->setString(fmt::format("{}%", g_rouletteManager.levelPercentageGoal).c_str());
}

if (levelIDs.size() == 1)
levelIDs.pop_back();

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

if (g_rouletteManager.isPlayingRoulette)
{
const PlayLayer* playLayer = GameManager::sharedState()->getPlayLayer();
const PlayLayer* playLayer = GameManager::sharedState()->getPlayLayer();

CCNode* normalPercentageLabel = nullptr;
if (g_rouletteManager.isPlayingRoulette && playLayer->m_level->m_levelID.value() == g_rouletteManager.currentLevelID)
{
CCLabelBMFont* normalPercentageLabel = as<CCLabelBMFont*>(this->getChildByID("normal-progress-label"));
float goalOffset = 24.f;

if (playLayer->m_level->m_normalPercent < 10)
goalOffset = 28.f;
else if (playLayer->m_level->m_normalPercent <= 100)
goalOffset = 40.f;

// normal mode percentage is always first in the array
CCObject* pauseLayerObject;
CCARRAY_FOREACH(this->getChildren(), pauseLayerObject)
{
if (
auto levelInfoLayerLabel = typeinfo_cast<CCLabelBMFont*>(pauseLayerObject);
levelInfoLayerLabel &&
fmt::format("{}%", playLayer->m_level->m_normalPercent.value()) == levelInfoLayerLabel->getString()
) {
normalPercentageLabel = levelInfoLayerLabel;
break;
}
};

if (normalPercentageLabel == nullptr) return;

auto goalPercentage = CCLabelBMFont::create(
fmt::format("({}%)", static_cast<int>(g_rouletteManager.levelPercentageGoal)).c_str(),
fmt::format("({}%)", g_rouletteManager.levelPercentageGoal).c_str(),
"bigFont.fnt"
);
goalPercentage->setPosition({ normalPercentageLabel->getPositionX() + goalOffset, normalPercentageLabel->getPositionY() });
goalPercentage->setScale(.5f);
goalPercentage->setColor({ 125, 125, 125 });
goalPercentage->setZOrder(4);
goalPercentage->setID("goal-progress-label"_spr);
this->addChild(goalPercentage);
}
}
Expand Down
24 changes: 14 additions & 10 deletions src/layers/PlayLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,27 @@ class $modify(PlayLayerPause, PlayLayer)
if (
const int percentage = this->getCurrentPercentInt();
g_rouletteManager.isPlayingRoulette &&
this->m_level->m_levelID == g_rouletteManager.lastLevelID &&
this->m_level->m_levelID == g_rouletteManager.currentLevelID &&
!this->m_isPracticeMode &&
percentage >= g_rouletteManager.levelPercentageGoal
) {
if (delta > .2f/* && !this->m_player1->m_isDead*/)
{
g_rouletteManager.hasFinishedPreviousLevel = true;
g_rouletteManager.lastLevelPercentage = percentage;
g_rouletteManager.currentLevelPercentage = percentage;
g_rouletteManager.levelPercentageGoal = percentage + 1;
g_rouletteManager.numLevels++;

const auto runningScene = CCDirector::sharedDirector()->getRunningScene();
m_fields->pauseGameAction = runningScene->runAction(
CCSequence::create(
CCDelayTime::create(1.f), CCCallFunc::create(runningScene, callfunc_selector(PlayLayerPause::pause)), nullptr
)
);
if (Mod::get()->getSettingValue<bool>("auto-pause"))
{
const auto runningScene = CCDirector::sharedDirector()->getRunningScene();

m_fields->pauseGameAction = runningScene->runAction(
CCSequence::create(
CCDelayTime::create(1.f), CCCallFunc::create(runningScene, callfunc_selector(PlayLayerPause::pause)), nullptr
)
);
}
}
}

Expand All @@ -81,11 +85,11 @@ class $modify(PlayLayerPause, PlayLayer)
{
if (
g_rouletteManager.isPlayingRoulette &&
this->m_level->m_levelID == g_rouletteManager.lastLevelID &&
this->m_level->m_levelID == g_rouletteManager.currentLevelID &&
!this->m_isPracticeMode
) {
g_rouletteManager.hasFinishedPreviousLevel = true;
g_rouletteManager.lastLevelPercentage = 100;
g_rouletteManager.currentLevelPercentage = 100;
g_rouletteManager.levelPercentageGoal = 100;
g_rouletteManager.numLevels++;
}
Expand Down
24 changes: 12 additions & 12 deletions src/roulette/layers/RouletteInfoLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void RouletteInfoLayer::destroyLayerChildren()
{
for (unsigned int i = 0; i < this->getChildrenCount(); i++)
{
auto node = static_cast<CCNode*>(this->getChildren()->objectAtIndex(0));
auto node = as<CCNode*>(this->getChildren()->objectAtIndex(0));
node->removeFromParentAndCleanup(true);
}

Expand All @@ -106,8 +106,8 @@ void RouletteInfoLayer::onToggleButton(CCObject* sender)
{
sender->retain();

auto button = static_cast<CCMenuItemToggler*>(sender);
auto parent = static_cast<CCMenu*>(button->getParent());
auto button = as<CCMenuItemToggler*>(sender);
auto parent = as<CCMenu*>(button->getParent());
auto ind = roulette::utils::getIndexOf(g_rouletteManager.getFromSaveContainer("selected-list-array").as_array(), true);

g_rouletteManager.getFromSaveContainer("selected-list-array").as_array().at(ind) = false;
Expand All @@ -117,10 +117,10 @@ void RouletteInfoLayer::onToggleButton(CCObject* sender)
switch (button->getTag())
{
case 0:
static_cast<CCMenuItemSpriteExtra*>(
as<CCMenuItemSpriteExtra*>(
g_rouletteManager.rouletteLayer->m_pMainMenu->getChildByTag(4)
)->setColor({ 125, 125, 125 });
static_cast<CCMenuItemSpriteExtra*>(
as<CCMenuItemSpriteExtra*>(
g_rouletteManager.rouletteLayer->m_pMainMenu->getChildByTag(5)
)->setColor({ 125, 125, 125 });

Expand All @@ -130,25 +130,25 @@ void RouletteInfoLayer::onToggleButton(CCObject* sender)
break;

case 1:
static_cast<CCMenuItemSpriteExtra*>(
as<CCMenuItemSpriteExtra*>(
g_rouletteManager.rouletteLayer->m_pMainMenu->getChildByTag(g_rouletteManager.previousDifficulty)
)->setColor({ 125, 125, 125 });
static_cast<CCMenuItemSpriteExtra*>(
as<CCMenuItemSpriteExtra*>(
g_rouletteManager.rouletteLayer->m_pMainMenu->getChildByTag(4)
)->setColor({ 125, 125, 125 });
static_cast<CCMenuItemSpriteExtra*>(
as<CCMenuItemSpriteExtra*>(
g_rouletteManager.rouletteLayer->m_pMainMenu->getChildByTag(5)
)->setColor({ 255, 255, 255 });
break;

case 2:
static_cast<CCMenuItemSpriteExtra*>(
as<CCMenuItemSpriteExtra*>(
g_rouletteManager.rouletteLayer->m_pMainMenu->getChildByTag(g_rouletteManager.previousDifficulty)
)->setColor({ 125, 125, 125 });
static_cast<CCMenuItemSpriteExtra*>(
as<CCMenuItemSpriteExtra*>(
g_rouletteManager.rouletteLayer->m_pMainMenu->getChildByTag(4)
)->setColor({ 255, 255, 255 });
static_cast<CCMenuItemSpriteExtra*>(
as<CCMenuItemSpriteExtra*>(
g_rouletteManager.rouletteLayer->m_pMainMenu->getChildByTag(5)
)->setColor({ 125, 125, 125 });
break;
Expand All @@ -162,7 +162,7 @@ void RouletteInfoLayer::onNumSkipsButton(CCObject*)
{
m_integer_input_layer->setup({
"Number Of Skips", "Skips",
0, 3, 9999, static_cast<int>(Mod::get()->getSettingValue<int64_t>("max-skips")),
0, 3, 9999, as<int>(Mod::get()->getSettingValue<int64_t>("max-skips")),
[&](auto iil) {
Mod::get()->setSettingValue<int64_t>("max-skips", iil->m_integer);
}
Expand Down
Loading

0 comments on commit 34712e2

Please sign in to comment.