2014-06-30 04:17:04 +02:00
|
|
|
/*
|
|
|
|
* opsu! - an open-source osu! client
|
2015-01-16 18:05:44 +01:00
|
|
|
* Copyright (C) 2014, 2015 Jeffrey Han
|
2014-06-30 04:17:04 +02:00
|
|
|
*
|
|
|
|
* opsu! is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* opsu! is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with opsu!. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2015-05-29 09:07:58 +02:00
|
|
|
package itdelatrisu.opsu.beatmap;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-05-29 09:07:58 +02:00
|
|
|
import itdelatrisu.opsu.ErrorHandler;
|
2015-08-21 17:25:52 +02:00
|
|
|
import itdelatrisu.opsu.Options;
|
2015-05-29 09:07:58 +02:00
|
|
|
import itdelatrisu.opsu.Utils;
|
2015-05-17 03:25:19 +02:00
|
|
|
import itdelatrisu.opsu.db.BeatmapDB;
|
2015-06-30 02:22:38 +02:00
|
|
|
import itdelatrisu.opsu.io.MD5InputStreamWrapper;
|
2015-03-05 03:03:06 +01:00
|
|
|
|
2015-06-22 04:57:30 +02:00
|
|
|
import java.io.BufferedInputStream;
|
2014-06-30 04:17:04 +02:00
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.File;
|
2014-08-25 05:48:52 +02:00
|
|
|
import java.io.FileInputStream;
|
2014-06-30 04:17:04 +02:00
|
|
|
import java.io.FileReader;
|
|
|
|
import java.io.FilenameFilter;
|
|
|
|
import java.io.IOException;
|
2015-06-22 04:57:30 +02:00
|
|
|
import java.io.InputStream;
|
2014-08-25 05:48:52 +02:00
|
|
|
import java.io.InputStreamReader;
|
2015-06-22 04:57:30 +02:00
|
|
|
import java.security.NoSuchAlgorithmException;
|
2014-06-30 04:17:04 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
2015-01-15 03:48:24 +01:00
|
|
|
import java.util.HashMap;
|
2014-06-30 04:17:04 +02:00
|
|
|
import java.util.LinkedList;
|
2015-03-08 05:24:19 +01:00
|
|
|
import java.util.List;
|
2015-03-05 03:03:06 +01:00
|
|
|
import java.util.Map;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
import org.newdawn.slick.Color;
|
|
|
|
import org.newdawn.slick.util.Log;
|
|
|
|
|
|
|
|
/**
|
2015-05-29 09:07:58 +02:00
|
|
|
* Parser for beatmaps.
|
2014-06-30 04:17:04 +02:00
|
|
|
*/
|
2015-05-29 09:07:58 +02:00
|
|
|
public class BeatmapParser {
|
2015-02-10 05:22:58 +01:00
|
|
|
/** The string lookup database. */
|
|
|
|
private static HashMap<String, String> stringdb = new HashMap<String, String>();
|
|
|
|
|
|
|
|
/** The expected pattern for beatmap directories, used to find beatmap set IDs. */
|
|
|
|
private static final String DIR_MSID_PATTERN = "^\\d+ .*";
|
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** The current file being parsed. */
|
2014-07-06 03:00:52 +02:00
|
|
|
private static File currentFile;
|
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** The current directory number while parsing. */
|
2014-07-06 03:00:52 +02:00
|
|
|
private static int currentDirectoryIndex = -1;
|
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** The total number of directories to parse. */
|
2014-07-06 03:00:52 +02:00
|
|
|
private static int totalDirectories = -1;
|
|
|
|
|
2015-03-08 05:24:19 +01:00
|
|
|
/** Parser statuses. */
|
|
|
|
public enum Status { NONE, PARSING, CACHE, INSERTING };
|
|
|
|
|
|
|
|
/** The current status. */
|
|
|
|
private static Status status = Status.NONE;
|
2015-03-05 03:03:06 +01:00
|
|
|
|
2015-06-30 02:22:38 +02:00
|
|
|
/** If no Provider supports a MessageDigestSpi implementation for the MD5 algorithm. */
|
|
|
|
private static boolean hasNoMD5Algorithm = false;
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
// This class should not be instantiated.
|
2015-05-29 09:07:58 +02:00
|
|
|
private BeatmapParser() {}
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
/**
|
2015-02-02 06:15:16 +01:00
|
|
|
* Invokes parser for each OSU file in a root directory and
|
2015-05-17 03:25:19 +02:00
|
|
|
* adds the beatmaps to a new BeatmapSetList.
|
2014-06-30 04:17:04 +02:00
|
|
|
* @param root the root directory (search has depth 1)
|
|
|
|
*/
|
2015-02-01 08:10:17 +01:00
|
|
|
public static void parseAllFiles(File root) {
|
2015-05-17 03:25:19 +02:00
|
|
|
// create a new BeatmapSetList
|
|
|
|
BeatmapSetList.create();
|
2015-01-21 01:24:59 +01:00
|
|
|
|
2015-08-21 17:25:52 +02:00
|
|
|
// create a new watch service
|
|
|
|
if (Options.isWatchServiceEnabled())
|
|
|
|
BeatmapWatchService.create();
|
|
|
|
|
2015-02-02 06:15:16 +01:00
|
|
|
// parse all directories
|
|
|
|
parseDirectories(root.listFiles());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invokes parser for each directory in the given array and
|
2015-05-17 03:25:19 +02:00
|
|
|
* adds the beatmaps to the existing BeatmapSetList.
|
2015-02-02 06:15:16 +01:00
|
|
|
* @param dirs the array of directories to parse
|
2015-05-17 03:25:19 +02:00
|
|
|
* @return the last BeatmapSetNode parsed, or null if none
|
2015-02-02 06:15:16 +01:00
|
|
|
*/
|
2015-05-17 03:25:19 +02:00
|
|
|
public static BeatmapSetNode parseDirectories(File[] dirs) {
|
2015-02-12 08:27:33 +01:00
|
|
|
if (dirs == null)
|
|
|
|
return null;
|
|
|
|
|
2014-07-06 03:00:52 +02:00
|
|
|
// progress tracking
|
2015-03-08 05:24:19 +01:00
|
|
|
status = Status.PARSING;
|
2014-07-06 03:00:52 +02:00
|
|
|
currentDirectoryIndex = 0;
|
2015-02-02 06:15:16 +01:00
|
|
|
totalDirectories = dirs.length;
|
2014-07-06 03:00:52 +02:00
|
|
|
|
2015-03-05 03:03:06 +01:00
|
|
|
// get last modified map from database
|
2015-05-17 03:25:19 +02:00
|
|
|
Map<String, Long> map = BeatmapDB.getLastModifiedMap();
|
2015-03-05 03:03:06 +01:00
|
|
|
|
2015-05-17 03:25:19 +02:00
|
|
|
// beatmap lists
|
|
|
|
List<ArrayList<Beatmap>> allBeatmaps = new LinkedList<ArrayList<Beatmap>>();
|
|
|
|
List<Beatmap> cachedBeatmaps = new LinkedList<Beatmap>(); // loaded from database
|
|
|
|
List<Beatmap> parsedBeatmaps = new LinkedList<Beatmap>(); // loaded from parser
|
2015-03-08 05:24:19 +01:00
|
|
|
|
2015-08-21 17:25:52 +02:00
|
|
|
// watch service
|
|
|
|
BeatmapWatchService ws = (Options.isWatchServiceEnabled()) ? BeatmapWatchService.get() : null;
|
|
|
|
|
2015-02-02 06:15:16 +01:00
|
|
|
// parse directories
|
2015-05-17 03:25:19 +02:00
|
|
|
BeatmapSetNode lastNode = null;
|
2015-02-02 06:15:16 +01:00
|
|
|
for (File dir : dirs) {
|
2014-07-06 03:00:52 +02:00
|
|
|
currentDirectoryIndex++;
|
2015-02-02 06:15:16 +01:00
|
|
|
if (!dir.isDirectory())
|
2014-06-30 04:17:04 +02:00
|
|
|
continue;
|
2015-02-02 06:15:16 +01:00
|
|
|
|
|
|
|
// find all OSU files
|
|
|
|
File[] files = dir.listFiles(new FilenameFilter() {
|
2014-06-30 04:17:04 +02:00
|
|
|
@Override
|
|
|
|
public boolean accept(File dir, String name) {
|
|
|
|
return name.toLowerCase().endsWith(".osu");
|
|
|
|
}
|
|
|
|
});
|
2015-12-15 01:02:37 +01:00
|
|
|
if (files == null || files.length < 1)
|
2014-06-30 04:17:04 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// create a new group entry
|
2015-05-17 03:25:19 +02:00
|
|
|
ArrayList<Beatmap> beatmaps = new ArrayList<Beatmap>();
|
2014-06-30 04:17:04 +02:00
|
|
|
for (File file : files) {
|
2014-07-06 03:00:52 +02:00
|
|
|
currentFile = file;
|
|
|
|
|
2015-03-05 03:03:06 +01:00
|
|
|
// check if beatmap is cached
|
|
|
|
String path = String.format("%s/%s", dir.getName(), file.getName());
|
2015-09-02 08:41:47 +02:00
|
|
|
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());
|
|
|
|
}
|
2015-03-05 03:03:06 +01:00
|
|
|
}
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
// Parse hit objects only when needed to save time/memory.
|
|
|
|
// Change boolean to 'true' to parse them immediately.
|
2015-05-17 03:25:19 +02:00
|
|
|
Beatmap beatmap = parseFile(file, dir, beatmaps, false);
|
2015-03-05 03:03:06 +01:00
|
|
|
|
2015-03-08 05:24:19 +01:00
|
|
|
// add to parsed beatmap list
|
2015-05-17 03:25:19 +02:00
|
|
|
if (beatmap != null) {
|
|
|
|
beatmaps.add(beatmap);
|
|
|
|
parsedBeatmaps.add(beatmap);
|
2015-03-08 05:24:19 +01:00
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
2015-03-08 05:24:19 +01:00
|
|
|
|
|
|
|
// add group entry if non-empty
|
2015-05-17 03:25:19 +02:00
|
|
|
if (!beatmaps.isEmpty()) {
|
|
|
|
beatmaps.trimToSize();
|
|
|
|
allBeatmaps.add(beatmaps);
|
2015-08-21 17:25:52 +02:00
|
|
|
if (ws != null)
|
|
|
|
ws.registerAll(dir.toPath());
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
2015-01-18 21:26:00 +01:00
|
|
|
|
2015-02-02 06:15:16 +01:00
|
|
|
// stop parsing files (interrupted)
|
2015-01-18 21:26:00 +01:00
|
|
|
if (Thread.interrupted())
|
|
|
|
break;
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
2014-07-06 03:00:52 +02:00
|
|
|
|
2015-03-08 05:24:19 +01:00
|
|
|
// load cached entries from database
|
2015-05-17 03:25:19 +02:00
|
|
|
if (!cachedBeatmaps.isEmpty()) {
|
2015-03-08 05:24:19 +01:00
|
|
|
status = Status.CACHE;
|
2015-03-08 08:05:01 +01:00
|
|
|
|
|
|
|
// Load array fields only when needed to save time/memory.
|
|
|
|
// Change flag to 'LOAD_ALL' to load them immediately.
|
2015-05-17 03:25:19 +02:00
|
|
|
BeatmapDB.load(cachedBeatmaps, BeatmapDB.LOAD_NONARRAY);
|
2015-03-08 05:24:19 +01:00
|
|
|
}
|
|
|
|
|
2015-05-17 03:25:19 +02:00
|
|
|
// add group entries to BeatmapSetList
|
|
|
|
for (ArrayList<Beatmap> beatmaps : allBeatmaps) {
|
|
|
|
Collections.sort(beatmaps);
|
|
|
|
lastNode = BeatmapSetList.get().addSongGroup(beatmaps);
|
2015-03-08 05:24:19 +01:00
|
|
|
}
|
|
|
|
|
2015-01-15 03:48:24 +01:00
|
|
|
// clear string DB
|
|
|
|
stringdb = new HashMap<String, String>();
|
|
|
|
|
2015-03-08 05:24:19 +01:00
|
|
|
// add beatmap entries to database
|
2015-05-17 03:25:19 +02:00
|
|
|
if (!parsedBeatmaps.isEmpty()) {
|
2015-03-08 05:24:19 +01:00
|
|
|
status = Status.INSERTING;
|
2015-05-17 03:25:19 +02:00
|
|
|
BeatmapDB.insert(parsedBeatmaps);
|
2015-03-08 00:05:18 +01:00
|
|
|
}
|
2015-03-05 03:03:06 +01:00
|
|
|
|
2015-03-08 05:24:19 +01:00
|
|
|
status = Status.NONE;
|
2014-07-06 03:00:52 +02:00
|
|
|
currentFile = null;
|
|
|
|
currentDirectoryIndex = -1;
|
|
|
|
totalDirectories = -1;
|
2015-02-02 06:15:16 +01:00
|
|
|
return lastNode;
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
|
2016-12-18 23:39:39 +01:00
|
|
|
/**
|
|
|
|
* Parses the timingpoints for a beatmap.
|
|
|
|
* @param map the map to parse timingpoints for
|
|
|
|
*/
|
|
|
|
public static void parseOnlyTimingPoints(Beatmap map) {
|
|
|
|
if (map == null || map.getFile() == null || !map.getFile().exists()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (map.timingPoints == null) {
|
|
|
|
map.timingPoints = new ArrayList<TimingPoint>();
|
|
|
|
}
|
|
|
|
try (
|
|
|
|
InputStream bis = new BufferedInputStream(new FileInputStream(map.getFile()));
|
2016-12-20 00:40:51 +01:00
|
|
|
BufferedReader in = new BufferedReader(new InputStreamReader(bis, "UTF-8"));
|
2016-12-18 23:39:39 +01:00
|
|
|
) {
|
|
|
|
String line;
|
|
|
|
boolean found = false;
|
|
|
|
while((line = in.readLine()) != null) {
|
|
|
|
line = line.trim();
|
|
|
|
if(!isValidLine(line)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ("[TimingPoints]".equals(line)) {
|
|
|
|
found = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (found) {
|
|
|
|
if (line.startsWith("[")) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
parseSectionTimingPoints(map, line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
map.timingPoints.trimToSize();
|
|
|
|
} catch (IOException e) {
|
|
|
|
ErrorHandler.error(String.format("Failed to read file '%s'.", map.getFile().getAbsolutePath()), e, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
/**
|
2015-05-17 03:25:19 +02:00
|
|
|
* Parses a beatmap.
|
2014-06-30 04:17:04 +02:00
|
|
|
* @param file the file to parse
|
2015-02-10 05:22:58 +01:00
|
|
|
* @param dir the directory containing the beatmap
|
2015-05-17 03:25:19 +02:00
|
|
|
* @param beatmaps the song group
|
2014-06-30 04:17:04 +02:00
|
|
|
* @param parseObjects if true, hit objects will be fully parsed now
|
2015-05-17 03:25:19 +02:00
|
|
|
* @return the new beatmap
|
2014-06-30 04:17:04 +02:00
|
|
|
*/
|
2015-05-17 03:25:19 +02:00
|
|
|
private static Beatmap parseFile(File file, File dir, ArrayList<Beatmap> beatmaps, boolean parseObjects) {
|
|
|
|
Beatmap beatmap = new Beatmap(file);
|
|
|
|
beatmap.timingPoints = new ArrayList<TimingPoint>();
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-06-30 02:22:38 +02:00
|
|
|
try (
|
|
|
|
InputStream bis = new BufferedInputStream(new FileInputStream(file));
|
|
|
|
MD5InputStreamWrapper md5stream = (!hasNoMD5Algorithm) ? new MD5InputStreamWrapper(bis) : null;
|
|
|
|
BufferedReader in = new BufferedReader(new InputStreamReader((md5stream != null) ? md5stream : bis, "UTF-8"));
|
|
|
|
) {
|
2014-06-30 04:17:04 +02:00
|
|
|
String line = in.readLine();
|
2014-07-18 03:16:15 +02:00
|
|
|
String tokens[] = null;
|
2014-06-30 04:17:04 +02:00
|
|
|
while (line != null) {
|
|
|
|
line = line.trim();
|
|
|
|
if (!isValidLine(line)) {
|
|
|
|
line = in.readLine();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
switch (line) {
|
|
|
|
case "[General]":
|
|
|
|
while ((line = in.readLine()) != null) {
|
|
|
|
line = line.trim();
|
|
|
|
if (!isValidLine(line))
|
|
|
|
continue;
|
|
|
|
if (line.charAt(0) == '[')
|
|
|
|
break;
|
2014-07-02 16:14:15 +02:00
|
|
|
if ((tokens = tokenize(line)) == null)
|
|
|
|
continue;
|
2014-07-24 19:38:59 +02:00
|
|
|
try {
|
|
|
|
switch (tokens[0]) {
|
|
|
|
case "AudioFilename":
|
2015-03-07 19:13:32 +01:00
|
|
|
File audioFileName = new File(dir, tokens[1]);
|
2015-05-17 03:25:19 +02:00
|
|
|
if (!beatmaps.isEmpty()) {
|
|
|
|
// if possible, reuse the same File object from another Beatmap in the group
|
|
|
|
File groupAudioFileName = beatmaps.get(0).audioFilename;
|
2015-03-08 05:24:19 +01:00
|
|
|
if (groupAudioFileName != null &&
|
|
|
|
tokens[1].equalsIgnoreCase(groupAudioFileName.getName()))
|
2015-01-21 04:19:14 +01:00
|
|
|
audioFileName = groupAudioFileName;
|
|
|
|
}
|
2015-03-07 19:13:32 +01:00
|
|
|
if (!audioFileName.isFile()) {
|
|
|
|
// try to find the file with a case-insensitive match
|
|
|
|
boolean match = false;
|
|
|
|
for (String s : dir.list()) {
|
|
|
|
if (s.equalsIgnoreCase(tokens[1])) {
|
|
|
|
audioFileName = new File(dir, s);
|
|
|
|
match = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!match) {
|
2015-04-10 18:34:18 +02:00
|
|
|
Log.error(String.format("Audio file '%s' not found in directory '%s'.", tokens[1], dir.getName()));
|
2015-03-07 19:13:32 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2015-05-17 03:25:19 +02:00
|
|
|
beatmap.audioFilename = audioFileName;
|
2014-07-24 19:38:59 +02:00
|
|
|
break;
|
|
|
|
case "AudioLeadIn":
|
2015-05-17 03:25:19 +02:00
|
|
|
beatmap.audioLeadIn = Integer.parseInt(tokens[1]);
|
2014-07-24 19:38:59 +02:00
|
|
|
break;
|
|
|
|
// case "AudioHash": // deprecated
|
2015-05-17 03:25:19 +02:00
|
|
|
// beatmap.audioHash = tokens[1];
|
2014-07-24 19:38:59 +02:00
|
|
|
// break;
|
|
|
|
case "PreviewTime":
|
2015-05-17 03:25:19 +02:00
|
|
|
beatmap.previewTime = Integer.parseInt(tokens[1]);
|
2014-07-24 19:38:59 +02:00
|
|
|
break;
|
|
|
|
case "Countdown":
|
2015-05-17 03:25:19 +02:00
|
|
|
beatmap.countdown = Byte.parseByte(tokens[1]);
|
2014-07-24 19:38:59 +02:00
|
|
|
break;
|
|
|
|
case "SampleSet":
|
2015-05-17 03:25:19 +02:00
|
|
|
beatmap.sampleSet = getDBString(tokens[1]);
|
2014-07-24 19:38:59 +02:00
|
|
|
break;
|
|
|
|
case "StackLeniency":
|
2015-05-17 03:25:19 +02:00
|
|
|
beatmap.stackLeniency = Float.parseFloat(tokens[1]);
|
2014-07-24 19:38:59 +02:00
|
|
|
break;
|
|
|
|
case "Mode":
|
2015-05-17 03:25:19 +02:00
|
|
|
beatmap.mode = Byte.parseByte(tokens[1]);
|
2014-07-24 19:38:59 +02:00
|
|
|
|
|
|
|
/* Non-Opsu! standard files not implemented (obviously). */
|
2015-05-17 03:25:19 +02:00
|
|
|
if (beatmap.mode != Beatmap.MODE_OSU)
|
2014-07-24 19:38:59 +02:00
|
|
|
return null;
|
|
|
|
|
|
|
|
break;
|
|
|
|
case "LetterboxInBreaks":
|
2015-05-23 20:52:03 +02:00
|
|
|
beatmap.letterboxInBreaks = Utils.parseBoolean(tokens[1]);
|
2014-07-24 19:38:59 +02:00
|
|
|
break;
|
|
|
|
case "WidescreenStoryboard":
|
2015-05-23 20:52:03 +02:00
|
|
|
beatmap.widescreenStoryboard = Utils.parseBoolean(tokens[1]);
|
2014-07-24 19:38:59 +02:00
|
|
|
break;
|
|
|
|
case "EpilepsyWarning":
|
2015-05-23 20:52:03 +02:00
|
|
|
beatmap.epilepsyWarning = Utils.parseBoolean(tokens[1]);
|
2014-07-24 19:38:59 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.warn(String.format("Failed to read line '%s' for file '%s'.",
|
|
|
|
line, file.getAbsolutePath()), e);
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "[Editor]":
|
|
|
|
while ((line = in.readLine()) != null) {
|
|
|
|
line = line.trim();
|
|
|
|
if (!isValidLine(line))
|
|
|
|
continue;
|
|
|
|
if (line.charAt(0) == '[')
|
|
|
|
break;
|
|
|
|
/* Not implemented. */
|
2014-07-02 16:14:15 +02:00
|
|
|
// if ((tokens = tokenize(line)) == null)
|
|
|
|
// continue;
|
2014-07-24 19:38:59 +02:00
|
|
|
// try {
|
|
|
|
// switch (tokens[0]) {
|
|
|
|
// case "Bookmarks":
|
|
|
|
// String[] bookmarks = tokens[1].split(",");
|
2015-05-17 03:25:19 +02:00
|
|
|
// beatmap.bookmarks = new int[bookmarks.length];
|
2014-07-24 19:38:59 +02:00
|
|
|
// for (int i = 0; i < bookmarks.length; i++)
|
|
|
|
// osu.bookmarks[i] = Integer.parseInt(bookmarks[i]);
|
|
|
|
// break;
|
|
|
|
// case "DistanceSpacing":
|
2015-05-17 03:25:19 +02:00
|
|
|
// beatmap.distanceSpacing = Float.parseFloat(tokens[1]);
|
2014-07-24 19:38:59 +02:00
|
|
|
// break;
|
|
|
|
// case "BeatDivisor":
|
2015-05-17 03:25:19 +02:00
|
|
|
// beatmap.beatDivisor = Byte.parseByte(tokens[1]);
|
2014-07-24 19:38:59 +02:00
|
|
|
// break;
|
|
|
|
// case "GridSize":
|
2015-05-17 03:25:19 +02:00
|
|
|
// beatmap.gridSize = Integer.parseInt(tokens[1]);
|
2014-07-24 19:38:59 +02:00
|
|
|
// break;
|
|
|
|
// case "TimelineZoom":
|
2015-05-17 03:25:19 +02:00
|
|
|
// beatmap.timelineZoom = Integer.parseInt(tokens[1]);
|
2014-07-24 19:38:59 +02:00
|
|
|
// break;
|
|
|
|
// default:
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// } catch (Exception e) {
|
|
|
|
// Log.warn(String.format("Failed to read editor line '%s' for file '%s'.",
|
|
|
|
// line, file.getAbsolutePath()), e);
|
2014-06-30 04:17:04 +02:00
|
|
|
// }
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "[Metadata]":
|
|
|
|
while ((line = in.readLine()) != null) {
|
|
|
|
line = line.trim();
|
|
|
|
if (!isValidLine(line))
|
|
|
|
continue;
|
|
|
|
if (line.charAt(0) == '[')
|
|
|
|
break;
|
2014-07-02 16:14:15 +02:00
|
|
|
if ((tokens = tokenize(line)) == null)
|
|
|
|
continue;
|
2014-07-24 19:38:59 +02:00
|
|
|
try {
|
|
|
|
switch (tokens[0]) {
|
|
|
|
case "Title":
|
2015-05-17 03:25:19 +02:00
|
|
|
beatmap.title = getDBString(tokens[1]);
|
2014-07-24 19:38:59 +02:00
|
|
|
break;
|
|
|
|
case "TitleUnicode":
|
2015-05-17 03:25:19 +02:00
|
|
|
beatmap.titleUnicode = getDBString(tokens[1]);
|
2014-07-24 19:38:59 +02:00
|
|
|
break;
|
|
|
|
case "Artist":
|
2015-05-17 03:25:19 +02:00
|
|
|
beatmap.artist = getDBString(tokens[1]);
|
2014-07-24 19:38:59 +02:00
|
|
|
break;
|
|
|
|
case "ArtistUnicode":
|
2015-05-17 03:25:19 +02:00
|
|
|
beatmap.artistUnicode = getDBString(tokens[1]);
|
2014-07-24 19:38:59 +02:00
|
|
|
break;
|
|
|
|
case "Creator":
|
2015-05-17 03:25:19 +02:00
|
|
|
beatmap.creator = getDBString(tokens[1]);
|
2014-07-24 19:38:59 +02:00
|
|
|
break;
|
|
|
|
case "Version":
|
2015-05-17 03:25:19 +02:00
|
|
|
beatmap.version = getDBString(tokens[1]);
|
2014-07-24 19:38:59 +02:00
|
|
|
break;
|
|
|
|
case "Source":
|
2015-05-17 03:25:19 +02:00
|
|
|
beatmap.source = getDBString(tokens[1]);
|
2014-07-24 19:38:59 +02:00
|
|
|
break;
|
|
|
|
case "Tags":
|
2015-05-17 03:25:19 +02:00
|
|
|
beatmap.tags = getDBString(tokens[1].toLowerCase());
|
2014-07-24 19:38:59 +02:00
|
|
|
break;
|
|
|
|
case "BeatmapID":
|
2015-05-17 03:25:19 +02:00
|
|
|
beatmap.beatmapID = Integer.parseInt(tokens[1]);
|
2014-07-24 19:38:59 +02:00
|
|
|
break;
|
|
|
|
case "BeatmapSetID":
|
2015-05-17 03:25:19 +02:00
|
|
|
beatmap.beatmapSetID = Integer.parseInt(tokens[1]);
|
2014-07-24 19:38:59 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.warn(String.format("Failed to read metadata '%s' for file '%s'.",
|
|
|
|
line, file.getAbsolutePath()), e);
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
2015-05-17 03:25:19 +02:00
|
|
|
if (beatmap.beatmapSetID <= 0) { // try to determine MSID from directory name
|
2015-02-10 05:22:58 +01:00
|
|
|
if (dir != null && dir.isDirectory()) {
|
|
|
|
String dirName = dir.getName();
|
|
|
|
if (!dirName.isEmpty() && dirName.matches(DIR_MSID_PATTERN))
|
2015-05-17 03:25:19 +02:00
|
|
|
beatmap.beatmapSetID = Integer.parseInt(dirName.substring(0, dirName.indexOf(' ')));
|
2015-02-10 05:22:58 +01:00
|
|
|
}
|
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "[Difficulty]":
|
|
|
|
while ((line = in.readLine()) != null) {
|
|
|
|
line = line.trim();
|
|
|
|
if (!isValidLine(line))
|
|
|
|
continue;
|
|
|
|
if (line.charAt(0) == '[')
|
|
|
|
break;
|
2014-07-02 16:14:15 +02:00
|
|
|
if ((tokens = tokenize(line)) == null)
|
|
|
|
continue;
|
2014-07-24 19:38:59 +02:00
|
|
|
try {
|
|
|
|
switch (tokens[0]) {
|
|
|
|
case "HPDrainRate":
|
2015-05-17 03:25:19 +02:00
|
|
|
beatmap.HPDrainRate = Float.parseFloat(tokens[1]);
|
2014-07-24 19:38:59 +02:00
|
|
|
break;
|
|
|
|
case "CircleSize":
|
2015-05-17 03:25:19 +02:00
|
|
|
beatmap.circleSize = Float.parseFloat(tokens[1]);
|
2014-07-24 19:38:59 +02:00
|
|
|
break;
|
|
|
|
case "OverallDifficulty":
|
2015-05-17 03:25:19 +02:00
|
|
|
beatmap.overallDifficulty = Float.parseFloat(tokens[1]);
|
2014-07-24 19:38:59 +02:00
|
|
|
break;
|
|
|
|
case "ApproachRate":
|
2015-05-17 03:25:19 +02:00
|
|
|
beatmap.approachRate = Float.parseFloat(tokens[1]);
|
2014-07-24 19:38:59 +02:00
|
|
|
break;
|
|
|
|
case "SliderMultiplier":
|
2015-05-17 03:25:19 +02:00
|
|
|
beatmap.sliderMultiplier = Float.parseFloat(tokens[1]);
|
2014-07-24 19:38:59 +02:00
|
|
|
break;
|
|
|
|
case "SliderTickRate":
|
2015-05-17 03:25:19 +02:00
|
|
|
beatmap.sliderTickRate = Float.parseFloat(tokens[1]);
|
2014-07-24 19:38:59 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.warn(String.format("Failed to read difficulty '%s' for file '%s'.",
|
|
|
|
line, file.getAbsolutePath()), e);
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
}
|
2015-05-17 03:25:19 +02:00
|
|
|
if (beatmap.approachRate == -1f) // not in old format
|
|
|
|
beatmap.approachRate = beatmap.overallDifficulty;
|
2014-06-30 04:17:04 +02:00
|
|
|
break;
|
|
|
|
case "[Events]":
|
|
|
|
while ((line = in.readLine()) != null) {
|
|
|
|
line = line.trim();
|
|
|
|
if (!isValidLine(line))
|
|
|
|
continue;
|
|
|
|
if (line.charAt(0) == '[')
|
|
|
|
break;
|
|
|
|
tokens = line.split(",");
|
|
|
|
switch (tokens[0]) {
|
|
|
|
case "0": // background
|
|
|
|
tokens[2] = tokens[2].replaceAll("^\"|\"$", "");
|
2015-05-29 09:07:58 +02:00
|
|
|
String ext = BeatmapParser.getExtension(tokens[2]);
|
2014-06-30 04:17:04 +02:00
|
|
|
if (ext.equals("jpg") || ext.equals("png"))
|
2015-06-09 09:10:44 +02:00
|
|
|
beatmap.bg = new File(dir, getDBString(tokens[2]));
|
2014-06-30 04:17:04 +02:00
|
|
|
break;
|
|
|
|
case "2": // break periods
|
2014-07-24 19:38:59 +02:00
|
|
|
try {
|
2015-05-17 03:25:19 +02:00
|
|
|
if (beatmap.breaks == null) // optional, create if needed
|
|
|
|
beatmap.breaks = new ArrayList<Integer>();
|
|
|
|
beatmap.breaks.add(Integer.parseInt(tokens[1]));
|
|
|
|
beatmap.breaks.add(Integer.parseInt(tokens[2]));
|
2014-07-24 19:38:59 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
Log.warn(String.format("Failed to read break period '%s' for file '%s'.",
|
|
|
|
line, file.getAbsolutePath()), e);
|
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Not implemented. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-05-17 03:25:19 +02:00
|
|
|
if (beatmap.breaks != null)
|
|
|
|
beatmap.breaks.trimToSize();
|
2014-06-30 04:17:04 +02:00
|
|
|
break;
|
|
|
|
case "[TimingPoints]":
|
|
|
|
while ((line = in.readLine()) != null) {
|
|
|
|
line = line.trim();
|
|
|
|
if (!isValidLine(line))
|
|
|
|
continue;
|
|
|
|
if (line.charAt(0) == '[')
|
|
|
|
break;
|
|
|
|
|
2014-07-24 19:38:59 +02:00
|
|
|
try {
|
2016-12-18 23:39:39 +01:00
|
|
|
parseSectionTimingPoints(beatmap, line);
|
2014-07-24 19:38:59 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
Log.warn(String.format("Failed to read timing point '%s' for file '%s'.",
|
|
|
|
line, file.getAbsolutePath()), e);
|
2014-07-09 19:36:42 +02:00
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
2015-05-17 03:25:19 +02:00
|
|
|
beatmap.timingPoints.trimToSize();
|
2014-06-30 04:17:04 +02:00
|
|
|
break;
|
|
|
|
case "[Colours]":
|
|
|
|
LinkedList<Color> colors = new LinkedList<Color>();
|
|
|
|
while ((line = in.readLine()) != null) {
|
|
|
|
line = line.trim();
|
|
|
|
if (!isValidLine(line))
|
|
|
|
continue;
|
|
|
|
if (line.charAt(0) == '[')
|
|
|
|
break;
|
2014-07-02 16:14:15 +02:00
|
|
|
if ((tokens = tokenize(line)) == null)
|
|
|
|
continue;
|
2014-07-24 19:38:59 +02:00
|
|
|
try {
|
2015-06-08 21:57:17 +02:00
|
|
|
String[] rgb = tokens[1].split(",");
|
|
|
|
Color color = new Color(
|
|
|
|
Integer.parseInt(rgb[0]),
|
|
|
|
Integer.parseInt(rgb[1]),
|
|
|
|
Integer.parseInt(rgb[2])
|
|
|
|
);
|
2014-07-24 19:38:59 +02:00
|
|
|
switch (tokens[0]) {
|
|
|
|
case "Combo1":
|
|
|
|
case "Combo2":
|
|
|
|
case "Combo3":
|
|
|
|
case "Combo4":
|
|
|
|
case "Combo5":
|
|
|
|
case "Combo6":
|
|
|
|
case "Combo7":
|
|
|
|
case "Combo8":
|
2015-06-08 21:57:17 +02:00
|
|
|
colors.add(color);
|
|
|
|
break;
|
|
|
|
case "SliderBorder":
|
|
|
|
beatmap.sliderBorder = color;
|
|
|
|
break;
|
2014-07-24 19:38:59 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.warn(String.format("Failed to read color '%s' for file '%s'.",
|
|
|
|
line, file.getAbsolutePath()), e);
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
}
|
2015-06-08 23:23:45 +02:00
|
|
|
if (!colors.isEmpty())
|
2015-05-17 03:25:19 +02:00
|
|
|
beatmap.combo = colors.toArray(new Color[colors.size()]);
|
2014-06-30 04:17:04 +02:00
|
|
|
break;
|
|
|
|
case "[HitObjects]":
|
2014-07-19 09:31:54 +02:00
|
|
|
int type = 0;
|
2014-06-30 04:17:04 +02:00
|
|
|
while ((line = in.readLine()) != null) {
|
|
|
|
line = line.trim();
|
|
|
|
if (!isValidLine(line))
|
|
|
|
continue;
|
|
|
|
if (line.charAt(0) == '[')
|
|
|
|
break;
|
|
|
|
/* Only type counts parsed at this time. */
|
|
|
|
tokens = line.split(",");
|
2014-07-24 19:38:59 +02:00
|
|
|
try {
|
|
|
|
type = Integer.parseInt(tokens[3]);
|
2015-05-17 03:42:03 +02:00
|
|
|
if ((type & HitObject.TYPE_CIRCLE) > 0)
|
2015-05-17 03:25:19 +02:00
|
|
|
beatmap.hitObjectCircle++;
|
2015-05-17 03:42:03 +02:00
|
|
|
else if ((type & HitObject.TYPE_SLIDER) > 0)
|
2015-05-17 03:25:19 +02:00
|
|
|
beatmap.hitObjectSlider++;
|
2015-05-17 03:42:03 +02:00
|
|
|
else //if ((type & HitObject.TYPE_SPINNER) > 0)
|
2015-05-17 03:25:19 +02:00
|
|
|
beatmap.hitObjectSpinner++;
|
2014-07-24 19:38:59 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
Log.warn(String.format("Failed to read hit object '%s' for file '%s'.",
|
|
|
|
line, file.getAbsolutePath()), e);
|
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
2014-07-18 03:16:15 +02:00
|
|
|
|
2014-07-24 19:38:59 +02:00
|
|
|
try {
|
|
|
|
// map length = last object end time (TODO: end on slider?)
|
2015-05-17 03:42:03 +02:00
|
|
|
if ((type & HitObject.TYPE_SPINNER) > 0) {
|
2014-07-24 19:38:59 +02:00
|
|
|
// some 'endTime' fields contain a ':' character (?)
|
|
|
|
int index = tokens[5].indexOf(':');
|
|
|
|
if (index != -1)
|
|
|
|
tokens[5] = tokens[5].substring(0, index);
|
2015-05-17 03:25:19 +02:00
|
|
|
beatmap.endTime = Integer.parseInt(tokens[5]);
|
2014-07-24 19:38:59 +02:00
|
|
|
} else if (type != 0)
|
2015-05-17 03:25:19 +02:00
|
|
|
beatmap.endTime = Integer.parseInt(tokens[2]);
|
2014-07-24 19:38:59 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
Log.warn(String.format("Failed to read hit object end time '%s' for file '%s'.",
|
|
|
|
line, file.getAbsolutePath()), e);
|
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
break;
|
|
|
|
default:
|
2014-07-04 00:50:44 +02:00
|
|
|
line = in.readLine();
|
2014-06-30 04:17:04 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-06-22 04:57:30 +02:00
|
|
|
if (md5stream != null)
|
|
|
|
beatmap.md5Hash = md5stream.getMD5();
|
2014-06-30 04:17:04 +02:00
|
|
|
} catch (IOException e) {
|
2015-01-16 03:55:26 +01:00
|
|
|
ErrorHandler.error(String.format("Failed to read file '%s'.", file.getAbsolutePath()), e, false);
|
2015-06-30 02:22:38 +02:00
|
|
|
} catch (NoSuchAlgorithmException e) {
|
|
|
|
ErrorHandler.error("Failed to get MD5 hash stream.", e, true);
|
|
|
|
|
|
|
|
// retry without MD5
|
|
|
|
hasNoMD5Algorithm = true;
|
|
|
|
return parseFile(file, dir, beatmaps, parseObjects);
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
|
2015-03-09 01:26:37 +01:00
|
|
|
// no associated audio file?
|
2015-05-17 03:25:19 +02:00
|
|
|
if (beatmap.audioFilename == null)
|
2015-03-09 01:26:37 +01:00
|
|
|
return null;
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
// parse hit objects now?
|
|
|
|
if (parseObjects)
|
2015-05-17 03:25:19 +02:00
|
|
|
parseHitObjects(beatmap);
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-05-17 03:25:19 +02:00
|
|
|
return beatmap;
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
|
2016-12-18 23:39:39 +01:00
|
|
|
/**
|
|
|
|
* Parses a timing point in the timingpoints section of a beatmap file
|
|
|
|
* @param beatmap the beatmap to add the timingpoint to
|
|
|
|
* @param line the line with timingpoint to parse
|
|
|
|
*/
|
|
|
|
private static void parseSectionTimingPoints(Beatmap beatmap, String line) {
|
|
|
|
TimingPoint timingPoint = new TimingPoint(line);
|
|
|
|
if(!timingPoint.isInherited()) {
|
|
|
|
int bpm = Math.round(60000 / timingPoint.getBeatLength());
|
|
|
|
if( beatmap.bpmMin == 0 ) {
|
|
|
|
beatmap.bpmMin = beatmap.bpmMax = bpm;
|
|
|
|
} else if( bpm < beatmap.bpmMin ) {
|
|
|
|
beatmap.bpmMin = bpm;
|
|
|
|
} else if( bpm > beatmap.bpmMax ) {
|
|
|
|
beatmap.bpmMax = bpm;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
beatmap.timingPoints.add(timingPoint);
|
|
|
|
}
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
/**
|
2015-05-17 03:25:19 +02:00
|
|
|
* Parses all hit objects in a beatmap.
|
|
|
|
* @param beatmap the beatmap to parse
|
2014-06-30 04:17:04 +02:00
|
|
|
*/
|
2015-05-17 03:25:19 +02:00
|
|
|
public static void parseHitObjects(Beatmap beatmap) {
|
|
|
|
if (beatmap.objects != null) // already parsed
|
2014-06-30 04:17:04 +02:00
|
|
|
return;
|
|
|
|
|
2015-05-17 03:42:03 +02:00
|
|
|
beatmap.objects = new HitObject[(beatmap.hitObjectCircle + beatmap.hitObjectSlider + beatmap.hitObjectSpinner)];
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-05-17 03:25:19 +02:00
|
|
|
try (BufferedReader in = new BufferedReader(new FileReader(beatmap.getFile()))) {
|
2014-06-30 04:17:04 +02:00
|
|
|
String line = in.readLine();
|
|
|
|
while (line != null) {
|
|
|
|
line = line.trim();
|
2014-07-18 21:11:57 +02:00
|
|
|
if (!line.equals("[HitObjects]"))
|
2014-06-30 04:17:04 +02:00
|
|
|
line = in.readLine();
|
2014-07-18 21:11:57 +02:00
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (line == null) {
|
2015-05-17 03:25:19 +02:00
|
|
|
Log.warn(String.format("No hit objects found in Beatmap '%s'.", beatmap.toString()));
|
2014-07-18 21:11:57 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2014-07-18 21:11:57 +02:00
|
|
|
// combo info
|
2015-06-08 23:23:45 +02:00
|
|
|
Color[] combo = beatmap.getComboColors();
|
2014-07-18 21:11:57 +02:00
|
|
|
int comboIndex = 0; // color index
|
|
|
|
int comboNumber = 1; // combo number
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2014-07-18 21:11:57 +02:00
|
|
|
int objectIndex = 0;
|
2015-02-16 00:51:07 +01:00
|
|
|
boolean first = true;
|
2015-05-17 03:25:19 +02:00
|
|
|
while ((line = in.readLine()) != null && objectIndex < beatmap.objects.length) {
|
2014-07-18 21:11:57 +02:00
|
|
|
line = line.trim();
|
2015-02-16 23:05:01 +01:00
|
|
|
if (!isValidLine(line))
|
2014-07-18 21:11:57 +02:00
|
|
|
continue;
|
|
|
|
if (line.charAt(0) == '[')
|
|
|
|
break;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2014-07-18 21:11:57 +02:00
|
|
|
// lines must have at minimum 5 parameters
|
|
|
|
int tokenCount = line.length() - line.replace(",", "").length();
|
2015-02-16 23:05:01 +01:00
|
|
|
if (tokenCount < 4)
|
2014-07-18 21:11:57 +02:00
|
|
|
continue;
|
|
|
|
|
2014-07-24 19:38:59 +02:00
|
|
|
try {
|
2015-05-17 03:42:03 +02:00
|
|
|
// create a new HitObject for each line
|
|
|
|
HitObject hitObject = new HitObject(line);
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2014-07-24 19:38:59 +02:00
|
|
|
// set combo info
|
|
|
|
// - new combo: get next combo index, reset combo number
|
|
|
|
// - else: maintain combo index, increase combo number
|
2015-03-01 17:06:46 +01:00
|
|
|
if (hitObject.isNewCombo() || first) {
|
2015-03-01 19:58:03 +01:00
|
|
|
int skip = (hitObject.isSpinner() ? 0 : 1) + hitObject.getComboSkip();
|
2015-02-19 01:35:26 +01:00
|
|
|
for (int i = 0; i < skip; i++) {
|
2015-06-08 23:23:45 +02:00
|
|
|
comboIndex = (comboIndex + 1) % combo.length;
|
2015-02-16 00:51:07 +01:00
|
|
|
comboNumber = 1;
|
|
|
|
}
|
2015-02-19 01:35:26 +01:00
|
|
|
first = false;
|
2015-02-16 00:51:07 +01:00
|
|
|
}
|
2015-02-16 23:13:16 +01:00
|
|
|
|
2014-07-24 19:38:59 +02:00
|
|
|
hitObject.setComboIndex(comboIndex);
|
|
|
|
hitObject.setComboNumber(comboNumber++);
|
2014-07-18 21:11:57 +02:00
|
|
|
|
2015-05-17 03:25:19 +02:00
|
|
|
beatmap.objects[objectIndex++] = hitObject;
|
2014-07-24 19:38:59 +02:00
|
|
|
} catch (Exception e) {
|
2015-09-02 08:41:47 +02:00
|
|
|
Log.warn(String.format("Failed to read hit object '%s' for beatmap '%s'.",
|
2015-05-17 03:25:19 +02:00
|
|
|
line, beatmap.toString()), e);
|
2014-07-24 19:38:59 +02:00
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
2015-09-02 08:41:47 +02:00
|
|
|
|
|
|
|
// 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);
|
2014-06-30 04:17:04 +02:00
|
|
|
} catch (IOException e) {
|
2015-05-17 03:25:19 +02:00
|
|
|
ErrorHandler.error(String.format("Failed to read file '%s'.", beatmap.getFile().getAbsolutePath()), e, false);
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns false if the line is too short or commented.
|
|
|
|
*/
|
|
|
|
private static boolean isValidLine(String line) {
|
|
|
|
return (line.length() > 1 && !line.startsWith("//"));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Splits line into two strings: tag, value.
|
2014-07-02 16:14:15 +02:00
|
|
|
* If no ':' character is present, null will be returned.
|
2014-06-30 04:17:04 +02:00
|
|
|
*/
|
|
|
|
private static String[] tokenize(String line) {
|
2014-07-02 16:14:15 +02:00
|
|
|
int index = line.indexOf(':');
|
|
|
|
if (index == -1) {
|
|
|
|
Log.debug(String.format("Failed to tokenize line: '%s'.", line));
|
|
|
|
return null;
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
2014-07-02 16:14:15 +02:00
|
|
|
|
|
|
|
String[] tokens = new String[2];
|
|
|
|
tokens[0] = line.substring(0, index).trim();
|
|
|
|
tokens[1] = line.substring(index + 1).trim();
|
2014-06-30 04:17:04 +02:00
|
|
|
return tokens;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the file extension of a file.
|
2015-09-10 05:51:16 +02:00
|
|
|
* @param file the file name
|
2014-06-30 04:17:04 +02:00
|
|
|
*/
|
|
|
|
public static String getExtension(String file) {
|
|
|
|
int i = file.lastIndexOf('.');
|
2014-07-02 16:14:15 +02:00
|
|
|
return (i != -1) ? file.substring(i + 1).toLowerCase() : "";
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
2014-07-06 03:00:52 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the name of the current file being parsed, or null if none.
|
|
|
|
*/
|
|
|
|
public static String getCurrentFileName() {
|
2015-03-08 05:24:19 +01:00
|
|
|
if (status == Status.PARSING)
|
2015-03-05 03:03:06 +01:00
|
|
|
return (currentFile != null) ? currentFile.getName() : null;
|
2015-03-08 05:24:19 +01:00
|
|
|
else
|
|
|
|
return (status == Status.NONE) ? null : "";
|
2014-07-06 03:00:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the progress of file parsing, or -1 if not parsing.
|
|
|
|
* @return the completion percent [0, 100] or -1
|
|
|
|
*/
|
|
|
|
public static int getParserProgress() {
|
|
|
|
if (currentDirectoryIndex == -1 || totalDirectories == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return currentDirectoryIndex * 100 / totalDirectories;
|
|
|
|
}
|
2015-01-15 03:48:24 +01:00
|
|
|
|
2015-03-05 03:03:06 +01:00
|
|
|
/**
|
2015-03-08 05:24:19 +01:00
|
|
|
* Returns the current parser status.
|
2015-03-05 03:03:06 +01:00
|
|
|
*/
|
2015-03-08 05:24:19 +01:00
|
|
|
public static Status getStatus() { return status; }
|
2015-03-05 03:03:06 +01:00
|
|
|
|
2015-01-15 03:48:24 +01:00
|
|
|
/**
|
|
|
|
* Returns the String object in the database for the given String.
|
|
|
|
* If none, insert the String into the database and return the original String.
|
|
|
|
* @param s the string to retrieve
|
|
|
|
* @return the string object
|
|
|
|
*/
|
2015-03-05 03:03:06 +01:00
|
|
|
public static String getDBString(String s) {
|
2015-01-15 03:48:24 +01:00
|
|
|
String DBString = stringdb.get(s);
|
|
|
|
if (DBString == null) {
|
|
|
|
stringdb.put(s, s);
|
|
|
|
return s;
|
|
|
|
} else
|
|
|
|
return DBString;
|
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|