Skip to content

Commit

Permalink
Icon Randomizer API
Browse files Browse the repository at this point in the history
  • Loading branch information
kittenchilly committed Jul 12, 2024
1 parent f0f949c commit 80a5b16
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 181 deletions.
2 changes: 1 addition & 1 deletion about.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ For people that really can't decide what to use.
- GLOBED: Player indicator in progress bar doesn't update when icon is randomized in a level

# Credits
hiimjustin000 - Most of the randomization code is from their Better Icon Randomizer. Go check it out too!
hiimjustin000 - Icon Randomizer API and initial inspiration, check out their Better Icon Randomizer mod!
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v1.2.0
- Icon randomization is now done through Icon Randomizer API by hiimjustin000 (new dependency)
- The optional p2/dual randomization is now done through and requires Seperate Dual Icons by Weebify, instead of being a setting.

# v1.1.2
- More accurate particles and trails
- More accurate glow randomization
Expand Down
17 changes: 8 additions & 9 deletions mod.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"geode": "3.1.1",
"geode": "3.2.0",
"gd": {
"win": "2.206",
"android": "2.206",
Expand All @@ -8,16 +8,15 @@
},
"id": "kittenchilly.randomize_icon_on_death",
"name": "Randomize Icon on Death",
"version": "v1.1.2",
"version": "v1.2.0",
"developer": "kittenchilly",
"description": "Randomizes your icons and colors everytime you die",
"repository": "https://github.com/kittenchilly/Randomize-Icon-on-Death",
"settings": {
"random-p2": {
"name": "Random P2",
"description": "If P2/Dual should also be a completely random icon, rather than P1's icon with colors inverted",
"type": "bool",
"default": false
"dependencies": [
{
"id": "hiimjustin000.icon_randomizer_api",
"version": ">=1.0.0",
"importance": "required"
}
}
]
}
188 changes: 17 additions & 171 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,138 +1,9 @@
#include <Geode/Geode.hpp>
#include <hiimjustin000.icon_randomizer_api/include/IconRandomizer.hpp>
#include <Geode/modify/PlayLayer.hpp>
#include <Geode/modify/GJBaseGameLayer.hpp>
#include <Geode/modify/PlayerObject.hpp>
#include <random>

using namespace geode::prelude;

inline static std::map<UnlockType, std::vector<int>> UNLOCKED = {
{ UnlockType::Cube, {} },
{ UnlockType::Col1, {} },
{ UnlockType::Col2, {} },
{ UnlockType::Ship, {} },
{ UnlockType::Ball, {} },
{ UnlockType::Bird, {} },
{ UnlockType::Dart, {} },
{ UnlockType::Robot, {} },
{ UnlockType::Spider, {} },
{ UnlockType::Streak, {} },
{ UnlockType::Death, {} },
{ UnlockType::GJItem, {} },
{ UnlockType::Swing, {} },
{ UnlockType::Jetpack, {} },
{ UnlockType::ShipFire, {} }
};

int randomNumber(int start, int end) {
std::random_device os_seed;
const unsigned int seed = os_seed();

std::mt19937 generator(seed);
std::uniform_int_distribution<int> distribute(start, end);

return distribute(generator);
}

void setupUnlockedIcons(IconType iconType) {
auto gameManager = GameManager::sharedState();
auto& vec = UNLOCKED[gameManager->iconTypeToUnlockType(iconType)];
vec.clear();
auto amount = iconType == IconType::Item ? 20 : gameManager->countForType(iconType);
for (int i = iconType == IconType::Item ? 18 : 1; i <= amount; i++) {
if (gameManager->isIconUnlocked(i, iconType)) vec.push_back(i);
}
}

void setupUnlockedColors(UnlockType unlockType) {
auto gameManager = GameManager::sharedState();
auto& vec = UNLOCKED[unlockType];
vec.clear();
for (int i = 0; i < 107; i++) {
if (gameManager->isColorUnlocked(i, unlockType)) vec.push_back(i);
}
}

void setupUnlocked() {
setupUnlockedIcons(IconType::Cube);
setupUnlockedColors(UnlockType::Col1);
setupUnlockedColors(UnlockType::Col2);
setupUnlockedIcons(IconType::Ship);
setupUnlockedIcons(IconType::Ball);
setupUnlockedIcons(IconType::Ufo);
setupUnlockedIcons(IconType::Wave);
setupUnlockedIcons(IconType::Robot);
setupUnlockedIcons(IconType::Spider);
setupUnlockedIcons(IconType::Special);
setupUnlockedIcons(IconType::DeathEffect);
setupUnlockedIcons(IconType::Item);
setupUnlockedIcons(IconType::Swing);
setupUnlockedIcons(IconType::Jetpack);
setupUnlockedIcons(IconType::ShipFire);
}

void randomize(UnlockType unlockType) {
auto& vec = UNLOCKED[unlockType];
if (unlockType == UnlockType::GJItem) {
auto gameStatsManager = GameStatsManager::sharedState();
for (int i = 0; i < vec.size(); i++) {
gameStatsManager->toggleEnableItem(unlockType, vec[i], randomNumber(0, 1));
}
return;
}
auto gameManager = GameManager::sharedState();
auto num = vec[(size_t)randomNumber(0, vec.size() - 1)];
switch (unlockType) {
case UnlockType::Cube:
gameManager->setPlayerFrame(num);
break;
case UnlockType::Col1:
gameManager->setPlayerColor(num);
break;
case UnlockType::Col2:
gameManager->setPlayerColor2(num);

//glow
num = vec[(size_t)randomNumber(0, vec.size() - 1)];
gameManager->m_playerGlowColor = num;
break;
case UnlockType::Ship:
gameManager->setPlayerShip(num);
break;
case UnlockType::Ball:
gameManager->setPlayerBall(num);
break;
case UnlockType::Bird:
gameManager->setPlayerBird(num);
break;
case UnlockType::Dart:
gameManager->setPlayerDart(num);
break;
case UnlockType::Robot:
gameManager->setPlayerRobot(num);
break;
case UnlockType::Spider:
gameManager->setPlayerSpider(num);
break;
case UnlockType::Streak:
gameManager->setPlayerStreak(num);
break;
case UnlockType::Death:
gameManager->setPlayerDeathEffect(num);
gameManager->loadDeathEffect(num);
break;
case UnlockType::Swing:
gameManager->setPlayerSwing(num);
break;
case UnlockType::Jetpack:
gameManager->setPlayerJetpack(num);
break;
case UnlockType::ShipFire:
gameManager->setPlayerShipStreak(num);
break;
}
}

void updateFrames(PlayerObject* player)
{
auto gameManager = GameManager::sharedState();
Expand Down Expand Up @@ -167,24 +38,13 @@ class $modify(PlayLayer) {

void resetLevel() {
auto gameManager = GameManager::sharedState();
auto separateDualIconsLoaded = Loader::get()->getLoadedMod("weebify.separate_dual_icons");

IconRandomizer::init();

setupUnlocked();

randomize(UnlockType::Cube);
randomize(UnlockType::Col1);
randomize(UnlockType::Col2);
randomize(UnlockType::Ship);
randomize(UnlockType::Ball);
randomize(UnlockType::Bird);
randomize(UnlockType::Dart);
randomize(UnlockType::Robot);
randomize(UnlockType::Spider);
randomize(UnlockType::Streak);
randomize(UnlockType::Death);
randomize(UnlockType::GJItem);
randomize(UnlockType::Swing);
randomize(UnlockType::Jetpack);
randomize(UnlockType::ShipFire);
IconRandomizer::randomizeAll(ICON_RANDOMIZER_API_ALL_ICONS);
IconRandomizer::randomizeAll(ICON_RANDOMIZER_API_ALL_SPECIAL);
IconRandomizer::randomizeAll(ICON_RANDOMIZER_API_ALL_COLORS);

updateFrames(m_player1);
updateFrames(m_player2);
Expand All @@ -203,34 +63,20 @@ class $modify(PlayLayer) {
m_player1->updateGlowColor();
m_player2->updateGlowColor();

//m_player1->addAllParticles();
//m_player2->addAllParticles();
// m_player1->addAllParticles();
// m_player2->addAllParticles();

if (Mod::get()->getSettingValue<bool>("random-p2"))
if (separateDualIconsLoaded)
{
setupUnlocked();

randomize(UnlockType::Cube);
randomize(UnlockType::Col1);
randomize(UnlockType::Col2);
randomize(UnlockType::Ship);
randomize(UnlockType::Ball);
randomize(UnlockType::Bird);
randomize(UnlockType::Dart);
randomize(UnlockType::Robot);
randomize(UnlockType::Spider);
randomize(UnlockType::Streak);
//randomize(UnlockType::Death);
//randomize(UnlockType::GJItem);
randomize(UnlockType::Swing);
randomize(UnlockType::Jetpack);
randomize(UnlockType::ShipFire);
IconRandomizer::init();

updateFrames(m_player2);

int color1 = gameManager->getPlayerColor();
int color2 = gameManager->getPlayerColor2();
IconRandomizer::randomizeAll(ICON_RANDOMIZER_API_ALL_ICONS, true);
IconRandomizer::randomizeAll(ICON_RANDOMIZER_API_ALL_SPECIAL, true);
IconRandomizer::randomizeAll(ICON_RANDOMIZER_API_ALL_COLORS, true);

color1 = gameManager->getPlayerColor();
color2 = gameManager->getPlayerColor2();
updateFrames(m_player2);
m_player2->setColor(gameManager->colorForIdx(color1));
m_player2->setSecondColor(gameManager->colorForIdx(color2));
m_player2->m_glowColor = gameManager->colorForIdx(gameManager->m_playerGlowColor);
Expand Down

0 comments on commit 80a5b16

Please sign in to comment.