A couple of API improvements.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2015-09-03 22:16:52 -05:00
parent 14948846f5
commit cd3d53336d
6 changed files with 33 additions and 20 deletions

View File

@ -21,14 +21,15 @@ package itdelatrisu.opsu.beatmap;
import itdelatrisu.opsu.GameMod;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.concurrent.TimeUnit;
/**
* Data type containing all beatmaps in a beatmap set.
*/
public class BeatmapSet {
public class BeatmapSet implements Iterable<Beatmap> {
/** List of associated beatmaps. */
private ArrayList<Beatmap> beatmaps;
private final ArrayList<Beatmap> beatmaps;
/**
* Constructor.
@ -58,6 +59,9 @@ public class BeatmapSet {
*/
public Beatmap remove(int index) { return beatmaps.remove(index); }
@Override
public Iterator<Beatmap> iterator() { return beatmaps.iterator(); }
/**
* Returns an array of strings containing beatmap information.
* <ul>
@ -139,7 +143,7 @@ public class BeatmapSet {
/**
* Checks whether the beatmap set matches a given condition.
* @param type the condition type (ar, cs, od, hp, bpm, length)
* @param type the condition type (ar, cs, od, hp, bpm, length, star/stars)
* @param operator the operator {@literal (=/==, >, >=, <, <=)}
* @param value the value
* @return true if the condition is met

View File

@ -171,8 +171,7 @@ public class BeatmapSetList {
mapCount -= beatmapSet.size();
if (beatmap.beatmapSetID > 0)
MSIDdb.remove(beatmap.beatmapSetID);
for (int i = 0, n = beatmapSet.size(); i < n; i++) {
Beatmap bm = beatmapSet.get(i);
for (Beatmap bm : beatmapSet) {
if (bm.md5Hash != null)
this.beatmapHashDB.remove(bm.md5Hash);
}

View File

@ -32,7 +32,7 @@ import org.newdawn.slick.Image;
*/
public class BeatmapSetNode {
/** The associated beatmap set. */
private BeatmapSet beatmapSet;
private final BeatmapSet beatmapSet;
/** Index of the selected beatmap (-1 if not focused). */
public int beatmapIndex = -1;
@ -57,6 +57,14 @@ public class BeatmapSetNode {
*/
public BeatmapSet getBeatmapSet() { return beatmapSet; }
/**
* Returns the selected beatmap (based on {@link #beatmapIndex}).
* @return the beatmap, or null if the index is invalid
*/
public Beatmap getSelectedBeatmap() {
return (beatmapIndex < 0 || beatmapIndex >= beatmapSet.size()) ? null : beatmapSet.get(beatmapIndex);
}
/**
* Draws the button.
* @param x the x coordinate

View File

@ -123,13 +123,11 @@ public enum BeatmapSortOrder {
@Override
public int compare(BeatmapSetNode v, BeatmapSetNode w) {
int vMax = 0, wMax = 0;
for (int i = 0, size = v.getBeatmapSet().size(); i < size; i++) {
Beatmap beatmap = v.getBeatmapSet().get(i);
for (Beatmap beatmap : v.getBeatmapSet()) {
if (beatmap.endTime > vMax)
vMax = beatmap.endTime;
}
for (int i = 0, size = w.getBeatmapSet().size(); i < size; i++) {
Beatmap beatmap = w.getBeatmapSet().get(i);
for (Beatmap beatmap : w.getBeatmapSet()) {
if (beatmap.endTime > wMax)
wMax = beatmap.endTime;
}

View File

@ -349,7 +349,7 @@ public class SongMenu extends BasicGameState {
// background
if (focusNode != null) {
Beatmap focusNodeBeatmap = focusNode.getBeatmapSet().get(focusNode.beatmapIndex);
Beatmap focusNodeBeatmap = focusNode.getSelectedBeatmap();
if (!focusNodeBeatmap.drawBackground(width, height, bgAlpha.getValue(), true))
GameImage.PLAYFIELD.getImage().draw();
}
@ -553,7 +553,7 @@ public class SongMenu extends BasicGameState {
// fade in background
if (focusNode != null) {
Beatmap focusNodeBeatmap = focusNode.getBeatmapSet().get(focusNode.beatmapIndex);
Beatmap focusNodeBeatmap = focusNode.getSelectedBeatmap();
if (!focusNodeBeatmap.isBackgroundLoading())
bgAlpha.update(delta);
}
@ -1052,7 +1052,7 @@ public class SongMenu extends BasicGameState {
// reload scores
if (focusNode != null) {
scoreMap = ScoreDB.getMapSetScores(focusNode.getBeatmapSet().get(focusNode.beatmapIndex));
scoreMap = ScoreDB.getMapSetScores(focusNode.getSelectedBeatmap());
focusScores = getScoreDataForNode(focusNode, true);
}
@ -1065,7 +1065,7 @@ public class SongMenu extends BasicGameState {
case BEATMAP: // clear all scores
if (stateActionNode == null || stateActionNode.beatmapIndex == -1)
break;
Beatmap beatmap = stateActionNode.getBeatmapSet().get(stateActionNode.beatmapIndex);
Beatmap beatmap = stateActionNode.getSelectedBeatmap();
ScoreDB.deleteScore(beatmap);
if (stateActionNode == focusNode) {
focusScores = null;
@ -1076,7 +1076,7 @@ public class SongMenu extends BasicGameState {
if (stateActionScore == null)
break;
ScoreDB.deleteScore(stateActionScore);
scoreMap = ScoreDB.getMapSetScores(focusNode.getBeatmapSet().get(focusNode.beatmapIndex));
scoreMap = ScoreDB.getMapSetScores(focusNode.getSelectedBeatmap());
focusScores = getScoreDataForNode(focusNode, true);
startScore = 0;
break;
@ -1235,7 +1235,7 @@ public class SongMenu extends BasicGameState {
if (changeStartNode || (startNode.index == 0 && startNode.beatmapIndex == -1 && startNode.prev == null))
startNode = node;
focusNode = BeatmapSetList.get().getNode(node, beatmapIndex);
Beatmap beatmap = focusNode.getBeatmapSet().get(focusNode.beatmapIndex);
Beatmap beatmap = focusNode.getSelectedBeatmap();
MusicController.play(beatmap, false, preview);
// load scores
@ -1335,7 +1335,7 @@ public class SongMenu extends BasicGameState {
if (scoreMap == null || scoreMap.isEmpty() || node.beatmapIndex == -1) // node not expanded
return null;
Beatmap beatmap = node.getBeatmapSet().get(node.beatmapIndex);
Beatmap beatmap = node.getSelectedBeatmap();
ScoreData[] scores = scoreMap.get(beatmap.version);
if (scores == null || scores.length < 1) // no scores
return null;
@ -1411,8 +1411,7 @@ public class SongMenu extends BasicGameState {
* @param beatmapSet the set of beatmaps
*/
private void calculateStarRatings(BeatmapSet beatmapSet) {
for (int i = 0, n = beatmapSet.size(); i < n; i++) {
Beatmap beatmap = beatmapSet.get(i);
for (Beatmap beatmap : beatmapSet) {
if (beatmap.starRating >= 0) { // already calculated
beatmapsCalculated.put(beatmap, beatmapsCalculated.get(beatmap));
continue;
@ -1443,7 +1442,7 @@ public class SongMenu extends BasicGameState {
SoundController.playSound(SoundEffect.MENUHIT);
Beatmap beatmap = MusicController.getBeatmap();
if (focusNode == null || beatmap != focusNode.getBeatmapSet().get(focusNode.beatmapIndex)) {
if (focusNode == null || beatmap != focusNode.getSelectedBeatmap()) {
UI.sendBarNotification("Unable to load the beatmap audio.");
return;
}

View File

@ -95,6 +95,11 @@ public class AnimatedValue {
}
}
/**
* Returns the animation equation being used.
*/
public AnimationEquation getEquation() { return eqn; }
/**
* Sets the animation equation to use.
* @param eqn the new equation