Skip to content

Commit

Permalink
Added missing "SliderBorder" field to BeatmapParser.
Browse files Browse the repository at this point in the history
Use beatmap.getSliderBorderColor() to get the slider border color for a beatmap.

Also adds the field to the beatmap cache, and fixes a bug where format changes would cause an exception when preparing statements in the new format.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
  • Loading branch information
itdelatrisu committed Jun 8, 2015
1 parent b6f208a commit 447a0f3
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 23 deletions.
35 changes: 35 additions & 0 deletions src/itdelatrisu/opsu/beatmap/Beatmap.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ public class Beatmap implements Comparable<Beatmap> {
/** Whether the combo is the default skin combo (true) or a beatmap combo (false). */
public boolean isDefaultCombo = true;

/** Slider border color. If null, the skin value is used. */
public Color sliderBorder;

/**
* [HitObjects]
*/
Expand Down Expand Up @@ -257,6 +260,15 @@ public String getArtist() {
return (Options.useUnicodeMetadata() && !artistUnicode.isEmpty()) ? artistUnicode : artist;
}

/**
* Returns the slider border color.
* If the beatmap does not provide a color, the skin color will be returned instead.
* @return the slider border color
*/
public Color getSliderBorderColor() {
return (sliderBorder != null) ? sliderBorder : Options.getSkin().getSliderBorderColor();
}

/**
* Draws the beatmap background.
* @param width the container width
Expand Down Expand Up @@ -441,4 +453,27 @@ public void comboFromString(String s) {
this.isDefaultCombo = false;
}
}

/**
* Returns the {@link #sliderBorder} field formatted as a string,
* or null if the field is null.
*/
public String sliderBorderToString() {
if (sliderBorder == null)
return null;

return String.format("%d,%d,%d", sliderBorder.getRed(), sliderBorder.getGreen(), sliderBorder.getBlue());
}

/**
* Sets the {@link #sliderBorder} field from a string.
* @param s the string
*/
public void sliderBorderFromString(String s) {
if (s == null)
return;

String[] rgb = s.split(",");
this.sliderBorder = new Color(new Color(Integer.parseInt(rgb[0]), Integer.parseInt(rgb[1]), Integer.parseInt(rgb[2])));
}
}
17 changes: 11 additions & 6 deletions src/itdelatrisu/opsu/beatmap/BeatmapParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,12 @@ else if (bpm > beatmap.bpmMax)
if ((tokens = tokenize(line)) == null)
continue;
try {
String[] rgb = tokens[1].split(",");
Color color = new Color(
Integer.parseInt(rgb[0]),
Integer.parseInt(rgb[1]),
Integer.parseInt(rgb[2])
);
switch (tokens[0]) {
case "Combo1":
case "Combo2":
Expand All @@ -513,12 +519,11 @@ else if (bpm > beatmap.bpmMax)
case "Combo6":
case "Combo7":
case "Combo8":
String[] rgb = tokens[1].split(",");
colors.add(new Color(
Integer.parseInt(rgb[0]),
Integer.parseInt(rgb[1]),
Integer.parseInt(rgb[2])
));
colors.add(color);
break;
case "SliderBorder":
beatmap.sliderBorder = color;
break;
default:
break;
}
Expand Down
42 changes: 25 additions & 17 deletions src/itdelatrisu/opsu/db/BeatmapDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class BeatmapDB {
* Current database version.
* This value should be changed whenever the database format changes.
*/
private static final String DATABASE_VERSION = "2014-03-08";
private static final String DATABASE_VERSION = "2014-06-08";

/** Minimum batch size ratio ({@code batchSize/cacheSize}) to invoke batch loading. */
private static final float LOAD_BATCH_MIN_RATIO = 0.2f;
Expand Down Expand Up @@ -78,16 +78,8 @@ public static void init() {
// create the database
createDatabase();

// prepare sql statements
// prepare sql statements (used below)
try {
insertStmt = connection.prepareStatement(
"INSERT INTO beatmaps VALUES (" +
"?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " +
"?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
);
selectStmt = connection.prepareStatement("SELECT * FROM beatmaps WHERE dir = ? AND file = ?");
deleteMapStmt = connection.prepareStatement("DELETE FROM beatmaps WHERE dir = ? AND file = ?");
deleteGroupStmt = connection.prepareStatement("DELETE FROM beatmaps WHERE dir = ?");
updateSizeStmt = connection.prepareStatement("REPLACE INTO info (key, value) VALUES ('size', ?)");
} catch (SQLException e) {
ErrorHandler.error("Failed to prepare beatmap statements.", e, true);
Expand All @@ -98,6 +90,20 @@ public static void init() {

// check the database version
checkVersion();

// prepare sql statements (not used here)
try {
insertStmt = connection.prepareStatement(
"INSERT INTO beatmaps VALUES (" +
"?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " +
"?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
);
selectStmt = connection.prepareStatement("SELECT * FROM beatmaps WHERE dir = ? AND file = ?");
deleteMapStmt = connection.prepareStatement("DELETE FROM beatmaps WHERE dir = ? AND file = ?");
deleteGroupStmt = connection.prepareStatement("DELETE FROM beatmaps WHERE dir = ?");
} catch (SQLException e) {
ErrorHandler.error("Failed to prepare beatmap statements.", e, true);
}
}

/**
Expand All @@ -116,7 +122,7 @@ private static void createDatabase() {
"bpmMin INTEGER, bpmMax INTEGER, endTime INTEGER, " +
"audioFile TEXT, audioLeadIn INTEGER, previewTime INTEGER, countdown INTEGER, sampleSet TEXT, stackLeniency REAL, " +
"mode INTEGER, letterboxInBreaks BOOLEAN, widescreenStoryboard BOOLEAN, epilepsyWarning BOOLEAN, " +
"bg TEXT, timingPoints TEXT, breaks TEXT, combo TEXT" +
"bg TEXT, sliderBorder TEXT, timingPoints TEXT, breaks TEXT, combo TEXT" +
"); " +
"CREATE TABLE IF NOT EXISTS info (" +
"key TEXT NOT NULL UNIQUE, value TEXT" +
Expand Down Expand Up @@ -330,9 +336,10 @@ private static void setStatementFields(PreparedStatement stmt, Beatmap beatmap)
stmt.setBoolean(34, beatmap.widescreenStoryboard);
stmt.setBoolean(35, beatmap.epilepsyWarning);
stmt.setString(36, beatmap.bg);
stmt.setString(37, beatmap.timingPointsToString());
stmt.setString(38, beatmap.breaksToString());
stmt.setString(39, beatmap.comboToString());
stmt.setString(37, beatmap.sliderBorderToString());
stmt.setString(38, beatmap.timingPointsToString());
stmt.setString(39, beatmap.breaksToString());
stmt.setString(40, beatmap.comboToString());
} catch (SQLException e) {
throw e;
} catch (Exception e) {
Expand Down Expand Up @@ -470,6 +477,7 @@ private static void setBeatmapFields(ResultSet rs, Beatmap beatmap) throws SQLEx
beatmap.widescreenStoryboard = rs.getBoolean(34);
beatmap.epilepsyWarning = rs.getBoolean(35);
beatmap.bg = BeatmapParser.getDBString(rs.getString(36));
beatmap.sliderBorderFromString(rs.getString(37));
} catch (SQLException e) {
throw e;
} catch (Exception e) {
Expand All @@ -485,9 +493,9 @@ private static void setBeatmapFields(ResultSet rs, Beatmap beatmap) throws SQLEx
*/
private static void setBeatmapArrayFields(ResultSet rs, Beatmap beatmap) throws SQLException {
try {
beatmap.timingPointsFromString(rs.getString(37));
beatmap.breaksFromString(rs.getString(38));
beatmap.comboFromString(rs.getString(39));
beatmap.timingPointsFromString(rs.getString(38));
beatmap.breaksFromString(rs.getString(39));
beatmap.comboFromString(rs.getString(40));
} catch (SQLException e) {
throw e;
} catch (Exception e) {
Expand Down

0 comments on commit 447a0f3

Please sign in to comment.