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 <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2015-09-02 01:41:47 -05:00
parent fdd70a81c4
commit 6c956e927f
2 changed files with 60 additions and 18 deletions

View File

@ -142,17 +142,19 @@ public class BeatmapParser {
// 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 class BeatmapParser {
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);
}

View File

@ -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 @@ public class HitObject {
// 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 class HitObject {
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 @@ public class HitObject {
// 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);