Fixed an error when importing beatmaps. (fixes #149)
Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
parent
f835a441c2
commit
d85de23cec
|
@ -155,7 +155,7 @@ public class DownloadsMenu extends BasicGameState {
|
||||||
private DropdownMenu<DownloadServer> serverMenu;
|
private DropdownMenu<DownloadServer> serverMenu;
|
||||||
|
|
||||||
/** Beatmap importing thread. */
|
/** Beatmap importing thread. */
|
||||||
private Thread importThread;
|
private BeatmapImportThread importThread;
|
||||||
|
|
||||||
/** Beatmap set ID of the current beatmap being previewed, or -1 if none. */
|
/** Beatmap set ID of the current beatmap being previewed, or -1 if none. */
|
||||||
private int previewID = -1;
|
private int previewID = -1;
|
||||||
|
@ -249,6 +249,46 @@ public class DownloadsMenu extends BasicGameState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Thread for importing packed beatmaps. */
|
||||||
|
private class BeatmapImportThread extends Thread {
|
||||||
|
/** Whether this thread has completed execution. */
|
||||||
|
private boolean finished = false;
|
||||||
|
|
||||||
|
/** The last imported beatmap set node, if any. */
|
||||||
|
private BeatmapSetNode importedNode;
|
||||||
|
|
||||||
|
/** Returns true only if this thread has completed execution. */
|
||||||
|
public boolean isFinished() { return finished; }
|
||||||
|
|
||||||
|
/** Returns an imported beatmap set node, or null if none. */
|
||||||
|
public BeatmapSetNode getImportedBeatmap() { return importedNode; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
importBeatmaps();
|
||||||
|
} finally {
|
||||||
|
finished = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Imports all packed beatmaps. */
|
||||||
|
private void importBeatmaps() {
|
||||||
|
// invoke unpacker and parser
|
||||||
|
File[] dirs = OszUnpacker.unpackAllFiles(Options.getOSZDir(), Options.getBeatmapDir());
|
||||||
|
if (dirs != null && dirs.length > 0) {
|
||||||
|
this.importedNode = BeatmapParser.parseDirectories(dirs);
|
||||||
|
if (importedNode != null) {
|
||||||
|
// send notification
|
||||||
|
UI.sendBarNotification((dirs.length == 1) ? "Imported 1 new song." :
|
||||||
|
String.format("Imported %d new songs.", dirs.length));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DownloadList.get().clearDownloads(Download.Status.COMPLETE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// game-related variables
|
// game-related variables
|
||||||
private GameContainer container;
|
private GameContainer container;
|
||||||
private StateBasedGame game;
|
private StateBasedGame game;
|
||||||
|
@ -495,6 +535,23 @@ public class DownloadsMenu extends BasicGameState {
|
||||||
UI.update(delta);
|
UI.update(delta);
|
||||||
if (importThread == null)
|
if (importThread == null)
|
||||||
MusicController.loopTrackIfEnded(false);
|
MusicController.loopTrackIfEnded(false);
|
||||||
|
else if (importThread.isFinished()) {
|
||||||
|
BeatmapSetNode importedNode = importThread.getImportedBeatmap();
|
||||||
|
if (importedNode != null) {
|
||||||
|
// stop preview
|
||||||
|
previewID = -1;
|
||||||
|
SoundController.stopTrack();
|
||||||
|
|
||||||
|
// initialize song list
|
||||||
|
BeatmapSetList.get().reset();
|
||||||
|
BeatmapSetList.get().init();
|
||||||
|
|
||||||
|
// focus new beatmap
|
||||||
|
// NOTE: This can't be called in another thread because it makes OpenGL calls.
|
||||||
|
((SongMenu) game.getState(Opsu.STATE_SONGMENU)).setFocus(importedNode, -1, true, true);
|
||||||
|
}
|
||||||
|
importThread = null;
|
||||||
|
}
|
||||||
int mouseX = input.getMouseX(), mouseY = input.getMouseY();
|
int mouseX = input.getMouseX(), mouseY = input.getMouseY();
|
||||||
UI.getBackButton().hoverUpdate(delta, mouseX, mouseY);
|
UI.getBackButton().hoverUpdate(delta, mouseX, mouseY);
|
||||||
prevPage.hoverUpdate(delta, mouseX, mouseY);
|
prevPage.hoverUpdate(delta, mouseX, mouseY);
|
||||||
|
@ -712,33 +769,7 @@ public class DownloadsMenu extends BasicGameState {
|
||||||
SoundController.playSound(SoundEffect.MENUCLICK);
|
SoundController.playSound(SoundEffect.MENUCLICK);
|
||||||
|
|
||||||
// import songs in new thread
|
// import songs in new thread
|
||||||
importThread = new Thread() {
|
importThread = new BeatmapImportThread();
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
// invoke unpacker and parser
|
|
||||||
File[] dirs = OszUnpacker.unpackAllFiles(Options.getOSZDir(), Options.getBeatmapDir());
|
|
||||||
if (dirs != null && dirs.length > 0) {
|
|
||||||
BeatmapSetNode node = BeatmapParser.parseDirectories(dirs);
|
|
||||||
if (node != null) {
|
|
||||||
// stop preview
|
|
||||||
previewID = -1;
|
|
||||||
SoundController.stopTrack();
|
|
||||||
|
|
||||||
// initialize song list
|
|
||||||
BeatmapSetList.get().reset();
|
|
||||||
BeatmapSetList.get().init();
|
|
||||||
((SongMenu) game.getState(Opsu.STATE_SONGMENU)).setFocus(node, -1, true, true);
|
|
||||||
|
|
||||||
// send notification
|
|
||||||
UI.sendBarNotification((dirs.length == 1) ? "Imported 1 new song." :
|
|
||||||
String.format("Imported %d new songs.", dirs.length));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DownloadList.get().clearDownloads(Download.Status.COMPLETE);
|
|
||||||
importThread = null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
importThread.start();
|
importThread.start();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user