Skip to content

Commit

Permalink
wstringless on android
Browse files Browse the repository at this point in the history
  • Loading branch information
Alphalaneous committed Mar 7, 2024
1 parent b1760ff commit 7db06d5
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/ui/hooks/MenuLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,22 @@ class $modify(MyMenuLayer, MenuLayer) {
this->addChild(creatorName);
creatorName->setID("copyright-text"_spr);

#ifdef GEODE_IS_WINDOWS

std::wstring text = Utils::getSplashText();

MinecraftLabel* splashText = MinecraftLabel::create(text, "minecraft.fnt"_spr);

#endif

#ifdef GEODE_IS_ANDROID

std::string text = Utils::getSplashText();

MinecraftLabel* splashText = MinecraftLabel::create(text, "minecraft.fnt"_spr);

#endif

splashText->setColor({255,255,0});
splashText->setPosition({title->getContentSize().width,(title->getContentSize().height) /2});
splashText->setZOrder(3);
Expand Down
55 changes: 55 additions & 0 deletions src/utils/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class Utils {
return dirt;
}

#ifdef GEODE_IS_WINDOWS

static std::vector<std::wstring> splitString(const std::wstring& str, const std::wstring& delimiter) {
std::vector<std::wstring> strings;

Expand All @@ -103,6 +105,28 @@ class Utils {
return strings;
}

#endif

#ifdef GEODE_IS_ANDROID

static std::vector<std::string> splitString(const std::string& str, const std::string& delimiter) {
std::vector<std::string> strings;

std::string::size_type pos = 0;
std::string::size_type prev = 0;
while ((pos = str.find(delimiter, prev)) != std::string::npos)
{
strings.push_back(str.substr(prev, pos - prev));
prev = pos + delimiter.size();
}

strings.push_back(str.substr(prev));

return strings;
}

#endif

static int random(int min, int max) {
std::random_device dev;
std::mt19937 rng(dev());
Expand All @@ -122,6 +146,8 @@ class Utils {
return result;
}

#ifdef GEODE_IS_WINDOWS

inline static std::vector<std::wstring> splashSplit;
inline static bool hasBeenGenerated = false;

Expand All @@ -144,4 +170,33 @@ class Utils {

return newSplash;
}

#endif

#ifdef GEODE_IS_ANDROID

inline static std::vector<std::string> splashSplit;
inline static bool hasBeenGenerated = false;

static std::string getSplashText(){
if(!hasBeenGenerated){
ghc::filesystem::path path = Mod::get()->getResourcesDir().append("splashes.txt");

std::ifstream input(path.string());
std::stringstream buffer;
buffer << input.rdbuf();
input.close();

std::string splashText = buffer.str();

splashSplit = Utils::splitString(splashText, L"\n");
hasBeenGenerated = true;
}

std::string newSplash = splashSplit.at(random(0, splashSplit.size()-1));

return newSplash;
}

#endif
};

0 comments on commit 7db06d5

Please sign in to comment.