Skip to content

Commit

Permalink
xxx save open
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghabry committed Jan 19, 2025
1 parent 1c411e3 commit 37255c5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import androidx.annotation.NonNull;
import androidx.documentfile.provider.DocumentFile;

import org.easyrpg.player.Helper;
import org.easyrpg.player.settings.SettingsManager;

import java.io.ByteArrayOutputStream;
Expand All @@ -27,7 +28,7 @@ public class Game implements Comparable<Game> {
private String gameFolderName;
/** Path to the game folder (forwarded via --project-path */
private final String gameFolderPath;
/** Relative path to the save directory, made absolute by launchGame (forwarded via --save-path) */
/** Relative path to the save directory, made absolute by calling createSaveUri */
private String savePath = "";
/** Whether the game was tagged as a favourite */
private boolean isFavorite;
Expand Down Expand Up @@ -173,6 +174,20 @@ public String toString() {
return getDisplayTitle();
}

public Uri createSaveUri(Context context) {
if (!getSavePath().isEmpty()) {
DocumentFile saveFolder = Helper.createFolderInSave(context, getSavePath());

if (saveFolder != null) {
return saveFolder.getUri();
}
} else {
return Uri.parse(getGameFolderPath());
}

return null;
}

public static Game fromCacheEntry(Context context, String cache) {
String[] entries = cache.split(String.valueOf(escapeCode));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.view.GravityCompat;
import androidx.documentfile.provider.DocumentFile;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.google.android.material.navigation.NavigationView;

import org.easyrpg.player.BaseActivity;
import org.easyrpg.player.Helper;
import org.easyrpg.player.R;
import org.easyrpg.player.settings.SettingsManager;
import org.libsdl.app.SDL;
Expand Down Expand Up @@ -346,6 +348,7 @@ public void onBindViewHolder(final ViewHolder holder, final int position) {
String[] choices_list = {
activity.getResources().getString(R.string.select_game_region),
activity.getResources().getString(R.string.game_rename),
"Open Save directory",
activity.getResources().getString(R.string.launch_debug_mode)
};

Expand All @@ -354,10 +357,14 @@ public void onBindViewHolder(final ViewHolder holder, final int position) {
.setTitle(R.string.settings)
.setItems(choices_list, (dialog, which) -> {
if (which == 0) {
chooseRegion(activity, holder, gameList.get(position));
chooseRegion(activity, holder, game);
} else if (which == 1) {
renameGame(activity, holder, gameList.get(position));
renameGame(activity, holder, game);
} else if (which == 2) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(game.createSaveUri(activity), DocumentsContract.Document.MIME_TYPE_DIR);
activity.startActivity(intent);
} else if (which == 3) {
launchGame(position, true);
}
});
Expand Down

0 comments on commit 37255c5

Please sign in to comment.