Skip to content

Commit

Permalink
implement utils except file utils but i tried ok
Browse files Browse the repository at this point in the history
  • Loading branch information
altalk23 committed Oct 3, 2023
1 parent d194cbe commit a985d5a
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 5 deletions.
2 changes: 1 addition & 1 deletion loader/src/platform/android/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extern "C" [[gnu::visibility("default")]] jint JNI_OnLoad(JavaVM* vm, void* rese
glDeleteVertexArraysOESEXT = (PFNGLDELETEVERTEXARRAYSOESPROC)eglGetProcAddress("glDeleteVertexArraysOES");

geodeEntry(nullptr);
return JNI_VERSION_1_1;
return JNI_VERSION_1_6;
}

extern "C" [[gnu::visibility("default")]] void emptyFunction(void*) {
Expand Down
77 changes: 74 additions & 3 deletions loader/src/platform/android/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,41 @@ using namespace geode::prelude;
#include <Geode/utils/web.hpp>
#include <ghc/filesystem.hpp>

#include <jni.h>
#include <Geode/cocos/platform/android/jni/JniHelper.h>

bool utils::clipboard::write(std::string const& data) {
JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, "com/geode/launcher/utils/GeodeUtils", "writeClipboard", "(Ljava/lang/String;)V")) {
jstring stringArg1 = t.env->NewStringUTF(data.c_str());

t.env->CallStaticVoidMethod(t.classID, t.methodID, stringArg1);

t.env->DeleteLocalRef(stringArg1);
t.env->DeleteLocalRef(t.classID);
return true;
}
return false;
}

std::string utils::clipboard::read() {
JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, "com/geode/launcher/utils/GeodeUtils", "readClipboard", "()Ljava/lang/String;")) {
jstring stringResult = (jstring)t.env->CallStaticObjectMethod(t.classID, t.methodID);

std::string result = JniHelper::jstring2string(stringResult);

t.env->DeleteLocalRef(stringResult);
t.env->DeleteLocalRef(t.classID);
return result;
}
return "";
}

CCPoint cocos::getMousePos() {
return CCPoint(0, 0);
}

ghc::filesystem::path dirs::getGameDir() {
return ghc::filesystem::path(
"/storage/emulated/0/Android/data/com.geode.launcher/files/game"
Expand Down Expand Up @@ -44,7 +71,17 @@ void utils::web::openLinkInBrowser(std::string const& url) {
CCApplication::sharedApplication()->openURL(url.c_str());
}

bool utils::file::openFolder(ghc::filesystem::path const&) {
bool utils::file::openFolder(ghc::filesystem::path const& path) {
JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, "com/geode/launcher/utils/GeodeUtils", "openFolder", "(Ljava/lang/String;)Z")) {
jstring stringArg1 = t.env->NewStringUTF(path.string().c_str());

jboolean result = t.env->CallStaticBooleanMethod(t.classID, t.methodID, stringArg1);

t.env->DeleteLocalRef(stringArg1);
t.env->DeleteLocalRef(t.classID);
return result;
}
return false;
}

Expand All @@ -58,16 +95,50 @@ void geode::utils::game::launchLoaderUninstaller(bool deleteSaveData) {
}

void geode::utils::game::exit() {
if (CCApplication::sharedApplication() &&
(GameManager::get()->m_playLayer || GameManager::get()->m_levelEditorLayer)) {
log::error("Cannot exit in PlayLayer or LevelEditorLayer!");
return;
}
AppDelegate::get()->trySaveGame();
// AppDelegate::get()->showLoadingCircle(false, true);

CCDirector::get()->getActionManager()->addAction(CCSequence::create(
CCDelayTime::create(0.5f),
CCCallFunc::create(nullptr, callfunc_selector(MenuLayer::endGame)),
nullptr
), CCDirector::get()->getRunningScene(), false);;
), CCDirector::get()->getRunningScene(), false);
}

void geode::utils::game::restart() {
if (CCApplication::sharedApplication() &&
(GameManager::get()->m_playLayer || GameManager::get()->m_levelEditorLayer)) {
log::error("Cannot restart in PlayLayer or LevelEditorLayer!");
return;
}

class Exit : public CCObject {
public:
void restart() {
JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, "com/geode/launcher/utils/GeodeUtils", "restartGame", "()V")) {
t.env->CallStaticVoidMethod(t.classID, t.methodID);

t.env->DeleteLocalRef(t.classID);
}
}
};
// Not implemented
log::error("Restarting the game is not implemented on android");
// log::error("Restarting the game is not implemented on android");

AppDelegate::get()->trySaveGame();
// AppDelegate::get()->showLoadingCircle(false, true);

CCDirector::get()->getActionManager()->addAction(CCSequence::create(
CCDelayTime::create(0.5f),
CCCallFunc::create(nullptr, callfunc_selector(Exit::restart)),
nullptr
), CCDirector::get()->getRunningScene(), false);
}

#endif
2 changes: 1 addition & 1 deletion loader/src/platform/mac/util.mm
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ @implementation FileDialog
void geode::utils::game::exit() {
if (CCApplication::sharedApplication() &&
(GameManager::get()->m_playLayer || GameManager::get()->m_levelEditorLayer)) {
log::error("Cannot restart in PlayLayer or LevelEditorLayer!");
log::error("Cannot exit in PlayLayer or LevelEditorLayer!");
return;
}

Expand Down

0 comments on commit a985d5a

Please sign in to comment.