Minor code cleaning.
Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
parent
be3adb3dc5
commit
6c369f6329
|
@ -44,10 +44,8 @@ import java.nio.ByteBuffer;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
|
|
||||||
|
@ -365,45 +363,6 @@ public class Utils {
|
||||||
dir.delete();
|
dir.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Wraps the given string into a list of split lines based on the width.
|
|
||||||
* @param text the text to split
|
|
||||||
* @param font the font used to draw the string
|
|
||||||
* @param width the maximum width of a line
|
|
||||||
* @return the list of split strings
|
|
||||||
* @author davedes (http://slick.ninjacave.com/forum/viewtopic.php?t=3778)
|
|
||||||
*/
|
|
||||||
public static List<String> wrap(String text, org.newdawn.slick.Font font, int width) {
|
|
||||||
List<String> list = new ArrayList<String>();
|
|
||||||
String str = text;
|
|
||||||
String line = "";
|
|
||||||
int i = 0;
|
|
||||||
int lastSpace = -1;
|
|
||||||
while (i < str.length()) {
|
|
||||||
char c = str.charAt(i);
|
|
||||||
if (Character.isWhitespace(c))
|
|
||||||
lastSpace = i;
|
|
||||||
String append = line + c;
|
|
||||||
if (font.getWidth(append) > width) {
|
|
||||||
int split = (lastSpace != -1) ? lastSpace : i;
|
|
||||||
int splitTrimmed = split;
|
|
||||||
if (lastSpace != -1 && split < str.length() - 1)
|
|
||||||
splitTrimmed++;
|
|
||||||
list.add(str.substring(0, split));
|
|
||||||
str = str.substring(splitTrimmed);
|
|
||||||
line = "";
|
|
||||||
i = 0;
|
|
||||||
lastSpace = -1;
|
|
||||||
} else {
|
|
||||||
line = append;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (str.length() != 0)
|
|
||||||
list.add(str);
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a the contents of a URL as a string.
|
* Returns a the contents of a URL as a string.
|
||||||
* @param url the remote URL
|
* @param url the remote URL
|
||||||
|
|
|
@ -160,7 +160,7 @@ public class Beatmap implements Comparable<Beatmap> {
|
||||||
public float HPDrainRate = 5f;
|
public float HPDrainRate = 5f;
|
||||||
|
|
||||||
/** CS: Size of circles and sliders (0:large ~ 10:small). */
|
/** CS: Size of circles and sliders (0:large ~ 10:small). */
|
||||||
public float circleSize = 4f;
|
public float circleSize = 5f;
|
||||||
|
|
||||||
/** OD: Affects timing window, spinners, and approach speed (0:easy ~ 10:hard). */
|
/** OD: Affects timing window, spinners, and approach speed (0:easy ~ 10:hard). */
|
||||||
public float overallDifficulty = 5f;
|
public float overallDifficulty = 5f;
|
||||||
|
@ -169,7 +169,7 @@ public class Beatmap implements Comparable<Beatmap> {
|
||||||
public float approachRate = -1f;
|
public float approachRate = -1f;
|
||||||
|
|
||||||
/** Slider movement speed multiplier. */
|
/** Slider movement speed multiplier. */
|
||||||
public float sliderMultiplier = 1f;
|
public float sliderMultiplier = 1.4f;
|
||||||
|
|
||||||
/** Rate at which slider ticks are placed (x per beat). */
|
/** Rate at which slider ticks are placed (x per beat). */
|
||||||
public float sliderTickRate = 1f;
|
public float sliderTickRate = 1f;
|
||||||
|
|
|
@ -69,7 +69,7 @@ public class BeatmapSet implements Iterable<Beatmap> {
|
||||||
* <li>1: Mapped by {Creator}
|
* <li>1: Mapped by {Creator}
|
||||||
* <li>2: Length: {} BPM: {} Objects: {}
|
* <li>2: Length: {} BPM: {} Objects: {}
|
||||||
* <li>3: Circles: {} Sliders: {} Spinners: {}
|
* <li>3: Circles: {} Sliders: {} Spinners: {}
|
||||||
* <li>4: CS:{} HP:{} AR:{} OD:{}
|
* <li>4: CS:{} HP:{} AR:{} OD:{} Stars:{}
|
||||||
* </ul>
|
* </ul>
|
||||||
* @param index the beatmap index
|
* @param index the beatmap index
|
||||||
* @throws IndexOutOfBoundsException
|
* @throws IndexOutOfBoundsException
|
||||||
|
@ -131,7 +131,7 @@ public class BeatmapSet implements Iterable<Beatmap> {
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// search: version, tags (remaining beatmaps)
|
// search: version, tags (remaining beatmaps)
|
||||||
for (int i = 1; i < beatmaps.size(); i++) {
|
for (int i = 1, n = beatmaps.size(); i < n; i++) {
|
||||||
beatmap = beatmaps.get(i);
|
beatmap = beatmaps.get(i);
|
||||||
if (beatmap.version.toLowerCase().contains(query) ||
|
if (beatmap.version.toLowerCase().contains(query) ||
|
||||||
beatmap.tags.contains(query))
|
beatmap.tags.contains(query))
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class BeatmapSetList {
|
||||||
|
|
||||||
/** Search pattern for conditional expressions. */
|
/** Search pattern for conditional expressions. */
|
||||||
private static final Pattern SEARCH_CONDITION_PATTERN = Pattern.compile(
|
private static final Pattern SEARCH_CONDITION_PATTERN = Pattern.compile(
|
||||||
"(ar|cs|od|hp|bpm|length|stars?)(=|==|>|>=|<|<=)((\\d*\\.)?\\d+)"
|
"(ar|cs|od|hp|bpm|length|stars?)(==?|>=?|<=?)((\\d*\\.)?\\d+)"
|
||||||
);
|
);
|
||||||
|
|
||||||
/** List containing all parsed nodes. */
|
/** List containing all parsed nodes. */
|
||||||
|
|
|
@ -39,13 +39,6 @@ public class HitObject {
|
||||||
TYPE_NEWCOMBO = 4, // not an object
|
TYPE_NEWCOMBO = 4, // not an object
|
||||||
TYPE_SPINNER = 8;
|
TYPE_SPINNER = 8;
|
||||||
|
|
||||||
/** Hit object type names. */
|
|
||||||
private static final String
|
|
||||||
CIRCLE = "circle",
|
|
||||||
SLIDER = "slider",
|
|
||||||
SPINNER = "spinner",
|
|
||||||
UNKNOWN = "unknown object";
|
|
||||||
|
|
||||||
/** Hit sound types (bits). */
|
/** Hit sound types (bits). */
|
||||||
public static final byte
|
public static final byte
|
||||||
SOUND_NORMAL = 0,
|
SOUND_NORMAL = 0,
|
||||||
|
@ -320,13 +313,13 @@ public class HitObject {
|
||||||
*/
|
*/
|
||||||
public String getTypeName() {
|
public String getTypeName() {
|
||||||
if (isCircle())
|
if (isCircle())
|
||||||
return CIRCLE;
|
return "circle";
|
||||||
else if (isSlider())
|
else if (isSlider())
|
||||||
return SLIDER;
|
return "slider";
|
||||||
else if (isSpinner())
|
else if (isSpinner())
|
||||||
return SPINNER;
|
return "spinner";
|
||||||
else
|
else
|
||||||
return UNKNOWN;
|
return "unknown object type";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -420,7 +420,7 @@ public class ButtonMenu extends BasicGameState {
|
||||||
for (int i = 0; i < title.length; i++) {
|
for (int i = 0; i < title.length; i++) {
|
||||||
// wrap text if too long
|
// wrap text if too long
|
||||||
if (Fonts.LARGE.getWidth(title[i]) > maxLineWidth) {
|
if (Fonts.LARGE.getWidth(title[i]) > maxLineWidth) {
|
||||||
List<String> list = Utils.wrap(title[i], Fonts.LARGE, maxLineWidth);
|
List<String> list = Fonts.wrap(Fonts.LARGE, title[i], maxLineWidth);
|
||||||
actualTitle.addAll(list);
|
actualTitle.addAll(list);
|
||||||
} else
|
} else
|
||||||
actualTitle.add(title[i]);
|
actualTitle.add(title[i]);
|
||||||
|
|
|
@ -24,8 +24,10 @@ import itdelatrisu.opsu.Options;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.FontFormatException;
|
import java.awt.FontFormatException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.newdawn.slick.SlickException;
|
import org.newdawn.slick.SlickException;
|
||||||
import org.newdawn.slick.UnicodeFont;
|
import org.newdawn.slick.UnicodeFont;
|
||||||
|
@ -110,4 +112,43 @@ public class Fonts {
|
||||||
Log.warn(String.format("Failed to load glyphs for string '%s'.", s), e);
|
Log.warn(String.format("Failed to load glyphs for string '%s'.", s), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wraps the given string into a list of split lines based on the width.
|
||||||
|
* @param font the font used to draw the string
|
||||||
|
* @param text the text to split
|
||||||
|
* @param width the maximum width of a line
|
||||||
|
* @return the list of split strings
|
||||||
|
* @author davedes (http://slick.ninjacave.com/forum/viewtopic.php?t=3778)
|
||||||
|
*/
|
||||||
|
public static List<String> wrap(org.newdawn.slick.Font font, String text, int width) {
|
||||||
|
List<String> list = new ArrayList<String>();
|
||||||
|
String str = text;
|
||||||
|
String line = "";
|
||||||
|
int i = 0;
|
||||||
|
int lastSpace = -1;
|
||||||
|
while (i < str.length()) {
|
||||||
|
char c = str.charAt(i);
|
||||||
|
if (Character.isWhitespace(c))
|
||||||
|
lastSpace = i;
|
||||||
|
String append = line + c;
|
||||||
|
if (font.getWidth(append) > width) {
|
||||||
|
int split = (lastSpace != -1) ? lastSpace : i;
|
||||||
|
int splitTrimmed = split;
|
||||||
|
if (lastSpace != -1 && split < str.length() - 1)
|
||||||
|
splitTrimmed++;
|
||||||
|
list.add(str.substring(0, split));
|
||||||
|
str = str.substring(splitTrimmed);
|
||||||
|
line = "";
|
||||||
|
i = 0;
|
||||||
|
lastSpace = -1;
|
||||||
|
} else {
|
||||||
|
line = append;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (str.length() != 0)
|
||||||
|
list.add(str);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user