From cd3d53336db14c29011f4d1751baf97307bb0e5a Mon Sep 17 00:00:00 2001 From: Jeffrey Han Date: Thu, 3 Sep 2015 22:16:52 -0500 Subject: [PATCH] A couple of API improvements. Signed-off-by: Jeffrey Han --- src/itdelatrisu/opsu/beatmap/BeatmapSet.java | 10 +++++++--- .../opsu/beatmap/BeatmapSetList.java | 3 +-- .../opsu/beatmap/BeatmapSetNode.java | 10 +++++++++- .../opsu/beatmap/BeatmapSortOrder.java | 6 ++---- src/itdelatrisu/opsu/states/SongMenu.java | 19 +++++++++---------- .../opsu/ui/animations/AnimatedValue.java | 5 +++++ 6 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/itdelatrisu/opsu/beatmap/BeatmapSet.java b/src/itdelatrisu/opsu/beatmap/BeatmapSet.java index 85eecb9c..df96187e 100644 --- a/src/itdelatrisu/opsu/beatmap/BeatmapSet.java +++ b/src/itdelatrisu/opsu/beatmap/BeatmapSet.java @@ -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 { /** List of associated beatmaps. */ - private ArrayList beatmaps; + private final ArrayList beatmaps; /** * Constructor. @@ -58,6 +59,9 @@ public class BeatmapSet { */ public Beatmap remove(int index) { return beatmaps.remove(index); } + @Override + public Iterator iterator() { return beatmaps.iterator(); } + /** * Returns an array of strings containing beatmap information. *
    @@ -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 diff --git a/src/itdelatrisu/opsu/beatmap/BeatmapSetList.java b/src/itdelatrisu/opsu/beatmap/BeatmapSetList.java index 2ddce0e3..9fdd9fdb 100644 --- a/src/itdelatrisu/opsu/beatmap/BeatmapSetList.java +++ b/src/itdelatrisu/opsu/beatmap/BeatmapSetList.java @@ -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); } diff --git a/src/itdelatrisu/opsu/beatmap/BeatmapSetNode.java b/src/itdelatrisu/opsu/beatmap/BeatmapSetNode.java index 84b9771a..947631c5 100644 --- a/src/itdelatrisu/opsu/beatmap/BeatmapSetNode.java +++ b/src/itdelatrisu/opsu/beatmap/BeatmapSetNode.java @@ -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 diff --git a/src/itdelatrisu/opsu/beatmap/BeatmapSortOrder.java b/src/itdelatrisu/opsu/beatmap/BeatmapSortOrder.java index ad1d53c5..78ca593c 100644 --- a/src/itdelatrisu/opsu/beatmap/BeatmapSortOrder.java +++ b/src/itdelatrisu/opsu/beatmap/BeatmapSortOrder.java @@ -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; } diff --git a/src/itdelatrisu/opsu/states/SongMenu.java b/src/itdelatrisu/opsu/states/SongMenu.java index 498cba0f..50b373fa 100644 --- a/src/itdelatrisu/opsu/states/SongMenu.java +++ b/src/itdelatrisu/opsu/states/SongMenu.java @@ -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; } diff --git a/src/itdelatrisu/opsu/ui/animations/AnimatedValue.java b/src/itdelatrisu/opsu/ui/animations/AnimatedValue.java index 4cad5959..da8bd8d5 100644 --- a/src/itdelatrisu/opsu/ui/animations/AnimatedValue.java +++ b/src/itdelatrisu/opsu/ui/animations/AnimatedValue.java @@ -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