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-17 03:25:19 +02:00
|
|
|
package itdelatrisu.opsu.beatmap;
|
|
|
|
|
|
|
|
import itdelatrisu.opsu.Options;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.util.ArrayList;
|
2015-03-05 03:03:06 +01:00
|
|
|
import java.util.LinkedList;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
import org.newdawn.slick.Color;
|
|
|
|
import org.newdawn.slick.Image;
|
|
|
|
import org.newdawn.slick.util.Log;
|
|
|
|
|
|
|
|
/**
|
2015-05-17 03:25:19 +02:00
|
|
|
* Beatmap structure storing data parsed from OSU files.
|
2014-06-30 04:17:04 +02:00
|
|
|
*/
|
2015-05-17 03:25:19 +02:00
|
|
|
public class Beatmap implements Comparable<Beatmap> {
|
2015-03-10 23:10:51 +01:00
|
|
|
/** Game modes. */
|
|
|
|
public static final byte MODE_OSU = 0, MODE_TAIKO = 1, MODE_CTB = 2, MODE_MANIA = 3;
|
|
|
|
|
2015-06-09 09:10:44 +02:00
|
|
|
/** Background image cache. */
|
|
|
|
private static final BeatmapImageCache bgImageCache = new BeatmapImageCache();
|
2015-01-22 06:44:45 +01:00
|
|
|
|
2015-06-09 09:10:44 +02:00
|
|
|
/**
|
|
|
|
* Returns the background image cache.
|
|
|
|
*/
|
|
|
|
public static BeatmapImageCache getBackgroundImageCache() { return bgImageCache; }
|
2015-02-10 03:40:38 +01:00
|
|
|
|
2015-05-17 03:25:19 +02:00
|
|
|
/** The OSU File object associated with this beatmap. */
|
2015-01-22 06:44:45 +01:00
|
|
|
private File file;
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
/**
|
2015-01-22 06:44:45 +01:00
|
|
|
* [General]
|
2014-06-30 04:17:04 +02:00
|
|
|
*/
|
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Audio file object. */
|
|
|
|
public File audioFilename;
|
|
|
|
|
|
|
|
/** Delay time before music starts (in ms). */
|
|
|
|
public int audioLeadIn = 0;
|
|
|
|
|
|
|
|
/** Audio hash (deprecated). */
|
|
|
|
// public String audioHash = "";
|
|
|
|
|
|
|
|
/** Start position of music preview (in ms). */
|
|
|
|
public int previewTime = -1;
|
|
|
|
|
|
|
|
/** Countdown type (0:disabled, 1:normal, 2:half, 3:double). */
|
|
|
|
public byte countdown = 0;
|
|
|
|
|
|
|
|
/** Sound samples ("None", "Normal", "Soft"). */
|
|
|
|
public String sampleSet = "";
|
|
|
|
|
|
|
|
/** How often closely placed hit objects will be stacked together. */
|
|
|
|
public float stackLeniency = 0.7f;
|
|
|
|
|
2015-03-10 23:10:51 +01:00
|
|
|
/** Game mode (MODE_* constants). */
|
|
|
|
public byte mode = MODE_OSU;
|
2015-01-22 06:44:45 +01:00
|
|
|
|
|
|
|
/** Whether the letterbox (top/bottom black bars) appears during breaks. */
|
|
|
|
public boolean letterboxInBreaks = false;
|
|
|
|
|
|
|
|
/** Whether the storyboard should be widescreen. */
|
|
|
|
public boolean widescreenStoryboard = false;
|
|
|
|
|
|
|
|
/** Whether to show an epilepsy warning. */
|
|
|
|
public boolean epilepsyWarning = false;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-01-21 01:01:18 +01:00
|
|
|
/**
|
2015-01-22 06:44:45 +01:00
|
|
|
* [Editor]
|
2015-01-21 01:01:18 +01:00
|
|
|
*/
|
2015-01-22 06:44:45 +01:00
|
|
|
|
|
|
|
/** List of editor bookmarks (in ms). */
|
|
|
|
// public int[] bookmarks;
|
|
|
|
|
|
|
|
/** Multiplier for "Distance Snap". */
|
|
|
|
// public float distanceSpacing = 0f;
|
|
|
|
|
|
|
|
/** Beat division. */
|
|
|
|
// public byte beatDivisor = 0;
|
|
|
|
|
|
|
|
/** Size of grid for "Grid Snap". */
|
|
|
|
// public int gridSize = 0;
|
|
|
|
|
|
|
|
/** Zoom in the editor timeline. */
|
|
|
|
// public int timelineZoom = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* [Metadata]
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** Song title. */
|
|
|
|
public String title = "", titleUnicode = "";
|
|
|
|
|
|
|
|
/** Song artist. */
|
|
|
|
public String artist = "", artistUnicode = "";
|
|
|
|
|
|
|
|
/** Beatmap creator. */
|
|
|
|
public String creator = "";
|
|
|
|
|
|
|
|
/** Beatmap difficulty. */
|
|
|
|
public String version = "";
|
|
|
|
|
|
|
|
/** Song source. */
|
|
|
|
public String source = "";
|
|
|
|
|
|
|
|
/** Song tags (for searching). */
|
|
|
|
public String tags = "";
|
|
|
|
|
|
|
|
/** Beatmap ID. */
|
|
|
|
public int beatmapID = 0;
|
|
|
|
|
|
|
|
/** Beatmap set ID. */
|
|
|
|
public int beatmapSetID = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* [Difficulty]
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** HP: Health drain rate (0:easy ~ 10:hard) */
|
|
|
|
public float HPDrainRate = 5f;
|
|
|
|
|
|
|
|
/** CS: Size of circles and sliders (0:large ~ 10:small). */
|
|
|
|
public float circleSize = 4f;
|
|
|
|
|
|
|
|
/** OD: Affects timing window, spinners, and approach speed (0:easy ~ 10:hard). */
|
|
|
|
public float overallDifficulty = 5f;
|
|
|
|
|
|
|
|
/** AR: How long circles stay on the screen (0:long ~ 10:short). */
|
|
|
|
public float approachRate = -1f;
|
|
|
|
|
|
|
|
/** Slider movement speed multiplier. */
|
|
|
|
public float sliderMultiplier = 1f;
|
|
|
|
|
|
|
|
/** Rate at which slider ticks are placed (x per beat). */
|
|
|
|
public float sliderTickRate = 1f;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* [Events]
|
|
|
|
*/
|
|
|
|
|
2015-06-09 09:10:44 +02:00
|
|
|
/** Background image file. */
|
|
|
|
public File bg;
|
2015-01-22 06:44:45 +01:00
|
|
|
|
2015-06-09 09:10:44 +02:00
|
|
|
/** Background video file. */
|
|
|
|
// public File video;
|
2015-01-22 06:44:45 +01:00
|
|
|
|
|
|
|
/** All break periods (start time, end time, ...). */
|
|
|
|
public ArrayList<Integer> breaks;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* [TimingPoints]
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** All timing points. */
|
2015-05-16 23:58:32 +02:00
|
|
|
public ArrayList<TimingPoint> timingPoints;
|
2015-01-22 06:44:45 +01:00
|
|
|
|
|
|
|
/** Song BPM range. */
|
2015-03-05 03:03:06 +01:00
|
|
|
public int bpmMin = 0, bpmMax = 0;
|
2015-01-22 06:44:45 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* [Colours]
|
|
|
|
*/
|
|
|
|
|
2015-06-08 23:23:45 +02:00
|
|
|
/** Combo colors (max 8). If null, the skin value is used. */
|
2015-01-22 06:44:45 +01:00
|
|
|
public Color[] combo;
|
|
|
|
|
2015-06-08 21:57:17 +02:00
|
|
|
/** Slider border color. If null, the skin value is used. */
|
|
|
|
public Color sliderBorder;
|
2015-06-30 02:22:38 +02:00
|
|
|
|
|
|
|
/** MD5 hash of this file. */
|
2015-06-14 03:16:27 +02:00
|
|
|
public String md5Hash;
|
2015-06-30 02:22:38 +02:00
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/**
|
|
|
|
* [HitObjects]
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** All hit objects. */
|
2015-05-17 03:42:03 +02:00
|
|
|
public HitObject[] objects;
|
2015-01-22 06:44:45 +01:00
|
|
|
|
|
|
|
/** Number of individual objects. */
|
|
|
|
public int
|
|
|
|
hitObjectCircle = 0,
|
|
|
|
hitObjectSlider = 0,
|
|
|
|
hitObjectSpinner = 0;
|
|
|
|
|
|
|
|
/** Last object end time (in ms). */
|
|
|
|
public int endTime = -1;
|
2015-01-21 01:01:18 +01:00
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
/**
|
|
|
|
* Constructor.
|
2015-05-17 03:25:19 +02:00
|
|
|
* @param file the file associated with this beatmap
|
2014-06-30 04:17:04 +02:00
|
|
|
*/
|
2015-05-17 03:25:19 +02:00
|
|
|
public Beatmap(File file) {
|
2014-06-30 04:17:04 +02:00
|
|
|
this.file = file;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the associated file object.
|
2014-08-25 05:48:52 +02:00
|
|
|
* @return the File object
|
2014-06-30 04:17:04 +02:00
|
|
|
*/
|
|
|
|
public File getFile() { return file; }
|
|
|
|
|
2014-08-25 05:48:52 +02:00
|
|
|
/**
|
|
|
|
* Returns the song title.
|
|
|
|
* If configured, the Unicode string will be returned instead.
|
|
|
|
* @return the song title
|
|
|
|
*/
|
|
|
|
public String getTitle() {
|
|
|
|
return (Options.useUnicodeMetadata() && !titleUnicode.isEmpty()) ? titleUnicode : title;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the song artist.
|
|
|
|
* If configured, the Unicode string will be returned instead.
|
|
|
|
* @return the song artist
|
|
|
|
*/
|
|
|
|
public String getArtist() {
|
|
|
|
return (Options.useUnicodeMetadata() && !artistUnicode.isEmpty()) ? artistUnicode : artist;
|
|
|
|
}
|
|
|
|
|
2015-06-08 23:23:45 +02:00
|
|
|
/**
|
|
|
|
* Returns the list of combo colors (max 8).
|
|
|
|
* If the beatmap does not provide colors, the skin colors will be returned instead.
|
|
|
|
* @return the combo colors
|
|
|
|
*/
|
|
|
|
public Color[] getComboColors() {
|
|
|
|
return (combo != null) ? combo : Options.getSkin().getComboColors();
|
|
|
|
}
|
|
|
|
|
2015-06-08 21:57:17 +02:00
|
|
|
/**
|
|
|
|
* 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();
|
|
|
|
}
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
/**
|
2015-05-17 03:25:19 +02:00
|
|
|
* Draws the beatmap background.
|
2014-06-30 04:17:04 +02:00
|
|
|
* @param width the container width
|
|
|
|
* @param height the container height
|
|
|
|
* @param alpha the alpha value
|
2015-02-10 03:40:38 +01:00
|
|
|
* @param stretch if true, stretch to screen dimensions; otherwise, maintain aspect ratio
|
2014-06-30 04:17:04 +02:00
|
|
|
* @return true if successful, false if any errors were produced
|
|
|
|
*/
|
2015-02-10 03:40:38 +01:00
|
|
|
public boolean drawBG(int width, int height, float alpha, boolean stretch) {
|
2014-06-30 04:17:04 +02:00
|
|
|
if (bg == null)
|
|
|
|
return false;
|
|
|
|
try {
|
2015-06-09 09:10:44 +02:00
|
|
|
Image bgImage = bgImageCache.get(this);
|
2015-01-21 01:01:18 +01:00
|
|
|
if (bgImage == null) {
|
2015-06-09 09:10:44 +02:00
|
|
|
bgImage = new Image(bg.getAbsolutePath());
|
|
|
|
bgImageCache.put(this, bgImage);
|
2015-01-21 01:01:18 +01:00
|
|
|
}
|
2015-02-10 03:40:38 +01:00
|
|
|
|
|
|
|
int swidth = width;
|
|
|
|
int sheight = height;
|
|
|
|
if (!stretch) {
|
2015-02-14 20:10:47 +01:00
|
|
|
// fit image to screen
|
2015-02-10 03:40:38 +01:00
|
|
|
if (bgImage.getWidth() / (float) bgImage.getHeight() > width / (float) height) // x > y
|
|
|
|
sheight = (int) (width * bgImage.getHeight() / (float) bgImage.getWidth());
|
|
|
|
else
|
|
|
|
swidth = (int) (height * bgImage.getWidth() / (float) bgImage.getHeight());
|
2015-02-14 20:10:47 +01:00
|
|
|
} else {
|
2015-02-15 07:40:01 +01:00
|
|
|
// fill screen while maintaining aspect ratio
|
2015-02-14 20:10:47 +01:00
|
|
|
if (bgImage.getWidth() / (float) bgImage.getHeight() > width / (float) height) // x > y
|
|
|
|
swidth = (int) (height * bgImage.getWidth() / (float) bgImage.getHeight());
|
|
|
|
else
|
|
|
|
sheight = (int) (width * bgImage.getHeight() / (float) bgImage.getWidth());
|
2015-02-10 03:40:38 +01:00
|
|
|
}
|
|
|
|
bgImage = bgImage.getScaledCopy(swidth, sheight);
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
bgImage.setAlpha(alpha);
|
2015-02-10 03:40:38 +01:00
|
|
|
bgImage.drawCentered(width / 2, height / 2);
|
2014-06-30 04:17:04 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
Log.warn(String.format("Failed to get background image '%s'.", bg), e);
|
|
|
|
bg = null; // don't try to load the file again until a restart
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-17 03:25:19 +02:00
|
|
|
* Compares two Beatmap objects first by overall difficulty, then by total objects.
|
2014-06-30 04:17:04 +02:00
|
|
|
*/
|
2015-01-16 21:44:13 +01:00
|
|
|
@Override
|
2015-05-17 03:25:19 +02:00
|
|
|
public int compareTo(Beatmap that) {
|
2014-06-30 10:03:39 +02:00
|
|
|
int cmp = Float.compare(this.overallDifficulty, that.overallDifficulty);
|
2014-06-30 04:17:04 +02:00
|
|
|
if (cmp == 0)
|
|
|
|
cmp = Integer.compare(
|
|
|
|
this.hitObjectCircle + this.hitObjectSlider + this.hitObjectSpinner,
|
|
|
|
that.hitObjectCircle + that.hitObjectSlider + that.hitObjectSpinner
|
|
|
|
);
|
|
|
|
return cmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a formatted string: "Artist - Title [Version]"
|
|
|
|
* @see java.lang.Object#toString()
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
2014-08-25 05:48:52 +02:00
|
|
|
return String.format("%s - %s [%s]", getArtist(), getTitle(), version);
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
2015-03-05 03:03:06 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the {@link #breaks} field formatted as a string,
|
|
|
|
* or null if the field is null.
|
|
|
|
*/
|
|
|
|
public String breaksToString() {
|
|
|
|
if (breaks == null)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
for (int i : breaks) {
|
|
|
|
sb.append(i);
|
|
|
|
sb.append(',');
|
|
|
|
}
|
|
|
|
if (sb.length() > 0)
|
|
|
|
sb.setLength(sb.length() - 1);
|
|
|
|
return sb.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the {@link #breaks} field from a string.
|
|
|
|
* @param s the string
|
|
|
|
*/
|
|
|
|
public void breaksFromString(String s) {
|
|
|
|
if (s == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.breaks = new ArrayList<Integer>();
|
|
|
|
String[] tokens = s.split(",");
|
|
|
|
for (int i = 0; i < tokens.length; i++)
|
|
|
|
breaks.add(Integer.parseInt(tokens[i]));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the {@link #timingPoints} field formatted as a string,
|
|
|
|
* or null if the field is null.
|
|
|
|
*/
|
|
|
|
public String timingPointsToString() {
|
|
|
|
if (timingPoints == null)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
2015-05-16 23:58:32 +02:00
|
|
|
for (TimingPoint p : timingPoints) {
|
2015-03-05 03:03:06 +01:00
|
|
|
sb.append(p.toString());
|
|
|
|
sb.append('|');
|
|
|
|
}
|
|
|
|
if (sb.length() > 0)
|
|
|
|
sb.setLength(sb.length() - 1);
|
|
|
|
return sb.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the {@link #timingPoints} field from a string.
|
|
|
|
* @param s the string
|
|
|
|
*/
|
|
|
|
public void timingPointsFromString(String s) {
|
2015-05-16 23:58:32 +02:00
|
|
|
this.timingPoints = new ArrayList<TimingPoint>();
|
2015-03-05 03:03:06 +01:00
|
|
|
if (s == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
String[] tokens = s.split("\\|");
|
|
|
|
for (int i = 0; i < tokens.length; i++) {
|
|
|
|
try {
|
2015-05-16 23:58:32 +02:00
|
|
|
timingPoints.add(new TimingPoint(tokens[i]));
|
2015-03-05 03:03:06 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
Log.warn(String.format("Failed to read timing point '%s'.", tokens[i]), e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
timingPoints.trimToSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the {@link #combo} field formatted as a string,
|
2015-03-08 08:05:01 +01:00
|
|
|
* or null if the field is null or the default combo.
|
2015-03-05 03:03:06 +01:00
|
|
|
*/
|
|
|
|
public String comboToString() {
|
2015-06-08 23:23:45 +02:00
|
|
|
if (combo == null)
|
2015-03-05 03:03:06 +01:00
|
|
|
return null;
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
for (int i = 0; i < combo.length; i++) {
|
|
|
|
Color c = combo[i];
|
|
|
|
sb.append(c.getRed());
|
|
|
|
sb.append(',');
|
|
|
|
sb.append(c.getGreen());
|
|
|
|
sb.append(',');
|
|
|
|
sb.append(c.getBlue());
|
|
|
|
sb.append('|');
|
|
|
|
}
|
|
|
|
if (sb.length() > 0)
|
|
|
|
sb.setLength(sb.length() - 1);
|
|
|
|
return sb.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the {@link #combo} field from a string.
|
|
|
|
* @param s the string
|
|
|
|
*/
|
|
|
|
public void comboFromString(String s) {
|
|
|
|
if (s == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
LinkedList<Color> colors = new LinkedList<Color>();
|
|
|
|
String[] tokens = s.split("\\|");
|
|
|
|
for (int i = 0; i < tokens.length; i++) {
|
|
|
|
String[] rgb = tokens[i].split(",");
|
|
|
|
colors.add(new Color(Integer.parseInt(rgb[0]), Integer.parseInt(rgb[1]), Integer.parseInt(rgb[2])));
|
|
|
|
}
|
2015-06-08 23:23:45 +02:00
|
|
|
if (!colors.isEmpty())
|
2015-03-05 03:03:06 +01:00
|
|
|
this.combo = colors.toArray(new Color[colors.size()]);
|
|
|
|
}
|
2015-06-08 21:57:17 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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])));
|
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|