Skip to content

Commit

Permalink
Reloading beatmaps now preserves non-parsed beatmap fields.
Browse files Browse the repository at this point in the history
Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
  • Loading branch information
itdelatrisu committed Feb 2, 2017
1 parent 7fab2b1 commit 25356ce
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 7 deletions.
15 changes: 14 additions & 1 deletion src/itdelatrisu/opsu/beatmap/Beatmap.java
Original file line number Diff line number Diff line change
Expand Up @@ -548,4 +548,17 @@ public void incrementPlayCounter() {
this.playCount++;
this.lastPlayed = System.currentTimeMillis();
}
}

/**
* Copies non-parsed fields from this beatmap into another beatmap.
* @param target the target beatmap
*/
public void copyAdditionalFields(Beatmap target) {
target.starRating = starRating;
target.dateAdded = dateAdded;
target.favorite = favorite;
target.playCount = playCount;
target.lastPlayed = lastPlayed;
target.localMusicOffset = localMusicOffset;
}
}
39 changes: 34 additions & 5 deletions src/itdelatrisu/opsu/beatmap/BeatmapParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,24 @@ private BeatmapParser() {}
* adds the beatmaps to a new BeatmapSetList.
* @param root the root directory (search has depth 1)
*/
public static void parseAllFiles(File root) {
// create a new BeatmapSetList
public static void parseAllFiles(File root) { parseAllFiles(root, null); }

/**
* Invokes parser for each OSU file in a root directory and
* adds the beatmaps to a new BeatmapSetList.
* @param root the root directory (search has depth 1)
* @param oldBeatmapList the old beatmap list to copy non-parsed fields from
*/
public static void parseAllFiles(File root, BeatmapSetList oldBeatmapList) {
// create a new beatmap list
BeatmapSetList.create();

// create a new watch service
if (Options.isWatchServiceEnabled())
BeatmapWatchService.create();

// parse all directories
parseDirectories(root.listFiles());
parseDirectories(root.listFiles(), oldBeatmapList);
}

/**
Expand All @@ -99,6 +107,17 @@ public static void parseAllFiles(File root) {
* @return the last BeatmapSetNode parsed, or null if none
*/
public static BeatmapSetNode parseDirectories(File[] dirs) {
return parseDirectories(dirs, null);
}

/**
* Invokes parser for each directory in the given array and
* adds the beatmaps to the existing BeatmapSetList.
* @param dirs the array of directories to parse
* @param oldBeatmapList the old beatmap list to copy non-parsed fields from
* @return the last BeatmapSetNode parsed, or null if none
*/
public static BeatmapSetNode parseDirectories(File[] dirs, BeatmapSetList oldBeatmapList) {
if (dirs == null)
return null;

Expand Down Expand Up @@ -173,9 +192,19 @@ public boolean accept(File dir, String name) {

// add to parsed beatmap list
if (beatmap != null) {
beatmap.dateAdded = timestamp;
if (beatmap.mode == Beatmap.MODE_OSU) // only support standard mode
// copy non-parsed fields
Beatmap oldBeatmap;
if (oldBeatmapList != null && (oldBeatmap = oldBeatmapList.getBeatmapFromHash(beatmap.md5Hash)) != null)
oldBeatmap.copyAdditionalFields(beatmap);

// add timestamp
if (beatmap.dateAdded < 1)
beatmap.dateAdded = timestamp;

// only support standard mode
if (beatmap.mode == Beatmap.MODE_OSU)
beatmaps.add(beatmap);

parsedBeatmaps.add(beatmap);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/itdelatrisu/opsu/states/SongMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ private void reloadBeatmaps() {
}

// invoke parser
BeatmapParser.parseAllFiles(beatmapDir);
BeatmapParser.parseAllFiles(beatmapDir, BeatmapSetList.get());
}
}

Expand Down

0 comments on commit 25356ce

Please # to comment.