From 447a0f371a45512cec8495e064bb5cfcb2a38cc6 Mon Sep 17 00:00:00 2001 From: Jeffrey Han Date: Mon, 8 Jun 2015 15:57:17 -0400 Subject: [PATCH] Added missing "SliderBorder" field to BeatmapParser. 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 --- src/itdelatrisu/opsu/beatmap/Beatmap.java | 35 ++++++++++++++++ .../opsu/beatmap/BeatmapParser.java | 17 +++++--- src/itdelatrisu/opsu/db/BeatmapDB.java | 42 +++++++++++-------- 3 files changed, 71 insertions(+), 23 deletions(-) diff --git a/src/itdelatrisu/opsu/beatmap/Beatmap.java b/src/itdelatrisu/opsu/beatmap/Beatmap.java index 923305a5..c4e95d7f 100644 --- a/src/itdelatrisu/opsu/beatmap/Beatmap.java +++ b/src/itdelatrisu/opsu/beatmap/Beatmap.java @@ -185,6 +185,9 @@ public class Beatmap implements Comparable { /** 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] */ @@ -257,6 +260,15 @@ public class Beatmap implements Comparable { 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 @@ -441,4 +453,27 @@ public class Beatmap implements Comparable { 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]))); + } } \ No newline at end of file diff --git a/src/itdelatrisu/opsu/beatmap/BeatmapParser.java b/src/itdelatrisu/opsu/beatmap/BeatmapParser.java index 65d56e8b..a211e588 100644 --- a/src/itdelatrisu/opsu/beatmap/BeatmapParser.java +++ b/src/itdelatrisu/opsu/beatmap/BeatmapParser.java @@ -504,6 +504,12 @@ public class BeatmapParser { 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": @@ -513,12 +519,11 @@ public class BeatmapParser { 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; } diff --git a/src/itdelatrisu/opsu/db/BeatmapDB.java b/src/itdelatrisu/opsu/db/BeatmapDB.java index 3b64c895..cb4b817d 100644 --- a/src/itdelatrisu/opsu/db/BeatmapDB.java +++ b/src/itdelatrisu/opsu/db/BeatmapDB.java @@ -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; @@ -78,16 +78,8 @@ public class BeatmapDB { // 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); @@ -98,6 +90,20 @@ public class BeatmapDB { // 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); + } } /** @@ -116,7 +122,7 @@ public class BeatmapDB { "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" + @@ -330,9 +336,10 @@ public class BeatmapDB { 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) { @@ -470,6 +477,7 @@ public class BeatmapDB { 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) { @@ -485,9 +493,9 @@ public class BeatmapDB { */ 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) {