From 6c956e927f8fa2b704914c70bae858f103542f97 Mon Sep 17 00:00:00 2001 From: Jeffrey Han Date: Wed, 2 Sep 2015 01:41:47 -0500 Subject: [PATCH] Beatmap parser fixes. - Fixed hit object 'addition' field parsing. (Still not sure what the fields do, but the types should be correct now...) - Fixed a careless error causing a potential null pointer exception. (blame: 0b33fed) - Show an error if parseHitObjects() parses a different amount of objects than expected. Signed-off-by: Jeffrey Han --- .../opsu/beatmap/BeatmapParser.java | 31 +++++++----- src/itdelatrisu/opsu/beatmap/HitObject.java | 47 ++++++++++++++++--- 2 files changed, 60 insertions(+), 18 deletions(-) diff --git a/src/itdelatrisu/opsu/beatmap/BeatmapParser.java b/src/itdelatrisu/opsu/beatmap/BeatmapParser.java index 80c6c2f2..ec122052 100644 --- a/src/itdelatrisu/opsu/beatmap/BeatmapParser.java +++ b/src/itdelatrisu/opsu/beatmap/BeatmapParser.java @@ -142,17 +142,19 @@ public boolean accept(File dir, String name) { // check if beatmap is cached String path = String.format("%s/%s", dir.getName(), file.getName()); - Long lastModified = map.get(path); - if (map != null && lastModified != null) { - // check last modified times - if (lastModified == file.lastModified()) { - // add to cached beatmap list - Beatmap beatmap = new Beatmap(file); - beatmaps.add(beatmap); - cachedBeatmaps.add(beatmap); - continue; - } else - BeatmapDB.delete(dir.getName(), file.getName()); + if (map != null) { + Long lastModified = map.get(path); + if (lastModified != null) { + // check last modified times + if (lastModified == file.lastModified()) { + // add to cached beatmap list + Beatmap beatmap = new Beatmap(file); + beatmaps.add(beatmap); + cachedBeatmaps.add(beatmap); + continue; + } else + BeatmapDB.delete(dir.getName(), file.getName()); + } } // Parse hit objects only when needed to save time/memory. @@ -686,10 +688,15 @@ public static void parseHitObjects(Beatmap beatmap) { beatmap.objects[objectIndex++] = hitObject; } catch (Exception e) { - Log.warn(String.format("Failed to read hit object '%s' for Beatmap '%s'.", + Log.warn(String.format("Failed to read hit object '%s' for beatmap '%s'.", line, beatmap.toString()), e); } } + + // check that all objects were parsed + if (objectIndex != beatmap.objects.length) + ErrorHandler.error(String.format("Parsed %d objects for beatmap '%s', %d objects expected.", + objectIndex, beatmap.toString(), beatmap.objects.length), null, true); } catch (IOException e) { ErrorHandler.error(String.format("Failed to read file '%s'.", beatmap.getFile().getAbsolutePath()), e, false); } diff --git a/src/itdelatrisu/opsu/beatmap/HitObject.java b/src/itdelatrisu/opsu/beatmap/HitObject.java index f32997ce..9cbe280a 100644 --- a/src/itdelatrisu/opsu/beatmap/HitObject.java +++ b/src/itdelatrisu/opsu/beatmap/HitObject.java @@ -101,9 +101,18 @@ public class HitObject { /** Hit sound type (SOUND_* bitmask). */ private byte hitSound; - /** Hit sound addition (sampleSet, AdditionSampleSet, ?, ...). */ + /** Hit sound addition (sampleSet, AdditionSampleSet). */ private byte[] addition; + /** Addition custom sample index. */ + private byte additionCustomSampleIndex; + + /** Addition hit sound volume. */ + private int additionHitSoundVolume; + + /** Addition hit sound file. */ + private String additionHitSound; + /** Slider curve type (SLIDER_* constant). */ private char sliderType; @@ -250,9 +259,17 @@ else if ((type & HitObject.TYPE_SLIDER) > 0) { // addition if (tokens.length > additionIndex) { String[] additionTokens = tokens[additionIndex].split(":"); - this.addition = new byte[additionTokens.length]; - for (int j = 0; j < additionTokens.length; j++) - this.addition[j] = Byte.parseByte(additionTokens[j]); + if (additionTokens.length > 1) { + this.addition = new byte[2]; + addition[0] = Byte.parseByte(additionTokens[0]); + addition[1] = Byte.parseByte(additionTokens[1]); + } + if (additionTokens.length > 2) + this.additionCustomSampleIndex = Byte.parseByte(additionTokens[2]); + if (additionTokens.length > 3) + this.additionHitSoundVolume = Integer.parseInt(additionTokens[3]); + if (additionTokens.length > 4) + this.additionHitSound = additionTokens[4]; } } @@ -471,6 +488,21 @@ public byte getAdditionSampleSet(int index) { return 0; } + /** + * Returns the custom sample index (addition). + */ + public byte getCustomSampleIndex() { return additionCustomSampleIndex; } + + /** + * Returns the hit sound volume (addition). + */ + public int getHitSoundVolume() { return additionHitSoundVolume; } + + /** + * Returns the hit sound file (addition). + */ + public String getHitSoundFile() { return additionHitSound; } + /** * Sets the hit object index in the current stack. * @param stack index in the stack @@ -529,9 +561,12 @@ else if (isSlider()) { // addition if (addition != null) { for (int i = 0; i < addition.length; i++) { - sb.append(addition[i]); - sb.append(':'); + sb.append(addition[i]); sb.append(':'); } + sb.append(additionCustomSampleIndex); sb.append(':'); + sb.append(additionHitSoundVolume); sb.append(':'); + if (additionHitSound != null) + sb.append(additionHitSound); } else sb.setLength(sb.length() - 1);