Browse Source

Implement argument passing for external games.

Miku AuahDark 3 years ago
parent
commit
b1724276ac
2 changed files with 13 additions and 23 deletions
  1. 1 1
      app/src/main/cpp/love
  2. 12 22
      app/src/main/java/org/love2d/android/GameActivity.java

+ 1 - 1
app/src/main/cpp/love

@@ -1 +1 @@
-Subproject commit 502adfcb15ce3cafb529768701a0eab599ac7d85
+Subproject commit aaeb318aa6b3718f6b1d079c3b0191081a74d40b

+ 12 - 22
app/src/main/java/org/love2d/android/GameActivity.java

@@ -55,8 +55,9 @@ public class GameActivity extends SDLActivity {
 
     protected Vibrator vibrator;
     protected boolean shortEdgesMode;
-    private GameInfo currentGameInfo;
     private int delayedFd = -1;
+    private String[] args = new String[0];
+    private boolean isFused;
 
     private static native void nativeSetDefaultStreamValues(int sampleRate, int framesPerBurst);
 
@@ -81,15 +82,20 @@ public class GameActivity extends SDLActivity {
         };
     }
 
+    @Override
+    protected String[] getArguments() {
+        return args;
+    }
+
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         Log.d(TAG, "started");
+        isFused = hasEmbeddedGame();
 
         if (checkCallingOrSelfPermission(Manifest.permission.VIBRATE) == PackageManager.PERMISSION_GRANTED) {
             vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
         }
 
-        currentGameInfo = new GameInfo();
         Intent intent = getIntent();
 
         super.onCreate(savedInstanceState);
@@ -169,11 +175,6 @@ public class GameActivity extends SDLActivity {
         return inputStream != null;
     }
 
-    @Keep
-    public GameInfo getGameInfo() {
-        return currentGameInfo;
-    }
-
     @Keep
     public void vibrate(double seconds) {
         if (vibrator != null) {
@@ -188,7 +189,7 @@ public class GameActivity extends SDLActivity {
     }
 
     @Keep
-    public boolean openURLFromLOVE(String url) {
+    public static boolean openURLFromLOVE(String url) {
         Log.d(TAG, "opening url = " + url);
         return openURL(url) == 0;
     }
@@ -323,7 +324,7 @@ public class GameActivity extends SDLActivity {
         if (mSingleton == null) {
             // Game is not running, consider setting the currentGameInfo here
 
-            if (hasEmbeddedGame()) {
+            if (isFused) {
                 // Send it as dropped file later
                 delayedFd = convertToFileDescriptor(game);
             } else {
@@ -394,20 +395,9 @@ public class GameActivity extends SDLActivity {
 
         if (scheme.equals("content")) {
             // The intent may have more information about the filename
-            currentGameInfo.identity = intent.getStringExtra("name");
-
-            if (currentGameInfo.identity == null) {
-                // Use "lovegame" as fallback
-                // TODO: Use the content URI basename
-                Log.w(TAG, "Using \"lovegame\" as fallback for game identity (Uri " + game + ")");
-                currentGameInfo.identity = "lovegame";
-            }
-
-            currentGameInfo.fd = convertToFileDescriptor(game);
+            args = new String[] {"/love2d://fd/" + convertToFileDescriptor(game)};
         } else if (scheme.equals("file")) {
-            File f = new File(path);
-            currentGameInfo.path = path;
-            currentGameInfo.identity = f.getName();
+            args = new String[] {path};
         }
     }
 }