Skip to content

Commit

Permalink
backup changes
Browse files Browse the repository at this point in the history
  • Loading branch information
RayDeeUx committed Dec 7, 2024
1 parent 66b2331 commit 669ea9e
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 52 deletions.
37 changes: 30 additions & 7 deletions src/EndLevelLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
using namespace geode::prelude;

class $modify(MyEndLevelLayer, EndLevelLayer) {
static const char* grabRandomQuote(std::vector<std::string> vector = Manager::getSharedInstance()->quotes) {
std::mt19937 randomSeed(std::random_device{}());
std::shuffle(vector.begin(), vector.end(), randomSeed);
return vector.front().c_str();
}
CCSprite* getHideButtonSprite() {
return typeinfo_cast<CCSprite*>(getChildByIDRecursive("hide-button")->getChildren()->objectAtIndex(0));
}
Expand Down Expand Up @@ -183,12 +178,39 @@ class $modify(MyEndLevelLayer, EndLevelLayer) {
}
}
*/
void applyCustomLevelCompleteText(const std::string_view matchPlayLayer) {
if (!getModBool("customLevelCompleteText") || !getModBool("enabled")) return;
const auto lvlCompleteText = typeinfo_cast<CCSprite*>(getChildByIDRecursive("level-complete-text"));
if (!lvlCompleteText) return;
Manager* manager = managerMacro;
auto origOpacity = lvlCompleteText->getOpacity();
lvlCompleteText->setOpacity(0);
if (getModString("alsoReplacePlayLayerLCT") == "Separate From EndLevelLayer") manager->generateNewSprites(getModString("customLCTMode"));
if (manager->chosenMode == "Images" && !manager->sharedReplacementSprite.empty()) {
CCSprite* newSprite = CCSprite::create(manager->sharedReplacementSprite.c_str());
lvlCompleteText->addChild(newSprite);
lvlCompleteText->updateLayout();
newSprite->setPosition(lvlCompleteText->getContentSize() / 2.f);
newSprite->setID("custom-level-complete-sprite-endlevellayer"_spr);
} else if (manager->chosenMode == "Oxygene One" && !manager->sharedReplacementLabel.empty()) {
CCLabelBMFont* newLabel = CCLabelBMFont::create(manager->sharedReplacementLabel.c_str(), "levelCompleteFont.fnt"_spr);
newLabel->setExtraKerning(5);
newLabel->limitLabelWidth(380.f, 1.0f, 0.25f);
lvlCompleteText->addChild(newLabel);
lvlCompleteText->updateLayout();
newLabel->setPosition(lvlCompleteText->getContentSize() / 2.f);
newLabel->setID("custom-level-complete-label-endlevellayer"_spr);
} else {
lvlCompleteText->setOpacity(origOpacity);
return log::info("failed. manager->chosenMode: {}", manager->chosenMode);
}
}
void applyRandomQuoteAndFont(PlayLayer* playLayer, GJGameLevel* theLevel) {
auto endTextLabel = typeinfo_cast<CCLabelBMFont*>(getChildByIDRecursive("end-text"));
if (!endTextLabel) return;
Manager* manager = managerMacro;
std::string randomString = MyEndLevelLayer::grabRandomQuote();
if (!manager->customQuotes.empty() && getModBool("customTextsOnly")) randomString = MyEndLevelLayer::grabRandomQuote(manager->customQuotes);
std::string randomString = manager->grabRandomString();
if (!manager->customQuotes.empty() && getModBool("customTextsOnly")) randomString = manager->grabRandomString(manager->customQuotes);
if ("Make sure to screenshot this win!" == randomString) {
#ifdef GEODE_IS_MACOS
randomString = "Press Command + Shift + 3 to screenshot this win!";
Expand Down Expand Up @@ -255,5 +277,6 @@ class $modify(MyEndLevelLayer, EndLevelLayer) {
auto playLayer = PlayLayer::get();
if (!playLayer) return;
if (getModBool("endTexts")) MyEndLevelLayer::applyRandomQuoteAndFont(playLayer, playLayer->m_level);
if (getModBool("customLevelCompleteText")) MyEndLevelLayer::applyCustomLevelCompleteText(getModString("alsoReplacePlayLayerLCT"));
}
};
40 changes: 37 additions & 3 deletions src/Manager.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include <random>

// Manager.hpp structure by acaruso
// reused with explicit permission and strong encouragement
Expand Down Expand Up @@ -34,14 +35,47 @@ class Manager {

float compactEndscreenFallbackPosition = CCDirector::get()->getWinSize().width * 0.6f;

CCLabelBMFont* sharedReplacementLabel = nullptr;
CCSprite* sharedReplacementSprite = nullptr;
std::string sharedReplacementLabel = "";
std::string sharedReplacementSprite = "";
std::string chosenMode = "";

static Manager* getSharedInstance() {
if (!instance) {
instance = new Manager();
}
return instance;
}

static bool isSupportedExtension(const std::string& fileName) {
return !fileName.empty() && (geode::utils::string::endsWith(fileName, ".png") || geode::utils::string::endsWith(fileName, ".jpg"));
}
static std::string grabRandomString(std::vector<std::string> vector = getSharedInstance()->quotes) {
std::mt19937 randomSeed(std::random_device{}());
std::shuffle(vector.begin(), vector.end(), randomSeed);
return vector.front();
}
static void generateNewSprites(std::string customLCTMode) {
Manager* manager = getSharedInstance();
log::info("customLCTMode: {}", customLCTMode);
if (customLCTMode == "Combined" || customLCTMode == "Images") {
if (!manager->customLevelCompleteSprites.empty()) manager->customLevelCompleteSprites.clear();
for (const auto& file : std::filesystem::directory_iterator((Mod::get()->getConfigDir() / R"(levelCompleteImages)").string())) {
if (isSupportedExtension(file.path().extension().string())) {
manager->customLevelCompleteSprites.push_back(file.path().string());
}
}
std::string chosenSprite; // init sprite
if (!manager->customLevelCompleteSprites.empty()) chosenSprite = grabRandomString(manager->customLevelCompleteSprites);
else if (customLCTMode == "Images" && chosenSprite.empty()) return; // return early if no file name was selected even though user selected "Images" mode
manager->sharedReplacementSprite = chosenSprite;
}
if (customLCTMode == "Combined" || customLCTMode == "Oxygene One") {
manager->sharedReplacementLabel = Mod::get()->getSettingValue<bool>("customLevelCompleteTextsOnly") ? grabRandomString(manager->customLevelCompleteQuotes) : grabRandomString(manager->levelCompleteQuotes);
}
if (customLCTMode == "Combined") customLCTMode = manager->grabRandomString(manager->knownCLCTModesBesidesCombined);
log::info("customLCTMode: {} (should not be Combined)", customLCTMode);
if (customLCTMode == "Combined") {
return log::info("something went terribly wrong --- check contents of the `manager->knownCLCTModesBesidesCombined` vector");
}
manager->chosenMode = customLCTMode;
}
};
73 changes: 31 additions & 42 deletions src/PlayLayer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <Geode/modify/PlayLayer.hpp>
#include <random>
#include "Manager.hpp"

#define getModBool Mod::get()->getSettingValue<bool>
Expand All @@ -9,14 +8,6 @@
using namespace geode::prelude;

class $modify(MyPlayLayer, PlayLayer) {
static std::string grabRandomString(std::vector<std::string> vector = managerMacro->quotes) {
std::mt19937 randomSeed(std::random_device{}());
std::shuffle(vector.begin(), vector.end(), randomSeed);
return vector.front();
}
static bool isSupportedExtension(const std::string& fileName) {
return !fileName.empty() && (geode::utils::string::endsWith(fileName, ".png") || geode::utils::string::endsWith(fileName, ".jpg"));
}
void levelComplete() {
if (!m_level) return PlayLayer::levelComplete();
Manager* manager = managerMacro;
Expand All @@ -26,12 +17,16 @@ class $modify(MyPlayLayer, PlayLayer) {
PlayLayer::levelComplete();
}
void onQuit() {
Manager::getSharedInstance()->lastFlukedPercent = 0;
Manager* manager = managerMacro;
manager->lastFlukedPercent = 0;
manager->sharedReplacementSprite = "";
manager->sharedReplacementLabel = "";
manager->chosenMode = "";
PlayLayer::onQuit();
}
void showCompleteText() {
PlayLayer::showCompleteText();
if (!m_level || !getModBool("enabled") || !getModBool("customLevelCompleteText") || getModString("alsoReplacePlayLayerLCT") == "Disabled") return;
if (!m_level || !getModBool("enabled") || !getModBool("customLevelCompleteText")) return;
Manager* manager = managerMacro;
CCSprite* toModify = nullptr;
for (const auto node : CCArrayExt<CCNode*>(this->getChildren())) {
Expand All @@ -41,41 +36,35 @@ class $modify(MyPlayLayer, PlayLayer) {
}
}
if (!toModify) return;
std::string customLCTMode = getModString("customLCTMode");
auto originalOpacity = toModify->getOpacity();
std::string customLCTModePlayLayer = getModString("customLCTMode");
bool lctReplaced = false;
manager->generateNewSprites(customLCTModePlayLayer);
// "omg ery why not just choose a mode first???"
// assigning it to manager = easier "shared replacement" with EndLevelLayer later
if (getModString("alsoReplacePlayLayerLCT") == "Disabled") return;
auto origOpacity = toModify->getOpacity();
toModify->setOpacity(0);
if (customLCTMode == "Combined" || customLCTMode == "Images") {
if (!manager->customLevelCompleteSprites.empty()) manager->customLevelCompleteSprites.clear();
for (const auto& file : std::filesystem::directory_iterator((Mod::get()->getConfigDir() / R"(levelCompleteImages)").string())) {
if (isSupportedExtension(file.path().extension().string())) {
manager->customLevelCompleteSprites.push_back(file.path().string());
}
}
std::string chosenSprite; // init sprite
if (!manager->customLevelCompleteSprites.empty()) chosenSprite = grabRandomString(manager->customLevelCompleteSprites);
else if (customLCTMode == "Images" && chosenSprite.empty()) return toModify->setOpacity(originalOpacity); // return early if no file name was selected even though user selected "Images" mode
manager->sharedReplacementSprite = CCSprite::create(chosenSprite.c_str());
}
if (customLCTMode == "Combined" || customLCTMode == "Oxygene One") {
std::string customQuote = getModBool("customLevelCompleteTextsOnly") ? grabRandomString(manager->customLevelCompleteQuotes) : grabRandomString(manager->levelCompleteQuotes);
CCLabelBMFont* replacementLabel = CCLabelBMFont::create(customQuote.c_str(), "levelCompleteFont.fnt"_spr);
replacementLabel->setExtraKerning(5);
manager->sharedReplacementLabel = replacementLabel;
}
if (customLCTMode == "Combined") customLCTMode = grabRandomString(manager->knownCLCTModesBesidesCombined);
if (customLCTMode == "Oxygene One" && manager->sharedReplacementLabel && !lctReplaced) {
toModify->addChild(manager->sharedReplacementLabel);
manager->sharedReplacementLabel->setPosition(toModify->getContentSize() / 2.f);
manager->sharedReplacementLabel->limitLabelWidth(370.f, 1.0f, 0.25f);
manager->sharedReplacementLabel->setID("custom-level-complete-label-playlayer"_spr);
if (manager->chosenMode == "Images" && !manager->sharedReplacementSprite.empty() && !lctReplaced) {
CCSprite* newSprite = CCSprite::create(manager->sharedReplacementSprite.c_str());
toModify->addChild(newSprite);
toModify->updateLayout();
newSprite->setPosition(toModify->getContentSize() / 2.f);
newSprite->setID("custom-level-complete-sprite-playlayer"_spr);
lctReplaced = true;
} else if (customLCTMode == "Images" && manager->sharedReplacementSprite && !lctReplaced) {
toModify->addChild(manager->sharedReplacementSprite);
manager->sharedReplacementSprite->setPosition(toModify->getContentSize() / 2.f);
manager->sharedReplacementSprite->setID("custom-level-complete-sprite-playlayer"_spr);
}
if (manager->chosenMode == "Oxygene One" && !manager->sharedReplacementLabel.empty() && !lctReplaced) {
CCLabelBMFont* newLabel = CCLabelBMFont::create(manager->sharedReplacementLabel.c_str(), "levelCompleteFont.fnt"_spr);
newLabel->setExtraKerning(5);
newLabel->limitLabelWidth(380.f, 1.0f, 0.25f);
toModify->addChild(newLabel);
toModify->updateLayout();
newLabel->setPosition(toModify->getContentSize() / 2.f);
newLabel->setID("custom-level-complete-label-playlayer"_spr);
lctReplaced = true;
}
if (!lctReplaced) return toModify->setOpacity(originalOpacity);
if (!lctReplaced) {
toModify->setOpacity(origOpacity);
return log::info("failed replacing sprite. customLCTMode: {} | manager->chosenMode: {}", customLCTModePlayLayer, manager->chosenMode);
}
}
};

0 comments on commit 669ea9e

Please sign in to comment.