Added replay saving/loading and score database auto-updater.
- Added 'info' table to score database to store the database version. Upon startup, if the stored version is less than the source version, all update queries defined in ScoreDB.getUpdateQueries() will be run. - Created "Replays" directory to store replay files. Replay files are created after gameplay. - Added 'replay' column to the score database to hold replay file names. - Created a Game.loadOsuFile() method to load game data. Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
package itdelatrisu.opsu.replay;
|
||||
|
||||
import itdelatrisu.opsu.ErrorHandler;
|
||||
import itdelatrisu.opsu.Options;
|
||||
import itdelatrisu.opsu.OsuReader;
|
||||
import itdelatrisu.opsu.OsuWriter;
|
||||
import itdelatrisu.opsu.Utils;
|
||||
@@ -217,10 +218,20 @@ public class Replay {
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the replay data to a file.
|
||||
* @param file the file to write to
|
||||
* Saves the replay data to a file in the replays directory.
|
||||
*/
|
||||
public void save(File file) {
|
||||
public void save() {
|
||||
// create replay directory
|
||||
File dir = Options.getReplayDir();
|
||||
if (!dir.isDirectory()) {
|
||||
if (!dir.mkdir()) {
|
||||
ErrorHandler.error("Failed to create replay directory.", null, false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// write file
|
||||
File file = new File(dir, String.format("%s.osr", getReplayFilename()));
|
||||
try (FileOutputStream out = new FileOutputStream(file)) {
|
||||
OsuWriter writer = new OsuWriter(out);
|
||||
|
||||
@@ -299,6 +310,18 @@ public class Replay {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the file name of where the replay should be saved and loaded,
|
||||
* or null if the required fields are not set.
|
||||
*/
|
||||
public String getReplayFilename() {
|
||||
if (replayHash == null)
|
||||
return null;
|
||||
|
||||
return String.format("%s-%d%d%d%d%d%d",
|
||||
replayHash, hit300, hit100, hit50, geki, katu, miss);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final int LINE_SPLIT = 5;
|
||||
|
||||
Reference in New Issue
Block a user