mirror of
https://github.com/love2d/love-android.git
synced 2026-08-12 08:31:04 +02:00
Added loading of games by opening the main.lua file
This commit is contained in:
@@ -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)) {
|
||||
|
||||
@@ -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<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 {
|
||||
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() {
|
||||
|
||||
Reference in New Issue
Block a user