Skip to content

Commit

Permalink
Added custom fixed speed option.
Browse files Browse the repository at this point in the history
Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
  • Loading branch information
itdelatrisu committed Feb 4, 2017
1 parent 510944f commit b22b1fb
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/itdelatrisu/opsu/options/OptionGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public class OptionGroup {
GameOption.FIXED_HP,
GameOption.FIXED_AR,
GameOption.FIXED_OD,
GameOption.FIXED_SPEED,
}),
new OptionGroup("SEEKING", new GameOption[] {
GameOption.CHECKPOINT,
Expand Down
30 changes: 25 additions & 5 deletions src/itdelatrisu/opsu/options/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ public void read(String s) {
@Override
public void read(String s) {
int i = (int) (Float.parseFloat(s) * 100f);
if (i >= 50 && i <= 200)
if (i >= getMinValue() && i <= getMaxValue())
val = i;
}
},
Expand Down Expand Up @@ -571,7 +571,7 @@ public void setValue(int value) {
@Override
public void read(String s) {
int i = (int) (Float.parseFloat(s) * 10f);
if (i >= 0 && i <= 100)
if (i >= getMinValue() && i <= getMaxValue())
val = i;
}
},
Expand All @@ -585,7 +585,7 @@ public void read(String s) {
@Override
public void read(String s) {
int i = (int) (Float.parseFloat(s) * 10f);
if (i >= 0 && i <= 100)
if (i >= getMinValue() && i <= getMaxValue())
val = i;
}
},
Expand All @@ -599,7 +599,7 @@ public void read(String s) {
@Override
public void read(String s) {
int i = (int) (Float.parseFloat(s) * 10f);
if (i >= 0 && i <= 100)
if (i >= getMinValue() && i <= getMaxValue())
val = i;
}
},
Expand All @@ -613,7 +613,21 @@ public void read(String s) {
@Override
public void read(String s) {
int i = (int) (Float.parseFloat(s) * 10f);
if (i >= 0 && i <= 100)
if (i >= getMinValue() && i <= getMaxValue())
val = i;
}
},
FIXED_SPEED ("Fixed speed", "FixedSpeed", "Determines the speed of the music.", 0, 0, 300) {
@Override
public String getValueString() { return (val == 0) ? "Disabled" : String.format("%.2fx", val / 100f); }

@Override
public String write() { return String.format(Locale.US, "%.2f", val / 100f); }

@Override
public void read(String s) {
int i = (int) (Float.parseFloat(s) * 100f);
if (i >= getMinValue() && i <= getMaxValue())
val = i;
}
},
Expand Down Expand Up @@ -1165,6 +1179,12 @@ public static void setDisplayMode(Container app) {
*/
public static float getFixedOD() { return GameOption.FIXED_OD.getIntegerValue() / 10f; }

/**
* Returns the fixed speed override, if any.
* @return the speed value (0, 3], 0f if disabled
*/
public static float getFixedSpeed() { return GameOption.FIXED_SPEED.getIntegerValue() / 100f; }

/**
* Returns whether or not to render loading text in the splash screen.
* @return true if enabled
Expand Down
21 changes: 16 additions & 5 deletions src/itdelatrisu/opsu/states/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@ else if (key == Options.getGameKeyRight())

// skip to checkpoint
MusicController.setPosition(checkpoint);
MusicController.setPitch(GameMod.getSpeedMultiplier() * playbackSpeed.getModifier());
MusicController.setPitch(getCurrentPitch());
if (video != null)
loadVideo(checkpoint);
while (objectIndex < gameObjects.length &&
Expand All @@ -1214,7 +1214,7 @@ else if (key == Options.getGameKeyRight())
break;
if (isReplay || GameMod.AUTO.isActive()) {
playbackSpeed = playbackSpeed.next();
MusicController.setPitch(GameMod.getSpeedMultiplier() * playbackSpeed.getModifier());
MusicController.setPitch(getCurrentPitch());
}
break;
case Input.KEY_UP:
Expand Down Expand Up @@ -1257,7 +1257,7 @@ public void mousePressed(int button, int x, int y) {
// playback speed button
else if (playbackSpeed.getButton().contains(x, y)) {
playbackSpeed = playbackSpeed.next();
MusicController.setPitch(GameMod.getSpeedMultiplier() * playbackSpeed.getModifier());
MusicController.setPitch(getCurrentPitch());
}

// replay seeking
Expand Down Expand Up @@ -1568,6 +1568,11 @@ else if (hitObject.isSpinner())
if (beatmap.localMusicOffset != 0)
UI.getNotificationManager().sendBarNotification(String.format("Using local beatmap offset (%dms)", beatmap.localMusicOffset));

// using custom difficulty settings?
if (Options.getFixedCS() > 0f || Options.getFixedAR() > 0f || Options.getFixedOD() > 0f ||
Options.getFixedHP() > 0f || Options.getFixedSpeed() > 0f)
UI.getNotificationManager().sendNotification("Playing with custom difficulty settings.");

// load video
if (beatmap.video != null) {
loadVideo((beatmap.videoOffset < 0) ? -beatmap.videoOffset : 0);
Expand All @@ -1584,7 +1589,7 @@ else if (hitObject.isSpinner())
skipButton.resetHover();
if (isReplay || GameMod.AUTO.isActive())
playbackSpeed.getButton().resetHover();
MusicController.setPitch(GameMod.getSpeedMultiplier() * playbackSpeed.getModifier());
MusicController.setPitch(getCurrentPitch());
}

@Override
Expand Down Expand Up @@ -1821,7 +1826,7 @@ private synchronized boolean skipIntro() {
MusicController.resume();
}
MusicController.setPosition(firstObjectTime - SKIP_OFFSET);
MusicController.setPitch(GameMod.getSpeedMultiplier() * playbackSpeed.getModifier());
MusicController.setPitch(getCurrentPitch());
replaySkipTime = (isReplay) ? -1 : trackPosition;
if (isReplay) {
replayX = (int) skipButton.getX();
Expand Down Expand Up @@ -2290,6 +2295,12 @@ private boolean hasMoreObjects() {
return objectIndex < gameObjects.length || !passedObjects.isEmpty();
}

/** Returns the current pitch. */
private float getCurrentPitch() {
float base = (Options.getFixedSpeed() > 0f) ? Options.getFixedSpeed() : 1f;
return base * GameMod.getSpeedMultiplier() * playbackSpeed.getModifier();
}

/**
* Returns true if the coordinates are within the music position bar bounds.
* @param cx the x coordinate
Expand Down

0 comments on commit b22b1fb

Please # to comment.