Implement argument passing for external games.

This commit is contained in:
Miku AuahDark
2022-05-22 22:47:59 +08:00
parent 96acf0a891
commit b1724276ac
2 changed files with 13 additions and 23 deletions
@@ -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};
}
}
}