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

View File

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

View File

@ -32,7 +32,7 @@ import org.newdawn.slick.Image;
*/ */
public class BeatmapSetNode { public class BeatmapSetNode {
/** The associated beatmap set. */ /** The associated beatmap set. */
private BeatmapSet beatmapSet; private final BeatmapSet beatmapSet;
/** Index of the selected beatmap (-1 if not focused). */ /** Index of the selected beatmap (-1 if not focused). */
public int beatmapIndex = -1; public int beatmapIndex = -1;
@ -57,6 +57,14 @@ public class BeatmapSetNode {
*/ */
public BeatmapSet getBeatmapSet() { return beatmapSet; } 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. * Draws the button.
* @param x the x coordinate * @param x the x coordinate

View File

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

View File

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