From 72b2fcd4eb802e4d80e72ed8f39dbf865e6dafab Mon Sep 17 00:00:00 2001 From: fysx Date: Wed, 22 Oct 2014 11:54:04 +0200 Subject: [PATCH] Added loading of games by opening the main.lua file --- .../src/modules/filesystem/physfs/Filesystem.cpp | 10 +++++++--- src/org/love2d/android/GameActivity.java | 14 +++++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/jni/love/src/modules/filesystem/physfs/Filesystem.cpp b/jni/love/src/modules/filesystem/physfs/Filesystem.cpp index b8e93521..038557a2 100644 --- a/jni/love/src/modules/filesystem/physfs/Filesystem.cpp +++ b/jni/love/src/modules/filesystem/physfs/Filesystem.cpp @@ -327,12 +327,16 @@ bool Filesystem::setSource(const char *source) SDL_Log ("Error creating storage directories!"); } + std::string game_path = std::string(love::android::getSelectedGameFile()); + if (game_path == "") + game_path = "/sdcard/lovegame/"; + if (!androidMountSelectedGame() && !androidMountAssetGame()) { - SDL_RWops *sdcard_main = SDL_RWFromFile("/sdcard/lovegame/main.lua", "rb"); + SDL_RWops *sdcard_main = SDL_RWFromFile(std::string(game_path + "main.lua").c_str(), "rb"); if (sdcard_main) { - SDL_Log ("using game from /sdcard/lovegame"); - new_search_path = "/sdcard/lovegame"; + SDL_Log ("using game from %s", game_path.c_str()); + new_search_path = game_path; sdcard_main->close(sdcard_main); if (!PHYSFS_addToSearchPath(new_search_path.c_str(), 1)) { diff --git a/src/org/love2d/android/GameActivity.java b/src/org/love2d/android/GameActivity.java index a1cb5e42..a507b3d2 100644 --- a/src/org/love2d/android/GameActivity.java +++ b/src/org/love2d/android/GameActivity.java @@ -2,6 +2,7 @@ package org.love2d.android; import org.libsdl.app.SDLActivity; +import java.util.List; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.FileOutputStream; @@ -45,11 +46,18 @@ public class GameActivity extends SDLActivity { Uri game = this.getIntent().getData(); if (game != null) { if (game.getScheme().equals ("file")) { - gamePath = game.getPath(); + // If we were given the path of a main.lua then use its + // directory. Otherwise use full path. + List path_segments = game.getPathSegments(); + if (path_segments.get(path_segments.size() - 1).equals("main.lua")) { + gamePath = game.getPath().substring(0, game.getPath().length() - "main.lua".length()); + } else { + gamePath = game.getPath(); + } } else { copyGameToCache (game); } - Log.d("GameActivity", "Selected the file: " + getGamePath()); + Log.d("GameActivity", "Opening game from: " + getGamePath()); } super.onCreate(savedInstanceState); @@ -72,7 +80,7 @@ public class GameActivity extends SDLActivity { public static String getGamePath() { Log.d ("GameActivity", "called getGamePath(), game path = " + gamePath); - return gamePath; + return gamePath; } public static DisplayMetrics getMetrics() {