Przeglądaj źródła

Added loading of games by opening the main.lua file

fysx 11 lat temu
rodzic
commit
72b2fcd4eb

+ 7 - 3
jni/love/src/modules/filesystem/physfs/Filesystem.cpp

@@ -327,12 +327,16 @@ bool Filesystem::setSource(const char *source)
 		SDL_Log ("Error creating storage directories!");
 		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()) {
 	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) {
 		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);
 			sdcard_main->close(sdcard_main);
 
 
 			if (!PHYSFS_addToSearchPath(new_search_path.c_str(), 1)) {
 			if (!PHYSFS_addToSearchPath(new_search_path.c_str(), 1)) {

+ 11 - 3
src/org/love2d/android/GameActivity.java

@@ -2,6 +2,7 @@ package org.love2d.android;
 
 
 import org.libsdl.app.SDLActivity;
 import org.libsdl.app.SDLActivity;
 
 
+import java.util.List;
 import java.io.BufferedInputStream;
 import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
 import java.io.BufferedOutputStream;
 import java.io.FileOutputStream;
 import java.io.FileOutputStream;
@@ -45,11 +46,18 @@ public class GameActivity extends SDLActivity {
       Uri game = this.getIntent().getData();
       Uri game = this.getIntent().getData();
       if (game != null) {
       if (game != null) {
         if (game.getScheme().equals ("file")) {
         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<String> 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 {
         } else {
           copyGameToCache (game);
           copyGameToCache (game);
         }
         }
-        Log.d("GameActivity", "Selected the file: " + getGamePath());
+        Log.d("GameActivity", "Opening game from: " + getGamePath());
       }
       }
 
 
       super.onCreate(savedInstanceState);
       super.onCreate(savedInstanceState);
@@ -72,7 +80,7 @@ public class GameActivity extends SDLActivity {
 
 
     public static String getGamePath() {
     public static String getGamePath() {
       Log.d ("GameActivity", "called getGamePath(), game path = " + gamePath);
       Log.d ("GameActivity", "called getGamePath(), game path = " + gamePath);
-        return gamePath;
+      return gamePath;
     }
     }
 
 
     public static DisplayMetrics getMetrics() {
     public static DisplayMetrics getMetrics() {