Added a module for unpacking OSZ archives.
- Included 'zip4j' library to extract the ZIP archives. (Homepage: http://www.lingala.net/zip4j/)
- OSZ files are unpacked from the root directory by default, and the path can be changed in the configuration file.
Other changes:
- Fixed a critical issue in splash screen where thread would running before other states loaded. (blame: dea7e94)
Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
@@ -79,10 +79,15 @@ public class Options extends BasicGameState {
|
||||
};
|
||||
|
||||
/**
|
||||
* The current beatmap directory.
|
||||
* The beatmap directory.
|
||||
*/
|
||||
private static File beatmapDir;
|
||||
|
||||
/**
|
||||
* The OSZ archive directory.
|
||||
*/
|
||||
private static File oszDir;
|
||||
|
||||
/**
|
||||
* The current skin directory (for user skins).
|
||||
*/
|
||||
@@ -1071,7 +1076,7 @@ public class Options extends BasicGameState {
|
||||
public static boolean isLoadVerbose() { return loadVerbose; }
|
||||
|
||||
/**
|
||||
* Returns the current beatmap directory.
|
||||
* Returns the beatmap directory.
|
||||
* If invalid, this will attempt to search for the directory,
|
||||
* and if nothing found, will create one.
|
||||
* @return the beatmap directory
|
||||
@@ -1090,6 +1095,19 @@ public class Options extends BasicGameState {
|
||||
return beatmapDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the OSZ archive directory.
|
||||
* If invalid, this will return the root directory.
|
||||
* @return the OSZ archive directory
|
||||
*/
|
||||
public static File getOSZDir() {
|
||||
if (oszDir != null && oszDir.isDirectory())
|
||||
return oszDir;
|
||||
|
||||
oszDir = new File("").getAbsoluteFile();
|
||||
return oszDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current skin directory.
|
||||
* If invalid, this will create a "Skins" folder in the root directory.
|
||||
@@ -1131,6 +1149,9 @@ public class Options extends BasicGameState {
|
||||
case "BeatmapDirectory":
|
||||
beatmapDir = new File(value);
|
||||
break;
|
||||
case "OSZDirectory":
|
||||
oszDir = new File(value);
|
||||
break;
|
||||
case "Skin":
|
||||
skinDir = new File(value);
|
||||
break;
|
||||
@@ -1250,6 +1271,8 @@ public class Options extends BasicGameState {
|
||||
// options
|
||||
writer.write(String.format("BeatmapDirectory = %s", getBeatmapDir().getAbsolutePath()));
|
||||
writer.newLine();
|
||||
writer.write(String.format("OSZDirectory = %s", getOSZDir().getAbsolutePath()));
|
||||
writer.newLine();
|
||||
writer.write(String.format("Skin = %s", getSkinDir().getAbsolutePath()));
|
||||
writer.newLine();
|
||||
writer.write(String.format("Port = %d", port));
|
||||
|
||||
@@ -21,9 +21,12 @@ package itdelatrisu.opsu.states;
|
||||
import itdelatrisu.opsu.Opsu;
|
||||
import itdelatrisu.opsu.OsuGroupList;
|
||||
import itdelatrisu.opsu.OsuParser;
|
||||
import itdelatrisu.opsu.OszUnpacker;
|
||||
import itdelatrisu.opsu.SoundController;
|
||||
import itdelatrisu.opsu.Utils;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
@@ -32,6 +35,11 @@ import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.state.BasicGameState;
|
||||
import org.newdawn.slick.state.StateBasedGame;
|
||||
|
||||
/**
|
||||
* "Splash Screen" state.
|
||||
* <p>
|
||||
* Loads game resources and enters "Main Menu" state.
|
||||
*/
|
||||
public class Splash extends BasicGameState {
|
||||
/**
|
||||
* Logo image.
|
||||
@@ -45,6 +53,7 @@ public class Splash extends BasicGameState {
|
||||
|
||||
// game-related variables
|
||||
private int state;
|
||||
private boolean init = false;
|
||||
|
||||
public Splash(int state) {
|
||||
this.state = state;
|
||||
@@ -53,34 +62,12 @@ public class Splash extends BasicGameState {
|
||||
@Override
|
||||
public void init(GameContainer container, StateBasedGame game)
|
||||
throws SlickException {
|
||||
final int width = container.getWidth();
|
||||
final int height = container.getHeight();
|
||||
|
||||
logo = new Image("logo.png");
|
||||
logo = logo.getScaledCopy((height / 1.2f) / logo.getHeight());
|
||||
logo = logo.getScaledCopy((container.getHeight() / 1.2f) / logo.getHeight());
|
||||
logo.setAlpha(0f);
|
||||
|
||||
// load Utils class first (needed in other 'init' methods)
|
||||
Utils.init(container, game);
|
||||
|
||||
// load other resources in a new thread
|
||||
final SongMenu menu = (SongMenu) game.getState(Opsu.STATE_SONGMENU);
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
// parse song directory
|
||||
OsuParser.parseAllFiles(Options.getBeatmapDir(), width, height);
|
||||
|
||||
// initialize song list
|
||||
Opsu.groups.init(OsuGroupList.SORT_TITLE);
|
||||
menu.setFocus(Opsu.groups.getRandomNode(), -1, true);
|
||||
|
||||
// load sounds
|
||||
SoundController.init();
|
||||
|
||||
finished = true;
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -93,23 +80,63 @@ public class Splash extends BasicGameState {
|
||||
|
||||
logo.drawCentered(width / 2, height / 2);
|
||||
|
||||
// progress tracking
|
||||
String currentFile = OsuParser.getCurrentFileName();
|
||||
if (currentFile != null && Options.isLoadVerbose()) {
|
||||
// display progress
|
||||
if (Options.isLoadVerbose()) {
|
||||
g.setColor(Color.white);
|
||||
g.setFont(Utils.FONT_MEDIUM);
|
||||
int lineHeight = Utils.FONT_MEDIUM.getLineHeight();
|
||||
g.drawString(
|
||||
String.format("Loading... (%s%%)", OsuParser.getParserProgress()),
|
||||
25, height - 25 - (lineHeight * 2)
|
||||
);
|
||||
g.drawString(currentFile, 25, height - 25 - lineHeight);
|
||||
|
||||
String unpackedFile = OszUnpacker.getCurrentFileName();
|
||||
String parsedFile = OsuParser.getCurrentFileName();
|
||||
if (unpackedFile != null) {
|
||||
g.drawString(
|
||||
String.format("Unpacking... (%d%%)", OszUnpacker.getUnpackerProgress()),
|
||||
25, height - 25 - (lineHeight * 2)
|
||||
);
|
||||
g.drawString(unpackedFile, 25, height - 25 - lineHeight);
|
||||
} else if (parsedFile != null) {
|
||||
g.drawString(
|
||||
String.format("Loading... (%d%%)", OsuParser.getParserProgress()),
|
||||
25, height - 25 - (lineHeight * 2)
|
||||
);
|
||||
g.drawString(parsedFile, 25, height - 25 - lineHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(GameContainer container, StateBasedGame game, int delta)
|
||||
throws SlickException {
|
||||
if (!init) {
|
||||
init = true;
|
||||
|
||||
// load other resources in a new thread
|
||||
final int width = container.getWidth();
|
||||
final int height = container.getHeight();
|
||||
final SongMenu menu = (SongMenu) game.getState(Opsu.STATE_SONGMENU);
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
File beatmapDir = Options.getBeatmapDir();
|
||||
|
||||
// unpack all OSZ archives
|
||||
OszUnpacker.unpackAllFiles(Options.getOSZDir(), beatmapDir);
|
||||
|
||||
// parse song directory
|
||||
OsuParser.parseAllFiles(beatmapDir, width, height);
|
||||
|
||||
// initialize song list
|
||||
Opsu.groups.init(OsuGroupList.SORT_TITLE);
|
||||
menu.setFocus(Opsu.groups.getRandomNode(), -1, true);
|
||||
|
||||
// load sounds
|
||||
SoundController.init();
|
||||
|
||||
finished = true;
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
// fade in logo
|
||||
float alpha = logo.getAlpha();
|
||||
if (alpha < 1f)
|
||||
|
||||
Reference in New Issue
Block a user