got rid of dependency injection, it doesn't add anything at this point and only slows down things and makes a mess. Also some refactoring.

This commit is contained in:
yugecin 2017-05-21 11:12:55 +02:00
parent 1ebf2c2dcb
commit ec53f531c8
72 changed files with 675 additions and 929 deletions

View File

@ -8,7 +8,8 @@ import itdelatrisu.opsu.objects.GameObject;
import itdelatrisu.opsu.objects.curves.Vec2f; import itdelatrisu.opsu.objects.curves.Vec2f;
import org.newdawn.slick.Color; import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics; import org.newdawn.slick.Graphics;
import yugecin.opsudance.options.Options;
import static yugecin.opsudance.core.InstanceContainer.displayContainer;
/** /**
* This class is just a dummy {@link GameObject} to place in the middle of 2 GameObjects. * This class is just a dummy {@link GameObject} to place in the middle of 2 GameObjects.
@ -22,8 +23,8 @@ public class FakeGameObject extends GameObject {
public FakeGameObject() { public FakeGameObject() {
this.start = new Vec2f(); this.start = new Vec2f();
this.end = new Vec2f(); this.end = new Vec2f();
this.start.x = this.end.x = Options.width / 2; this.start.x = this.end.x = displayContainer.width / 2;
this.start.y = this.end.y = Options.height / 2; this.start.y = this.end.y = displayContainer.height / 2;
} }
public FakeGameObject(GameObject start, GameObject end) { public FakeGameObject(GameObject start, GameObject end) {

View File

@ -5,7 +5,8 @@ import itdelatrisu.opsu.Utils;
import itdelatrisu.opsu.objects.GameObject; import itdelatrisu.opsu.objects.GameObject;
import yugecin.opsudance.movers.Mover; import yugecin.opsudance.movers.Mover;
import yugecin.opsudance.movers.factories.AutoMoverFactory; import yugecin.opsudance.movers.factories.AutoMoverFactory;
import yugecin.opsudance.options.Options;
import static yugecin.opsudance.core.InstanceContainer.*;
/** /**
* Created by Alex Wieser on 09.10.2016. * Created by Alex Wieser on 09.10.2016.
@ -130,6 +131,6 @@ public class CombinedSpiralMover extends Mover {
} }
private boolean checkBounds(double[] pos) { private boolean checkBounds(double[] pos) {
return 0 < pos[0] && pos[0] < Options.width && 0 < pos[1] && pos[1] < Options.height; return 0 < pos[0] && pos[0] < displayContainer.width && 0 < pos[1] && pos[1] < displayContainer.height;
} }
} }

View File

@ -7,7 +7,8 @@ import awlex.ospu.movers.CombinedSpiralMover;
import yugecin.opsudance.movers.Mover; import yugecin.opsudance.movers.Mover;
import awlex.ospu.movers.SpiralToMover; import awlex.ospu.movers.SpiralToMover;
import yugecin.opsudance.movers.factories.MoverFactory; import yugecin.opsudance.movers.factories.MoverFactory;
import yugecin.opsudance.options.Options;
import static yugecin.opsudance.core.InstanceContainer.displayContainer;
/** /**
* Created by Alex Wieser on 09.10.2016. * Created by Alex Wieser on 09.10.2016.
@ -87,7 +88,7 @@ public class SpiralMoverFactory implements MoverFactory {
* @return * @return
*/ */
private boolean checkBounds(double[] pos) { private boolean checkBounds(double[] pos) {
return 0 < pos[0] && pos[0] < Options.width && 0 < pos[1] && pos[1] < Options.height; return 0 < pos[0] && pos[0] < displayContainer.width && 0 < pos[1] && pos[1] < displayContainer.height;
} }
@Override @Override

View File

@ -1,9 +1,10 @@
package awlex.ospu.spinners; package awlex.ospu.spinners;
import itdelatrisu.opsu.Utils; import itdelatrisu.opsu.Utils;
import yugecin.opsudance.options.Options;
import yugecin.opsudance.spinners.Spinner; import yugecin.opsudance.spinners.Spinner;
import static yugecin.opsudance.core.InstanceContainer.*;
/** /**
* Created by Alex Wieser on 09.10.2016. * Created by Alex Wieser on 09.10.2016.
* WHO DO YOU THINK I AM? * WHO DO YOU THINK I AM?
@ -42,11 +43,11 @@ public class SpiralSpinner extends Spinner {
double ang; double ang;
double rad; double rad;
for (int i = 0; i < SIZE / 2; i++) { for (int i = 0; i < SIZE / 2; i++) {
MAX_RAD = (int) (Options.height * .35); MAX_RAD = (int) (displayContainer.height * .35);
ang = (DENSITY * (Math.PI / SIZE) * i); ang = (DENSITY * (Math.PI / SIZE) * i);
rad = (MAX_RAD / (SIZE / 2)) * i; rad = (MAX_RAD / (SIZE / 2)) * i;
int offsetX = Options.width / 2; int offsetX = displayContainer.width / 2;
int offsetY = Options.height / 2; int offsetY = displayContainer.height / 2;
points[SIZE / 2 - 1 - i] = new double[]{ points[SIZE / 2 - 1 - i] = new double[]{
offsetX + rad * Math.cos(ang), offsetX + rad * Math.cos(ang),
offsetY + rad * Math.sin(ang) offsetY + rad * Math.sin(ang)
@ -83,12 +84,12 @@ public class SpiralSpinner extends Spinner {
} }
private void rotatePointAroundCenter(double[] point, double beta) { private void rotatePointAroundCenter(double[] point, double beta) {
double angle = Math.atan2(point[1] - Options.height / 2, point[0] - Options.width / 2); double angle = Math.atan2(point[1] - displayContainer.height / 2, point[0] - displayContainer.width / 2);
double rad = Utils.distance(point[0], point[1], Options.width / 2, Options.height / 2); double rad = Utils.distance(point[0], point[1], displayContainer.width / 2, displayContainer.height / 2);
//rotationMatrix //rotationMatrix
point[0] = Options.width / 2 + rad * (Math.cos(angle) * Math.cos(beta) - Math.sin(angle) * Math.sin(beta)); point[0] = displayContainer.width / 2 + rad * (Math.cos(angle) * Math.cos(beta) - Math.sin(angle) * Math.sin(beta));
point[1] = Options.height / 2 + rad * (Math.cos(angle) * Math.sin(beta) + Math.sin(angle) * Math.cos(beta)); point[1] = displayContainer.height / 2 + rad * (Math.cos(angle) * Math.sin(beta) + Math.sin(angle) * Math.cos(beta));
} }

View File

@ -24,7 +24,6 @@ import itdelatrisu.opsu.audio.SoundController;
import itdelatrisu.opsu.audio.SoundEffect; import itdelatrisu.opsu.audio.SoundEffect;
import itdelatrisu.opsu.beatmap.Beatmap; import itdelatrisu.opsu.beatmap.Beatmap;
import itdelatrisu.opsu.beatmap.HitObject; import itdelatrisu.opsu.beatmap.HitObject;
import itdelatrisu.opsu.downloads.Updater;
import itdelatrisu.opsu.objects.curves.Curve; import itdelatrisu.opsu.objects.curves.Curve;
import itdelatrisu.opsu.replay.Replay; import itdelatrisu.opsu.replay.Replay;
import itdelatrisu.opsu.replay.ReplayFrame; import itdelatrisu.opsu.replay.ReplayFrame;
@ -42,25 +41,17 @@ import org.newdawn.slick.Animation;
import org.newdawn.slick.Color; import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics; import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image; import org.newdawn.slick.Image;
import yugecin.opsudance.core.inject.Inject;
import yugecin.opsudance.core.inject.InstanceContainer;
import yugecin.opsudance.options.Configuration;
import yugecin.opsudance.skinning.SkinService; import yugecin.opsudance.skinning.SkinService;
import yugecin.opsudance.utils.SlickUtil; import yugecin.opsudance.utils.SlickUtil;
import static yugecin.opsudance.options.Options.*; import static yugecin.opsudance.options.Options.*;
import static yugecin.opsudance.core.InstanceContainer.*;
/** /**
* Holds game data and renders all related elements. * Holds game data and renders all related elements.
*/ */
public class GameData { public class GameData {
@Inject
private Configuration config;
@Inject
private InstanceContainer instanceContainer;
/** Delta multiplier for steady HP drain. */ /** Delta multiplier for steady HP drain. */
public static final float HP_DRAIN_MULTIPLIER = 1 / 200f; public static final float HP_DRAIN_MULTIPLIER = 1 / 200f;
@ -354,17 +345,10 @@ public class GameData {
/** Whether this object is used for gameplay (true) or score viewing (false). */ /** Whether this object is used for gameplay (true) or score viewing (false). */
private boolean isGameplay; private boolean isGameplay;
/** Container dimensions. */
private int width, height;
/** /**
* Constructor for gameplay. * Constructor for gameplay.
* @param width container width
* @param height container height
*/ */
public GameData(int width, int height) { public GameData() {
this.width = width;
this.height = height;
this.isGameplay = true; this.isGameplay = true;
clear(); clear();
@ -375,12 +359,8 @@ public class GameData {
* This will initialize all parameters and images needed for the * This will initialize all parameters and images needed for the
* {@link #drawRankingElements(Graphics, Beatmap)} method. * {@link #drawRankingElements(Graphics, Beatmap)} method.
* @param s the ScoreData object * @param s the ScoreData object
* @param width container width
* @param height container height
*/ */
public GameData(ScoreData s, int width, int height) { public GameData(ScoreData s) {
this.width = width;
this.height = height;
this.isGameplay = false; this.isGameplay = false;
this.scoreData = s; this.scoreData = s;
@ -395,8 +375,9 @@ public class GameData {
hitResultCount[HIT_300K] = 0; hitResultCount[HIT_300K] = 0;
hitResultCount[HIT_100K] = s.katu; hitResultCount[HIT_100K] = s.katu;
hitResultCount[HIT_MISS] = s.miss; hitResultCount[HIT_MISS] = s.miss;
this.replay = (s.replayString == null) ? null : if (s.replayString != null) {
instanceContainer.injectFields(new Replay(new File(config.replayDir, String.format("%s.osr", s.replayString)))); this.replay = new Replay(new File(config.replayDir, s.replayString + ".osr"));
}
loadImages(); loadImages();
} }
@ -622,6 +603,8 @@ public class GameData {
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void drawGameElements(Graphics g, boolean breakPeriod, boolean firstObject, float alpha) { public void drawGameElements(Graphics g, boolean breakPeriod, boolean firstObject, float alpha) {
int width = displayContainer.width;
int height = displayContainer.height;
boolean relaxAutoPilot = (GameMod.RELAX.isActive() || GameMod.AUTOPILOT.isActive()); boolean relaxAutoPilot = (GameMod.RELAX.isActive() || GameMod.AUTOPILOT.isActive());
int margin = (int) (width * 0.008f); int margin = (int) (width * 0.008f);
float uiScale = GameImage.getUIscale(); float uiScale = GameImage.getUIscale();
@ -813,6 +796,9 @@ public class GameData {
* @param beatmap the beatmap * @param beatmap the beatmap
*/ */
public void drawRankingElements(Graphics g, Beatmap beatmap) { public void drawRankingElements(Graphics g, Beatmap beatmap) {
int width = displayContainer.width;
int height = displayContainer.height;
// TODO Version 2 skins // TODO Version 2 skins
float rankingHeight = 75; float rankingHeight = 75;
float scoreTextScale = 1.0f; float scoreTextScale = 1.0f;
@ -925,7 +911,7 @@ public class GameData {
if (hitResult.hitResultType == HitObjectType.SPINNER && hitResult.result != HIT_MISS) { if (hitResult.hitResultType == HitObjectType.SPINNER && hitResult.result != HIT_MISS) {
Image spinnerOsu = GameImage.SPINNER_OSU.getImage(); Image spinnerOsu = GameImage.SPINNER_OSU.getImage();
spinnerOsu.setAlpha(hitResult.alpha); spinnerOsu.setAlpha(hitResult.alpha);
spinnerOsu.drawCentered(width / 2, height / 4); spinnerOsu.drawCentered(displayContainer.width / 2, displayContainer.height / 4);
spinnerOsu.setAlpha(1f); spinnerOsu.setAlpha(1f);
} else if (OPTION_SHOW_HIT_LIGHTING.state && !hitResult.hideResult && hitResult.result != HIT_MISS && } else if (OPTION_SHOW_HIT_LIGHTING.state && !hitResult.hideResult && hitResult.result != HIT_MISS &&
// hit lighting // hit lighting
@ -1199,7 +1185,7 @@ public class GameData {
// combo burst // combo burst
if (comboBurstIndex > -1 && OPTION_SHOW_COMBO_BURSTS.state) { if (comboBurstIndex > -1 && OPTION_SHOW_COMBO_BURSTS.state) {
int leftX = 0; int leftX = 0;
int rightX = width - comboBurstImages[comboBurstIndex].getWidth(); int rightX = displayContainer.width - comboBurstImages[comboBurstIndex].getWidth();
if (comboBurstX < leftX) { if (comboBurstX < leftX) {
comboBurstX += (delta / 2f) * GameImage.getUIscale(); comboBurstX += (delta / 2f) * GameImage.getUIscale();
if (comboBurstX > leftX) if (comboBurstX > leftX)
@ -1260,7 +1246,7 @@ public class GameData {
} }
comboBurstAlpha = 0.8f; comboBurstAlpha = 0.8f;
if ((comboBurstIndex % 2) == 0) { if ((comboBurstIndex % 2) == 0) {
comboBurstX = width; comboBurstX = displayContainer.width;
} else { } else {
comboBurstX = comboBurstImages[0].getWidth() * -1; comboBurstX = comboBurstImages[0].getWidth() * -1;
} }
@ -1603,7 +1589,7 @@ public class GameData {
replay = new Replay(); replay = new Replay();
replay.mode = Beatmap.MODE_OSU; replay.mode = Beatmap.MODE_OSU;
replay.version = Updater.get().getBuildDate(); replay.version = updater.getBuildDate();
replay.beatmapHash = (beatmap == null) ? "" : beatmap.md5Hash; replay.beatmapHash = (beatmap == null) ? "" : beatmap.md5Hash;
replay.playerName = ""; // TODO replay.playerName = ""; // TODO
replay.replayHash = Long.toString(System.currentTimeMillis()); // TODO replay.replayHash = Long.toString(System.currentTimeMillis()); // TODO

View File

@ -18,14 +18,18 @@
package itdelatrisu.opsu; package itdelatrisu.opsu;
import org.newdawn.slick.util.Log;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.lang.reflect.Field;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.jar.JarEntry; import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import static yugecin.opsudance.core.InstanceContainer.*;
/** /**
* Native loader, based on the JarSplice launcher. * Native loader, based on the JarSplice launcher.
@ -33,38 +37,55 @@ import java.util.jar.JarFile;
* @author http://ninjacave.com * @author http://ninjacave.com
*/ */
public class NativeLoader { public class NativeLoader {
/** The directory to unpack natives to. */
private final File nativeDir;
/** public static void loadNatives() {
* Constructor. try {
* @param dir the directory to unpack natives to unpackNatives();
*/ } catch (IOException e) {
public NativeLoader(File dir) { String msg = String.format("Could not unpack native(s): %s", e.getMessage());
nativeDir = dir; throw new RuntimeException(msg, e);
}
String nativepath = config.NATIVE_DIR.getAbsolutePath();
System.setProperty("org.lwjgl.librarypath", nativepath);
System.setProperty("java.library.path", nativepath);
try {
// Workaround for "java.library.path" property being read-only.
// http://stackoverflow.com/a/24988095
Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
fieldSysPath.setAccessible(true);
fieldSysPath.set(null, null);
} catch (Exception e) {
Log.warn("Failed to set 'sys_paths' field.", e);
}
} }
/** /**
* Unpacks natives for the current operating system to the natives directory. * Unpacks natives for the current operating system to the natives directory.
* @throws IOException if an I/O exception occurs * @throws IOException if an I/O exception occurs
*/ */
public void loadNatives() throws IOException { public static void unpackNatives() throws IOException {
if (!nativeDir.exists()) if (env.jarfile == null) {
nativeDir.mkdir();
JarFile jarFile = Utils.getJarFile();
if (jarFile == null)
return; return;
}
Enumeration<JarEntry> entries = jarFile.entries(); if (!config.NATIVE_DIR.exists() && !config.NATIVE_DIR.mkdir()) {
String msg = String.format("Could not create folder '%s'",
config.NATIVE_DIR.getAbsolutePath());
throw new RuntimeException(msg);
}
Enumeration<JarEntry> entries = env.jarfile.entries();
while (entries.hasMoreElements()) { while (entries.hasMoreElements()) {
JarEntry e = entries.nextElement(); JarEntry e = entries.nextElement();
if (e == null) if (e == null)
break; break;
File f = new File(nativeDir, e.getName()); File f = new File(config.NATIVE_DIR, e.getName());
if (isNativeFile(e.getName()) && !e.isDirectory() && e.getName().indexOf('/') == -1 && !f.exists()) { if (isNativeFile(e.getName()) && !e.isDirectory() && e.getName().indexOf('/') == -1 && !f.exists()) {
InputStream in = jarFile.getInputStream(jarFile.getEntry(e.getName())); InputStream in = env.jarfile.getInputStream(env.jarfile.getEntry(e.getName()));
OutputStream out = new FileOutputStream(f); OutputStream out = new FileOutputStream(f);
byte[] buffer = new byte[65536]; byte[] buffer = new byte[65536];
@ -77,7 +98,7 @@ public class NativeLoader {
} }
} }
jarFile.close(); env.jarfile.close();
} }
/** /**
@ -85,7 +106,7 @@ public class NativeLoader {
* @param entryName the file name * @param entryName the file name
* @return true if the file is a native that should be loaded, false otherwise * @return true if the file is a native that should be loaded, false otherwise
*/ */
private boolean isNativeFile(String entryName) { private static boolean isNativeFile(String entryName) {
String osName = System.getProperty("os.name"); String osName = System.getProperty("os.name");
String name = entryName.toLowerCase(); String name = entryName.toLowerCase();
@ -101,4 +122,5 @@ public class NativeLoader {
} }
return false; return false;
} }
} }

View File

@ -18,6 +18,7 @@
package itdelatrisu.opsu; package itdelatrisu.opsu;
import com.sun.istack.internal.Nullable;
import itdelatrisu.opsu.downloads.Download; import itdelatrisu.opsu.downloads.Download;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
@ -30,14 +31,12 @@ import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.SocketTimeoutException; import java.net.SocketTimeoutException;
import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
import java.util.Arrays; import java.util.Arrays;
import java.util.Scanner; import java.util.Scanner;
import java.util.jar.JarFile;
import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext; import javax.net.ssl.SSLContext;
@ -55,7 +54,8 @@ import org.newdawn.slick.util.Log;
import com.sun.jna.platform.FileUtils; import com.sun.jna.platform.FileUtils;
import yugecin.opsudance.core.DisplayContainer; import yugecin.opsudance.core.DisplayContainer;
import yugecin.opsudance.core.errorhandling.ErrorHandler; import yugecin.opsudance.core.errorhandling.ErrorHandler;
import yugecin.opsudance.options.Options;
import static yugecin.opsudance.core.InstanceContainer.*;
/** /**
* Contains miscellaneous utilities. * Contains miscellaneous utilities.
@ -418,43 +418,6 @@ public class Utils {
return String.format("%02d:%02d:%02d", seconds / 3600, (seconds / 60) % 60, seconds % 60); return String.format("%02d:%02d:%02d", seconds / 3600, (seconds / 60) % 60, seconds % 60);
} }
/**
* Returns whether or not the application is running within a JAR.
* @return true if JAR, false if file
*/
public static boolean isJarRunning() {
return Utils.class.getResource(String.format("%s.class", Utils.class.getSimpleName())).toString().startsWith("jar:");
}
/**
* Returns the JarFile for the application.
* @return the JAR file, or null if it could not be determined
*/
public static JarFile getJarFile() {
if (!isJarRunning())
return null;
try {
return new JarFile(new File(Utils.class.getProtectionDomain().getCodeSource().getLocation().toURI()), false);
} catch (URISyntaxException | IOException e) {
Log.error("Could not determine the JAR file.", e);
return null;
}
}
/**
* Returns the directory where the application is being run.
* @return the directory, or null if it could not be determined
*/
public static File getRunningDirectory() {
try {
return new File(Utils.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
} catch (URISyntaxException e) {
Log.error("Could not get the running directory.", e);
return null;
}
}
/** /**
* Parses the integer string argument as a boolean: * Parses the integer string argument as a boolean:
* {@code 1} is {@code true}, and all other values are {@code false}. * {@code 1} is {@code true}, and all other values are {@code false}.
@ -470,8 +433,9 @@ public class Utils {
* most recent update to the working directory (e.g. fetch or successful push). * most recent update to the working directory (e.g. fetch or successful push).
* @return the 40-character SHA-1 hash, or null if it could not be determined * @return the 40-character SHA-1 hash, or null if it could not be determined
*/ */
@Nullable
public static String getGitHash() { public static String getGitHash() {
if (isJarRunning()) if (env.isJarRunning)
return null; return null;
File f = new File(".git/refs/remotes/origin/master"); File f = new File(".git/refs/remotes/origin/master");
if (!f.isFile()) if (!f.isFile())
@ -517,10 +481,10 @@ public class Utils {
} }
public static int getQuadrant(double x, double y) { public static int getQuadrant(double x, double y) {
if (x < Options.width / 2d) { if (x < displayContainer.width / 2d) {
return y < Options.height / 2d ? 2 : 3; return y < displayContainer.height / 2d ? 2 : 3;
} }
return y < Options.height / 2d ? 1 : 4; return y < displayContainer.height / 2d ? 1 : 4;
} }
/* /*
@ -537,24 +501,24 @@ public class Utils {
*/ */
public static float[] mirrorPoint(float x, float y) { public static float[] mirrorPoint(float x, float y) {
double dx = x - Options.width / 2d; double dx = x - displayContainer.width / 2d;
double dy = y - Options.height / 2d; double dy = y - displayContainer.height / 2d;
double ang = Math.atan2(dy, dx); double ang = Math.atan2(dy, dx);
double d = -Math.sqrt(dx * dx + dy * dy); double d = -Math.sqrt(dx * dx + dy * dy);
return new float[]{ return new float[]{
(float) (Options.width / 2d + Math.cos(ang) * d), (float) (displayContainer.width / 2d + Math.cos(ang) * d),
(float) (Options.height / 2d + Math.sin(ang) * d) (float) (displayContainer.height / 2d + Math.sin(ang) * d)
}; };
} }
public static float[] mirrorPoint(float x, float y, float degrees) { public static float[] mirrorPoint(float x, float y, float degrees) {
double dx = x - Options.width / 2d; double dx = x - displayContainer.width / 2d;
double dy = y - Options.height / 2d; double dy = y - displayContainer.height / 2d;
double ang = Math.atan2(dy, dx) + (degrees * Math.PI / 180d); double ang = Math.atan2(dy, dx) + (degrees * Math.PI / 180d);
double d = Math.sqrt(dx * dx + dy * dy); double d = Math.sqrt(dx * dx + dy * dy);
return new float[]{ return new float[]{
(float) (Options.width / 2d + Math.cos(ang) * d), (float) (displayContainer.width / 2d + Math.cos(ang) * d),
(float) (Options.height / 2d + Math.sin(ang) * d) (float) (displayContainer.height / 2d + Math.sin(ang) * d)
}; };
} }

View File

@ -35,12 +35,10 @@ import org.newdawn.slick.Color;
import org.newdawn.slick.util.Log; import org.newdawn.slick.util.Log;
import yugecin.opsudance.core.errorhandling.ErrorHandler; import yugecin.opsudance.core.errorhandling.ErrorHandler;
import yugecin.opsudance.core.events.EventBus; import yugecin.opsudance.core.events.EventBus;
import yugecin.opsudance.core.inject.Inject;
import yugecin.opsudance.core.inject.InstanceContainer;
import yugecin.opsudance.events.BubbleNotificationEvent; import yugecin.opsudance.events.BubbleNotificationEvent;
import yugecin.opsudance.options.Configuration;
import yugecin.opsudance.skinning.SkinService; import yugecin.opsudance.skinning.SkinService;
import static yugecin.opsudance.core.InstanceContainer.*;
import static yugecin.opsudance.options.Options.*; import static yugecin.opsudance.options.Options.*;
/** /**
@ -48,12 +46,6 @@ import static yugecin.opsudance.options.Options.*;
*/ */
public class BeatmapParser { public class BeatmapParser {
@Inject
private InstanceContainer instanceContainer;
@Inject
private Configuration config;
/** The string lookup database. */ /** The string lookup database. */
private static HashMap<String, String> stringdb = new HashMap<String, String>(); private static HashMap<String, String> stringdb = new HashMap<String, String>();
@ -78,14 +70,9 @@ public class BeatmapParser {
/** If no Provider supports a MessageDigestSpi implementation for the MD5 algorithm. */ /** If no Provider supports a MessageDigestSpi implementation for the MD5 algorithm. */
private boolean hasNoMD5Algorithm = false; private boolean hasNoMD5Algorithm = false;
@Inject
public BeatmapParser() {
}
/** /**
* Invokes parser for each OSU file in a root directory and * Invokes parser for each OSU file in a root directory and
* adds the beatmaps to a new BeatmapSetList. * adds the beatmaps to a new BeatmapSetList.
* @param root the root directory (search has depth 1)
*/ */
public void parseAll() { public void parseAll() {
// create a new BeatmapSetList // create a new BeatmapSetList
@ -93,7 +80,7 @@ public class BeatmapParser {
// create a new watch service // create a new watch service
if (OPTION_ENABLE_WATCH_SERVICE.state) { if (OPTION_ENABLE_WATCH_SERVICE.state) {
BeatmapWatchService.create(instanceContainer); BeatmapWatchService.create();
} }
// parse all directories // parse all directories

View File

@ -40,10 +40,9 @@ import java.util.concurrent.Executors;
import org.newdawn.slick.util.Log; import org.newdawn.slick.util.Log;
import yugecin.opsudance.core.events.EventBus; import yugecin.opsudance.core.events.EventBus;
import yugecin.opsudance.core.inject.InstanceContainer;
import yugecin.opsudance.events.BubbleNotificationEvent; import yugecin.opsudance.events.BubbleNotificationEvent;
import yugecin.opsudance.options.Configuration;
import static yugecin.opsudance.core.InstanceContainer.*;
import static yugecin.opsudance.options.Options.*; import static yugecin.opsudance.options.Options.*;
/* /*
@ -83,6 +82,7 @@ import static yugecin.opsudance.options.Options.*;
* @author The Java Tutorials (http://docs.oracle.com/javase/tutorial/essential/io/examples/WatchDir.java) (base) * @author The Java Tutorials (http://docs.oracle.com/javase/tutorial/essential/io/examples/WatchDir.java) (base)
*/ */
public class BeatmapWatchService { public class BeatmapWatchService {
/** Beatmap watcher service instance. */ /** Beatmap watcher service instance. */
private static BeatmapWatchService ws; private static BeatmapWatchService ws;
@ -90,14 +90,14 @@ public class BeatmapWatchService {
* Creates a new watch service instance (overwriting any previous instance), * Creates a new watch service instance (overwriting any previous instance),
* registers the beatmap directory, and starts processing events. * registers the beatmap directory, and starts processing events.
*/ */
public static void create(InstanceContainer instanceContainer) { public static void create() {
// close the existing watch service // close the existing watch service
destroy(); destroy();
// create a new watch service // create a new watch service
try { try {
ws = instanceContainer.provide(BeatmapWatchService.class); ws = new BeatmapWatchService();
ws.register(instanceContainer.provide(Configuration.class).beatmapDir.toPath()); ws.register(config.beatmapDir.toPath());
} catch (IOException e) { } catch (IOException e) {
Log.error("Could not create watch service", e); Log.error("Could not create watch service", e);
EventBus.post(new BubbleNotificationEvent("Could not create watch service", BubbleNotificationEvent.COMMONCOLOR_RED)); EventBus.post(new BubbleNotificationEvent("Could not create watch service", BubbleNotificationEvent.COMMONCOLOR_RED));

View File

@ -27,32 +27,23 @@ import net.lingala.zip4j.core.ZipFile;
import net.lingala.zip4j.exception.ZipException; import net.lingala.zip4j.exception.ZipException;
import org.newdawn.slick.util.Log; import org.newdawn.slick.util.Log;
import yugecin.opsudance.core.events.EventBus; import yugecin.opsudance.core.events.EventBus;
import yugecin.opsudance.core.inject.Inject;
import yugecin.opsudance.events.BubbleNotificationEvent; import yugecin.opsudance.events.BubbleNotificationEvent;
import yugecin.opsudance.options.Configuration;
import static yugecin.opsudance.core.InstanceContainer.*;
/** /**
* Unpacker for OSZ (ZIP) archives. * Unpacker for OSZ (ZIP) archives.
*/ */
public class OszUnpacker { public class OszUnpacker {
@Inject
private Configuration config;
/** The index of the current file being unpacked. */ /** The index of the current file being unpacked. */
private int fileIndex = -1; private int fileIndex = -1;
/** The total number of files to unpack. */ /** The total number of files to unpack. */
private File[] files; private File[] files;
@Inject
public OszUnpacker() {
}
/** /**
* Invokes the unpacker for each OSZ archive in a root directory. * Invokes the unpacker for each OSZ archive in a root directory.
* @param root the root directory
* @param dest the destination directory
* @return an array containing the new (unpacked) directories, or null * @return an array containing the new (unpacked) directories, or null
* if no OSZs found * if no OSZs found
*/ */

View File

@ -34,11 +34,10 @@ import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics; import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image; import org.newdawn.slick.Image;
import yugecin.opsudance.core.events.EventBus; import yugecin.opsudance.core.events.EventBus;
import yugecin.opsudance.core.inject.Inject;
import yugecin.opsudance.events.BarNotificationEvent; import yugecin.opsudance.events.BarNotificationEvent;
import yugecin.opsudance.events.BubbleNotificationEvent; import yugecin.opsudance.events.BubbleNotificationEvent;
import yugecin.opsudance.options.Configuration;
import static yugecin.opsudance.core.InstanceContainer.*;
import static yugecin.opsudance.options.Options.*; import static yugecin.opsudance.options.Options.*;
/** /**
@ -46,9 +45,6 @@ import static yugecin.opsudance.options.Options.*;
*/ */
public class DownloadNode { public class DownloadNode {
@Inject
private Configuration config;
/** The associated Download object. */ /** The associated Download object. */
private Download download; private Download download;

View File

@ -35,26 +35,18 @@ import java.util.Properties;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.newdawn.slick.util.Log; import org.newdawn.slick.util.Log;
import org.newdawn.slick.util.ResourceLoader; import org.newdawn.slick.util.ResourceLoader;
import yugecin.opsudance.core.Constants;
import yugecin.opsudance.core.errorhandling.ErrorHandler; import yugecin.opsudance.core.errorhandling.ErrorHandler;
import yugecin.opsudance.core.events.EventBus; import yugecin.opsudance.core.events.EventBus;
import yugecin.opsudance.core.inject.Inject;
import yugecin.opsudance.events.BarNotificationEvent; import yugecin.opsudance.events.BarNotificationEvent;
import yugecin.opsudance.options.Configuration;
import static yugecin.opsudance.core.InstanceContainer.*;
/** /**
* Handles automatic program updates. * Handles automatic program updates.
*/ */
public class Updater { public class Updater {
@Inject
private Configuration config;
private static Updater updater;
public static Updater get() {
return updater;
}
/** The exit confirmation message. */ /** The exit confirmation message. */
public static final String EXIT_CONFIRMATION = "An opsu! update is being downloaded.\nAre you sure you want to quit opsu!?"; public static final String EXIT_CONFIRMATION = "An opsu! update is being downloaded.\nAre you sure you want to quit opsu!?";
@ -95,7 +87,7 @@ public class Updater {
* Returns the status description. * Returns the status description.
*/ */
public String getDescription() { return description; } public String getDescription() { return description; }
}; }
/** The current updater status. */ /** The current updater status. */
private Status status; private Status status;
@ -119,10 +111,8 @@ public class Updater {
return currentVersion.getMajorVersion() + "." + currentVersion.getMinorVersion() + "." + currentVersion.getIncrementalVersion(); return currentVersion.getMajorVersion() + "." + currentVersion.getMinorVersion() + "." + currentVersion.getIncrementalVersion();
} }
@Inject
public Updater() { public Updater() {
status = Status.INITIAL; status = Status.INITIAL;
updater = this;
} }
/** /**
@ -145,7 +135,7 @@ public class Updater {
Date date = null; Date date = null;
try { try {
Properties props = new Properties(); Properties props = new Properties();
props.load(ResourceLoader.getResourceAsStream(config.VERSION_FILE)); props.load(ResourceLoader.getResourceAsStream(Constants.VERSION_FILE));
String build = props.getProperty("build.date"); String build = props.getProperty("build.date");
if (build == null || build.equals("${timestamp}") || build.equals("${maven.build.timestamp}")) if (build == null || build.equals("${timestamp}") || build.equals("${maven.build.timestamp}"))
date = new Date(); date = new Date();
@ -214,16 +204,16 @@ public class Updater {
// get current version // get current version
Properties props = new Properties(); Properties props = new Properties();
props.load(ResourceLoader.getResourceAsStream(config.VERSION_FILE)); props.load(ResourceLoader.getResourceAsStream(Constants.VERSION_FILE));
if ((currentVersion = getVersion(props)) == null) if ((currentVersion = getVersion(props)) == null)
return; return;
// get latest version // get latest version
String s = null; String s = null;
try { try {
s = Utils.readDataFromUrl(new URL(config.VERSION_REMOTE)); s = Utils.readDataFromUrl(new URL(Constants.VERSION_REMOTE));
} catch (UnknownHostException e) { } catch (UnknownHostException e) {
Log.warn(String.format("Check for updates failed. Please check your internet connection, or your connection to %s.", config.VERSION_REMOTE)); Log.warn(String.format("Check for updates failed. Please check your internet connection, or your connection to %s.", Constants.VERSION_REMOTE));
} }
if (s == null) { if (s == null) {
status = Status.CONNECTION_ERROR; status = Status.CONNECTION_ERROR;

View File

@ -34,17 +34,12 @@ import java.util.Date;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import yugecin.opsudance.core.errorhandling.ErrorHandler; import yugecin.opsudance.core.errorhandling.ErrorHandler;
import yugecin.opsudance.core.inject.Inject;
import yugecin.opsudance.core.inject.InstanceContainer;
/** /**
* Download server: http://bloodcat.com/osu/ * Download server: http://bloodcat.com/osu/
*/ */
public class BloodcatServer extends DownloadServer { public class BloodcatServer extends DownloadServer {
@Inject
public InstanceContainer instanceContainer;
/** Server name. */ /** Server name. */
private static final String SERVER_NAME = "Bloodcat"; private static final String SERVER_NAME = "Bloodcat";
@ -60,10 +55,6 @@ public class BloodcatServer extends DownloadServer {
/** Total result count from the last query. */ /** Total result count from the last query. */
private int totalResults = -1; private int totalResults = -1;
@Inject
public BloodcatServer() {
}
@Override @Override
public String getName() { return SERVER_NAME; } public String getName() { return SERVER_NAME; }
@ -89,12 +80,12 @@ public class BloodcatServer extends DownloadServer {
nodes = new DownloadNode[arr.length()]; nodes = new DownloadNode[arr.length()];
for (int i = 0; i < nodes.length; i++) { for (int i = 0; i < nodes.length; i++) {
JSONObject item = arr.getJSONObject(i); JSONObject item = arr.getJSONObject(i);
nodes[i] = instanceContainer.injectFields(new DownloadNode( nodes[i] = new DownloadNode(
item.getInt("id"), formatDate(item.getString("synced")), //"date" item.getInt("id"), formatDate(item.getString("synced")), //"date"
item.getString("title"), item.isNull("titleU") ? null : item.getString("titleU"), //"titleUnicode" item.getString("title"), item.isNull("titleU") ? null : item.getString("titleU"), //"titleUnicode"
item.getString("artist"), item.isNull("artistU") ? null : item.getString("artistU"), //"artistUnicode" item.getString("artist"), item.isNull("artistU") ? null : item.getString("artistU"), //"artistUnicode"
item.getString("creator") item.getString("creator")
)); );
} }
// store total result count // store total result count

View File

@ -30,8 +30,6 @@ import java.net.URLEncoder;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import yugecin.opsudance.core.errorhandling.ErrorHandler; import yugecin.opsudance.core.errorhandling.ErrorHandler;
import yugecin.opsudance.core.inject.Inject;
import yugecin.opsudance.core.inject.InstanceContainer;
/** /**
* Download server: https://osu.hexide.com/ * Download server: https://osu.hexide.com/
@ -40,9 +38,6 @@ import yugecin.opsudance.core.inject.InstanceContainer;
*/ */
public class HexideServer extends DownloadServer { public class HexideServer extends DownloadServer {
@Inject
private InstanceContainer instanceContainer;
/** Server name. */ /** Server name. */
private static final String SERVER_NAME = "Hexide"; private static final String SERVER_NAME = "Hexide";
@ -64,10 +59,6 @@ public class HexideServer extends DownloadServer {
/** Total result count from the last query. */ /** Total result count from the last query. */
private int totalResults = -1; private int totalResults = -1;
@Inject
public HexideServer() {
}
@Override @Override
public String getName() { return SERVER_NAME; } public String getName() { return SERVER_NAME; }
@ -124,10 +115,10 @@ public class HexideServer extends DownloadServer {
artist = creator = "?"; artist = creator = "?";
} }
} }
nodes[i] = instanceContainer.injectFields(new DownloadNode( nodes[i] = new DownloadNode(
item.getInt("ranked_id"), item.getString("date"), item.getInt("ranked_id"), item.getString("date"),
title, null, artist, null, creator title, null, artist, null, creator
)); );
} }
// store total result count // store total result count

View File

@ -30,17 +30,12 @@ import java.net.URLEncoder;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import yugecin.opsudance.core.errorhandling.ErrorHandler; import yugecin.opsudance.core.errorhandling.ErrorHandler;
import yugecin.opsudance.core.inject.Inject;
import yugecin.opsudance.core.inject.InstanceContainer;
/** /**
* Download server: http://osu.mengsky.net/ * Download server: http://osu.mengsky.net/
*/ */
public class MengSkyServer extends DownloadServer { public class MengSkyServer extends DownloadServer {
@Inject
private InstanceContainer instanceContainer;
/** Server name. */ /** Server name. */
private static final String SERVER_NAME = "MengSky"; private static final String SERVER_NAME = "MengSky";
@ -56,10 +51,6 @@ public class MengSkyServer extends DownloadServer {
/** Total result count from the last query. */ /** Total result count from the last query. */
private int totalResults = -1; private int totalResults = -1;
@Inject
public MengSkyServer() {
}
@Override @Override
public String getName() { return SERVER_NAME; } public String getName() { return SERVER_NAME; }
@ -93,10 +84,10 @@ public class MengSkyServer extends DownloadServer {
// sometimes titleU is artistU instead of the proper title // sometimes titleU is artistU instead of the proper title
if (titleU.equals(artistU) && !titleU.equals(title)) if (titleU.equals(artistU) && !titleU.equals(title))
titleU = title; titleU = title;
nodes[i] = instanceContainer.injectFields(new DownloadNode( nodes[i] = new DownloadNode(
item.getInt("id"), item.getString("syncedDateTime"), item.getInt("id"), item.getString("syncedDateTime"),
title, titleU, artist, artistU, creator title, titleU, artist, artistU, creator
)); );
} }
// store total result count // store total result count

View File

@ -21,8 +21,6 @@ package itdelatrisu.opsu.downloads.servers;
import itdelatrisu.opsu.Utils; import itdelatrisu.opsu.Utils;
import itdelatrisu.opsu.downloads.DownloadNode; import itdelatrisu.opsu.downloads.DownloadNode;
import yugecin.opsudance.core.errorhandling.ErrorHandler; import yugecin.opsudance.core.errorhandling.ErrorHandler;
import yugecin.opsudance.core.inject.Inject;
import yugecin.opsudance.core.inject.InstanceContainer;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
@ -39,9 +37,6 @@ import java.util.regex.Pattern;
*/ */
public class MnetworkServer extends DownloadServer { public class MnetworkServer extends DownloadServer {
@Inject
private InstanceContainer instanceContainer;
/** Server name. */ /** Server name. */
private static final String SERVER_NAME = "Mnetwork"; private static final String SERVER_NAME = "Mnetwork";
@ -57,10 +52,6 @@ public class MnetworkServer extends DownloadServer {
/** Beatmap pattern. */ /** Beatmap pattern. */
private Pattern BEATMAP_PATTERN = Pattern.compile("^(\\d+) ([^-]+) - (.+)\\.osz$"); private Pattern BEATMAP_PATTERN = Pattern.compile("^(\\d+) ([^-]+) - (.+)\\.osz$");
@Inject
public MnetworkServer() {
}
@Override @Override
public String getName() { return SERVER_NAME; } public String getName() { return SERVER_NAME; }
@ -119,7 +110,7 @@ public class MnetworkServer extends DownloadServer {
if (!m.matches()) if (!m.matches())
continue; continue;
nodeList.add(instanceContainer.injectFields(new DownloadNode(Integer.parseInt(m.group(1)), date, m.group(3), null, m.group(2), null, ""))); nodeList.add(new DownloadNode(Integer.parseInt(m.group(1)), date, m.group(3), null, m.group(2), null, ""));
} }
nodes = nodeList.toArray(new DownloadNode[nodeList.size()]); nodes = nodeList.toArray(new DownloadNode[nodeList.size()]);

View File

@ -36,8 +36,6 @@ import java.util.TimeZone;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import yugecin.opsudance.core.errorhandling.ErrorHandler; import yugecin.opsudance.core.errorhandling.ErrorHandler;
import yugecin.opsudance.core.inject.Inject;
import yugecin.opsudance.core.inject.InstanceContainer;
/** /**
* Download server: http://loli.al/ * Download server: http://loli.al/
@ -46,9 +44,6 @@ import yugecin.opsudance.core.inject.InstanceContainer;
*/ */
public class OsuMirrorServer extends DownloadServer { public class OsuMirrorServer extends DownloadServer {
@Inject
private InstanceContainer instanceContainer;
/** Server name. */ /** Server name. */
private static final String SERVER_NAME = "osu!Mirror"; private static final String SERVER_NAME = "osu!Mirror";
@ -73,10 +68,6 @@ public class OsuMirrorServer extends DownloadServer {
/** Lookup table from beatmap set ID -> server download ID. */ /** Lookup table from beatmap set ID -> server download ID. */
private HashMap<Integer, Integer> idTable = new HashMap<Integer, Integer>(); private HashMap<Integer, Integer> idTable = new HashMap<Integer, Integer>();
@Inject
public OsuMirrorServer() {
}
@Override @Override
public String getName() { return SERVER_NAME; } public String getName() { return SERVER_NAME; }
@ -113,12 +104,12 @@ public class OsuMirrorServer extends DownloadServer {
JSONObject item = arr.getJSONObject(i); JSONObject item = arr.getJSONObject(i);
int beatmapSetID = item.getInt("OSUSetid"); int beatmapSetID = item.getInt("OSUSetid");
int serverID = item.getInt("id"); int serverID = item.getInt("id");
nodes[i] = instanceContainer.injectFields(new DownloadNode( nodes[i] = new DownloadNode(
beatmapSetID, formatDate(item.getString("ModifyDate")), beatmapSetID, formatDate(item.getString("ModifyDate")),
item.getString("Title"), null, item.getString("Title"), null,
item.getString("Artist"), null, item.getString("Artist"), null,
item.getString("Mapper") item.getString("Mapper")
)); );
idTable.put(beatmapSetID, serverID); idTable.put(beatmapSetID, serverID);
if (serverID > maxServerID) if (serverID > maxServerID)
maxServerID = serverID; maxServerID = serverID;

View File

@ -34,17 +34,12 @@ import java.util.List;
import org.json.JSONObject; import org.json.JSONObject;
import yugecin.opsudance.core.errorhandling.ErrorHandler; import yugecin.opsudance.core.errorhandling.ErrorHandler;
import yugecin.opsudance.core.inject.Inject;
import yugecin.opsudance.core.inject.InstanceContainer;
/** /**
* Download server: http://osu.yas-online.net/ * Download server: http://osu.yas-online.net/
*/ */
public class YaSOnlineServer extends DownloadServer { public class YaSOnlineServer extends DownloadServer {
@Inject
public InstanceContainer instanceContainer;
/** Server name. */ /** Server name. */
private static final String SERVER_NAME = "YaS Online"; private static final String SERVER_NAME = "YaS Online";
@ -72,10 +67,6 @@ public class YaSOnlineServer extends DownloadServer {
/** Max server download ID seen (for approximating total pages). */ /** Max server download ID seen (for approximating total pages). */
private int maxServerID = 0; private int maxServerID = 0;
@Inject
public YaSOnlineServer() {
}
@Override @Override
public String getName() { return SERVER_NAME; } public String getName() { return SERVER_NAME; }
@ -183,7 +174,7 @@ public class YaSOnlineServer extends DownloadServer {
if (serverID > maxServerID) if (serverID > maxServerID)
maxServerID = serverID; maxServerID = serverID;
nodeList.add(instanceContainer.injectFields(new DownloadNode(item.getInt("mapid"), date, title, null, artist, null, ""))); nodeList.add(new DownloadNode(item.getInt("mapid"), date, title, null, artist, null, ""));
} }
nodes = nodeList.toArray(new DownloadNode[nodeList.size()]); nodes = nodeList.toArray(new DownloadNode[nodeList.size()]);

View File

@ -30,9 +30,8 @@ import itdelatrisu.opsu.ui.Colors;
import org.newdawn.slick.Color; import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics; import org.newdawn.slick.Graphics;
import yugecin.opsudance.Dancer; import yugecin.opsudance.Dancer;
import yugecin.opsudance.core.inject.Inject;
import yugecin.opsudance.render.GameObjectRenderer;
import static yugecin.opsudance.core.InstanceContainer.*;
import static yugecin.opsudance.options.Options.*; import static yugecin.opsudance.options.Options.*;
/** /**
@ -40,9 +39,6 @@ import static yugecin.opsudance.options.Options.*;
*/ */
public class Circle extends GameObject { public class Circle extends GameObject {
@Inject
private GameObjectRenderer gameObjectRenderer;
/** The associated HitObject. */ /** The associated HitObject. */
private HitObject hitObject; private HitObject hitObject;
@ -156,7 +152,7 @@ public class Circle extends GameObject {
@Override @Override
public boolean mousePressed(int x, int y, int trackPosition) { public boolean mousePressed(int x, int y, int trackPosition) {
double distance = Math.hypot(this.x - x, this.y - y); double distance = Math.hypot(this.x - x, this.y - y);
if (distance < gameObjectRenderer.getCircleDiameter() / 2) { if (distance < gameObjectRenderer.circleDiameter / 2) {
int timeDiff = trackPosition - hitObject.getTime(); int timeDiff = trackPosition - hitObject.getTime();
int result = hitResult(timeDiff); int result = hitResult(timeDiff);

View File

@ -35,11 +35,9 @@ import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics; import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image; import org.newdawn.slick.Image;
import yugecin.opsudance.Dancer; import yugecin.opsudance.Dancer;
import yugecin.opsudance.core.DisplayContainer;
import yugecin.opsudance.core.inject.Inject;
import yugecin.opsudance.render.GameObjectRenderer;
import yugecin.opsudance.skinning.SkinService; import yugecin.opsudance.skinning.SkinService;
import static yugecin.opsudance.core.InstanceContainer.*;
import static yugecin.opsudance.options.Options.*; import static yugecin.opsudance.options.Options.*;
/** /**
@ -47,12 +45,6 @@ import static yugecin.opsudance.options.Options.*;
*/ */
public class Slider extends GameObject { public class Slider extends GameObject {
@Inject
private DisplayContainer displayContainer;
@Inject
private GameObjectRenderer gameObjectRenderer;
/** Slider ball frames. */ /** Slider ball frames. */
private static Image[] sliderBallImages; private static Image[] sliderBallImages;
@ -605,7 +597,7 @@ public class Slider extends GameObject {
return false; return false;
double distance = Math.hypot(this.x - x, this.y - y); double distance = Math.hypot(this.x - x, this.y - y);
if (distance < gameObjectRenderer.getCircleDiameter() / 2) { if (distance < gameObjectRenderer.circleDiameter / 2) {
int timeDiff = Math.abs(trackPosition - hitObject.getTime()); int timeDiff = Math.abs(trackPosition - hitObject.getTime());
int[] hitResultOffset = game.getHitResultOffsets(); int[] hitResultOffset = game.getHitResultOffsets();

View File

@ -37,8 +37,8 @@ import org.lwjgl.opengl.GL20;
import org.newdawn.slick.Color; import org.newdawn.slick.Color;
import org.newdawn.slick.Image; import org.newdawn.slick.Image;
import org.newdawn.slick.util.Log; import org.newdawn.slick.util.Log;
import yugecin.opsudance.render.GameObjectRenderer;
import static yugecin.opsudance.core.InstanceContainer.*;
import static yugecin.opsudance.options.Options.*; import static yugecin.opsudance.options.Options.*;
/** /**
@ -316,7 +316,7 @@ public class CurveRenderState {
double diff_x = x - last_x; double diff_x = x - last_x;
double diff_y = y - last_y; double diff_y = y - last_y;
float dist = Utils.distance(x, y, last_x, last_y); float dist = Utils.distance(x, y, last_x, last_y);
if (dist < GameObjectRenderer.instance.getCircleDiameter() / 8) { if (dist < gameObjectRenderer.circleDiameter / 8) {
x = (float) (x - diff_x / 2); x = (float) (x - diff_x / 2);
y = (float) (y - diff_y / 2); y = (float) (y - diff_y / 2);
} else { } else {

View File

@ -45,9 +45,9 @@ import org.newdawn.slick.util.Log;
import lzma.streams.LzmaOutputStream; import lzma.streams.LzmaOutputStream;
import yugecin.opsudance.core.errorhandling.ErrorHandler; import yugecin.opsudance.core.errorhandling.ErrorHandler;
import yugecin.opsudance.core.events.EventBus; import yugecin.opsudance.core.events.EventBus;
import yugecin.opsudance.core.inject.Inject;
import yugecin.opsudance.events.BubbleNotificationEvent; import yugecin.opsudance.events.BubbleNotificationEvent;
import yugecin.opsudance.options.Configuration;
import static yugecin.opsudance.core.InstanceContainer.*;
/** /**
* Captures osu! replay data. * Captures osu! replay data.
@ -57,9 +57,6 @@ import yugecin.opsudance.options.Configuration;
*/ */
public class Replay { public class Replay {
@Inject
public Configuration config;
/** The associated file. */ /** The associated file. */
private File file; private File file;

View File

@ -30,22 +30,15 @@ import java.nio.file.StandardCopyOption;
import org.newdawn.slick.util.Log; import org.newdawn.slick.util.Log;
import yugecin.opsudance.core.events.EventBus; import yugecin.opsudance.core.events.EventBus;
import yugecin.opsudance.core.inject.Inject;
import yugecin.opsudance.core.inject.InstanceContainer;
import yugecin.opsudance.events.BubbleNotificationEvent; import yugecin.opsudance.events.BubbleNotificationEvent;
import yugecin.opsudance.options.Configuration;
import static yugecin.opsudance.core.InstanceContainer.*;
/** /**
* Importer for replay files. * Importer for replay files.
*/ */
public class ReplayImporter { public class ReplayImporter {
@Inject
private InstanceContainer instanceContainer;
@Inject
private Configuration config;
/** The subdirectory (within the replay import directory) to move replays that could not be imported. */ /** The subdirectory (within the replay import directory) to move replays that could not be imported. */
private final String FAILED_IMPORT_DIR = "failed"; private final String FAILED_IMPORT_DIR = "failed";
@ -55,10 +48,6 @@ public class ReplayImporter {
/** The total number of replays to import. */ /** The total number of replays to import. */
private File[] files; private File[] files;
@Inject
public ReplayImporter() {
}
/** /**
* Invokes the importer for each OSR file in the replay import dir, adding the replay * Invokes the importer for each OSR file in the replay import dir, adding the replay
* to the score database and moving the file into the replay directory. * to the score database and moving the file into the replay directory.
@ -87,7 +76,7 @@ public class ReplayImporter {
// import OSRs // import OSRs
for (File file : files) { for (File file : files) {
fileIndex++; fileIndex++;
Replay r = instanceContainer.injectFields(new Replay(file)); Replay r = new Replay(file);
try { try {
r.loadHeader(); r.loadHeader();
} catch (IOException e) { } catch (IOException e) {

View File

@ -39,10 +39,10 @@ import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics; import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image; import org.newdawn.slick.Image;
import org.newdawn.slick.Input; import org.newdawn.slick.Input;
import yugecin.opsudance.core.DisplayContainer;
import yugecin.opsudance.core.inject.InstanceContainer;
import yugecin.opsudance.core.state.BaseOpsuState; import yugecin.opsudance.core.state.BaseOpsuState;
import static yugecin.opsudance.core.InstanceContainer.*;
/** /**
* Generic button menu state. * Generic button menu state.
* <p> * <p>
@ -68,7 +68,7 @@ public class ButtonMenu extends BaseOpsuState {
BEATMAP (new Button[] { Button.CLEAR_SCORES, Button.FAVORITE_ADD, Button.DELETE, Button.CANCEL }) { BEATMAP (new Button[] { Button.CLEAR_SCORES, Button.FAVORITE_ADD, Button.DELETE, Button.CANCEL }) {
@Override @Override
public String[] getTitle() { public String[] getTitle() {
BeatmapSetNode node = instanceContainer.provide(ButtonMenu.class).getNode(); BeatmapSetNode node = buttonState.getNode();
String beatmapString = (node != null) ? BeatmapSetList.get().getBaseNode(node.index).toString() : ""; String beatmapString = (node != null) ? BeatmapSetList.get().getBaseNode(node.index).toString() : "";
return new String[] { beatmapString, "What do you want to do with this beatmap?" }; return new String[] { beatmapString, "What do you want to do with this beatmap?" };
} }
@ -99,7 +99,7 @@ public class ButtonMenu extends BaseOpsuState {
BEATMAP_DELETE_SELECT (new Button[] { Button.DELETE_GROUP, Button.DELETE_SONG, Button.CANCEL_DELETE }) { BEATMAP_DELETE_SELECT (new Button[] { Button.DELETE_GROUP, Button.DELETE_SONG, Button.CANCEL_DELETE }) {
@Override @Override
public String[] getTitle() { public String[] getTitle() {
BeatmapSetNode node = instanceContainer.provide(ButtonMenu.class).getNode(); BeatmapSetNode node = buttonState.getNode();
String beatmapString = (node != null) ? node.toString() : ""; String beatmapString = (node != null) ? node.toString() : "";
return new String[] { String.format("Are you sure you wish to delete '%s' from disk?", beatmapString) }; return new String[] { String.format("Are you sure you wish to delete '%s' from disk?", beatmapString) };
} }
@ -179,7 +179,7 @@ public class ButtonMenu extends BaseOpsuState {
} }
@Override @Override
protected float getBaseY(DisplayContainer displayContainer) { protected float getBaseY() {
return displayContainer.height * 2f / 3; return displayContainer.height * 2f / 3;
} }
@ -268,9 +268,6 @@ public class ButtonMenu extends BaseOpsuState {
} }
}; };
public static DisplayContainer displayContainer;
public static InstanceContainer instanceContainer;
/** The buttons in the state. */ /** The buttons in the state. */
private final Button[] buttons; private final Button[] buttons;
@ -299,7 +296,7 @@ public class ButtonMenu extends BaseOpsuState {
*/ */
public void revalidate(Image button, Image buttonL, Image buttonR) { public void revalidate(Image button, Image buttonL, Image buttonR) {
float center = displayContainer.width / 2; float center = displayContainer.width / 2;
float baseY = getBaseY(displayContainer); float baseY = getBaseY();
float offsetY = button.getHeight() * 1.25f; float offsetY = button.getHeight() * 1.25f;
menuButtons = new MenuButton[buttons.length]; menuButtons = new MenuButton[buttons.length];
@ -314,7 +311,7 @@ public class ButtonMenu extends BaseOpsuState {
/** /**
* Returns the base Y coordinate for the buttons. * Returns the base Y coordinate for the buttons.
*/ */
protected float getBaseY(DisplayContainer displayContainer) { protected float getBaseY() {
float baseY = displayContainer.height * 0.2f; float baseY = displayContainer.height * 0.2f;
baseY += ((getTitle().length - 1) * Fonts.LARGE.getLineHeight()); baseY += ((getTitle().length - 1) * Fonts.LARGE.getLineHeight());
return baseY; return baseY;
@ -437,62 +434,62 @@ public class ButtonMenu extends BaseOpsuState {
@Override @Override
public void click() { public void click() {
SoundController.playSound(SoundEffect.MENUBACK); SoundController.playSound(SoundEffect.MENUBACK);
displayContainer.switchState(MainMenu.class); displayContainer.switchState(mainmenuState);
} }
}, },
CLEAR_SCORES ("Clear local scores", Color.magenta) { CLEAR_SCORES ("Clear local scores", Color.magenta) {
@Override @Override
public void click() { public void click() {
SoundController.playSound(SoundEffect.MENUHIT); SoundController.playSound(SoundEffect.MENUHIT);
BeatmapSetNode node = instanceContainer.provide(ButtonMenu.class).getNode(); BeatmapSetNode node = buttonState.getNode();
instanceContainer.provide(SongMenu.class).doStateActionOnLoad(MenuState.BEATMAP, node); songMenuState.doStateActionOnLoad(MenuState.BEATMAP, node);
displayContainer.switchState(SongMenu.class); displayContainer.switchState(songMenuState);
} }
}, },
FAVORITE_ADD ("Add to Favorites", Color.blue) { FAVORITE_ADD ("Add to Favorites", Color.blue) {
@Override @Override
public void click() { public void click() {
SoundController.playSound(SoundEffect.MENUHIT); SoundController.playSound(SoundEffect.MENUHIT);
BeatmapSetNode node = instanceContainer.provide(ButtonMenu.class).getNode(); BeatmapSetNode node = buttonState.getNode();
node.getBeatmapSet().setFavorite(true); node.getBeatmapSet().setFavorite(true);
displayContainer.switchState(SongMenu.class); displayContainer.switchState(songMenuState);
} }
}, },
FAVORITE_REMOVE ("Remove from Favorites", Color.blue) { FAVORITE_REMOVE ("Remove from Favorites", Color.blue) {
@Override @Override
public void click() { public void click() {
SoundController.playSound(SoundEffect.MENUHIT); SoundController.playSound(SoundEffect.MENUHIT);
BeatmapSetNode node = instanceContainer.provide(ButtonMenu.class).getNode(); BeatmapSetNode node = buttonState.getNode();
node.getBeatmapSet().setFavorite(false); node.getBeatmapSet().setFavorite(false);
instanceContainer.provide(SongMenu.class).doStateActionOnLoad(MenuState.BEATMAP_FAVORITE); songMenuState.doStateActionOnLoad(MenuState.BEATMAP_FAVORITE);
displayContainer.switchState(SongMenu.class); displayContainer.switchState(songMenuState);
} }
}, },
DELETE ("Delete...", Color.red) { DELETE ("Delete...", Color.red) {
@Override @Override
public void click() { public void click() {
SoundController.playSound(SoundEffect.MENUHIT); SoundController.playSound(SoundEffect.MENUHIT);
BeatmapSetNode node = instanceContainer.provide(ButtonMenu.class).getNode(); BeatmapSetNode node = buttonState.getNode();
MenuState ms = (node.beatmapIndex == -1 || node.getBeatmapSet().size() == 1) ? MenuState ms = (node.beatmapIndex == -1 || node.getBeatmapSet().size() == 1) ?
MenuState.BEATMAP_DELETE_CONFIRM : MenuState.BEATMAP_DELETE_SELECT; MenuState.BEATMAP_DELETE_CONFIRM : MenuState.BEATMAP_DELETE_SELECT;
instanceContainer.provide(ButtonMenu.class).setMenuState(ms, node); buttonState.setMenuState(ms, node);
displayContainer.switchState(ButtonMenu.class); displayContainer.switchState(buttonState);
} }
}, },
CANCEL ("Cancel", Color.gray) { CANCEL ("Cancel", Color.gray) {
@Override @Override
public void click() { public void click() {
SoundController.playSound(SoundEffect.MENUBACK); SoundController.playSound(SoundEffect.MENUBACK);
displayContainer.switchState(SongMenu.class); displayContainer.switchState(songMenuState);
} }
}, },
DELETE_CONFIRM ("Yes, delete this beatmap!", Color.red) { DELETE_CONFIRM ("Yes, delete this beatmap!", Color.red) {
@Override @Override
public void click() { public void click() {
SoundController.playSound(SoundEffect.MENUHIT); SoundController.playSound(SoundEffect.MENUHIT);
BeatmapSetNode node = instanceContainer.provide(ButtonMenu.class).getNode(); BeatmapSetNode node = buttonState.getNode();
instanceContainer.provide(SongMenu.class).doStateActionOnLoad(MenuState.BEATMAP_DELETE_CONFIRM, node); songMenuState.doStateActionOnLoad(MenuState.BEATMAP_DELETE_CONFIRM, node);
displayContainer.switchState(SongMenu.class); displayContainer.switchState(songMenuState);
} }
}, },
DELETE_GROUP ("Yes, delete all difficulties!", Color.red) { DELETE_GROUP ("Yes, delete all difficulties!", Color.red) {
@ -505,9 +502,9 @@ public class ButtonMenu extends BaseOpsuState {
@Override @Override
public void click() { public void click() {
SoundController.playSound(SoundEffect.MENUHIT); SoundController.playSound(SoundEffect.MENUHIT);
BeatmapSetNode node = instanceContainer.provide(ButtonMenu.class).getNode(); BeatmapSetNode node = buttonState.getNode();
instanceContainer.provide(SongMenu.class).doStateActionOnLoad(MenuState.BEATMAP_DELETE_SELECT, node); songMenuState.doStateActionOnLoad(MenuState.BEATMAP_DELETE_SELECT, node);
displayContainer.switchState(SongMenu.class); displayContainer.switchState(songMenuState);
} }
}, },
CANCEL_DELETE ("Nooooo! I didn't mean to!", Color.gray) { CANCEL_DELETE ("Nooooo! I didn't mean to!", Color.gray) {
@ -520,8 +517,8 @@ public class ButtonMenu extends BaseOpsuState {
@Override @Override
public void click() { public void click() {
SoundController.playSound(SoundEffect.MENUHIT); SoundController.playSound(SoundEffect.MENUHIT);
instanceContainer.provide(SongMenu.class).doStateActionOnLoad(MenuState.RELOAD); songMenuState.doStateActionOnLoad(MenuState.RELOAD);
displayContainer.switchState(SongMenu.class); displayContainer.switchState(songMenuState);
} }
}, },
RELOAD_CANCEL ("Cancel", Color.red) { RELOAD_CANCEL ("Cancel", Color.red) {
@ -534,9 +531,9 @@ public class ButtonMenu extends BaseOpsuState {
@Override @Override
public void click() { public void click() {
SoundController.playSound(SoundEffect.MENUHIT); SoundController.playSound(SoundEffect.MENUHIT);
ScoreData scoreData = instanceContainer.provide(ButtonMenu.class).getScoreData(); ScoreData scoreData = buttonState.getScoreData();
instanceContainer.provide(SongMenu.class).doStateActionOnLoad(MenuState.SCORE, scoreData); songMenuState.doStateActionOnLoad(MenuState.SCORE, scoreData);
displayContainer.switchState(SongMenu.class); displayContainer.switchState(songMenuState);
} }
}, },
CLOSE ("Close", Color.gray) { CLOSE ("Close", Color.gray) {
@ -556,9 +553,6 @@ public class ButtonMenu extends BaseOpsuState {
} }
}; };
public static DisplayContainer displayContainer;
public static InstanceContainer instanceContainer;
/** The text to show on the button. */ /** The text to show on the button. */
private final String text; private final String text;
@ -600,12 +594,6 @@ public class ButtonMenu extends BaseOpsuState {
/** The score data to process in the state. */ /** The score data to process in the state. */
private ScoreData scoreData; private ScoreData scoreData;
public ButtonMenu(DisplayContainer displayContainer, InstanceContainer instanceContainer) {
super();
Button.displayContainer = MenuState.displayContainer = displayContainer;
Button.instanceContainer = MenuState.instanceContainer = instanceContainer;
}
@Override @Override
public void revalidate() { public void revalidate() {
super.revalidate(); super.revalidate();

View File

@ -22,10 +22,8 @@ import itdelatrisu.opsu.GameImage;
import itdelatrisu.opsu.audio.MusicController; import itdelatrisu.opsu.audio.MusicController;
import itdelatrisu.opsu.audio.SoundController; import itdelatrisu.opsu.audio.SoundController;
import itdelatrisu.opsu.audio.SoundEffect; import itdelatrisu.opsu.audio.SoundEffect;
import itdelatrisu.opsu.beatmap.BeatmapParser;
import itdelatrisu.opsu.beatmap.BeatmapSetList; import itdelatrisu.opsu.beatmap.BeatmapSetList;
import itdelatrisu.opsu.beatmap.BeatmapSetNode; import itdelatrisu.opsu.beatmap.BeatmapSetNode;
import itdelatrisu.opsu.beatmap.OszUnpacker;
import itdelatrisu.opsu.downloads.Download; import itdelatrisu.opsu.downloads.Download;
import itdelatrisu.opsu.downloads.DownloadList; import itdelatrisu.opsu.downloads.DownloadList;
import itdelatrisu.opsu.downloads.DownloadNode; import itdelatrisu.opsu.downloads.DownloadNode;
@ -55,11 +53,10 @@ import org.newdawn.slick.SlickException;
import org.newdawn.slick.gui.TextField; import org.newdawn.slick.gui.TextField;
import org.newdawn.slick.util.Log; import org.newdawn.slick.util.Log;
import yugecin.opsudance.core.events.EventBus; import yugecin.opsudance.core.events.EventBus;
import yugecin.opsudance.core.inject.Inject;
import yugecin.opsudance.core.inject.InstanceContainer;
import yugecin.opsudance.core.state.ComplexOpsuState; import yugecin.opsudance.core.state.ComplexOpsuState;
import yugecin.opsudance.events.BarNotificationEvent; import yugecin.opsudance.events.BarNotificationEvent;
import yugecin.opsudance.options.Configuration;
import static yugecin.opsudance.core.InstanceContainer.*;
/** /**
* Downloads menu. * Downloads menu.
@ -69,18 +66,6 @@ import yugecin.opsudance.options.Configuration;
*/ */
public class DownloadsMenu extends ComplexOpsuState { public class DownloadsMenu extends ComplexOpsuState {
@Inject
private InstanceContainer instanceContainer;
@Inject
private Configuration config;
@Inject
private OszUnpacker oszUnpacker;
@Inject
private BeatmapParser beatmapParser;
/** Delay time, in milliseconds, between each search. */ /** Delay time, in milliseconds, between each search. */
private static final int SEARCH_DELAY = 700; private static final int SEARCH_DELAY = 700;
@ -275,12 +260,12 @@ public class DownloadsMenu extends ComplexOpsuState {
} finally { } finally {
finished = true; finished = true;
} }
}; }
/** Imports all packed beatmaps. */ /** Imports all packed beatmaps. */
private void importBeatmaps() { private void importBeatmaps() {
// invoke unpacker and parser // invoke unpacker and parser
File[] dirs = oszUnpacker.unpackAll(); File[] dirs = oszunpacker.unpackAll();
if (dirs != null && dirs.length > 0) { if (dirs != null && dirs.length > 0) {
this.importedNode = beatmapParser.parseDirectories(dirs); this.importedNode = beatmapParser.parseDirectories(dirs);
if (importedNode != null) { if (importedNode != null) {
@ -294,13 +279,12 @@ public class DownloadsMenu extends ComplexOpsuState {
} }
} }
@Inject public DownloadsMenu() {
public DownloadsMenu(InstanceContainer instanceContainer) {
SERVERS = new DownloadServer[] { SERVERS = new DownloadServer[] {
instanceContainer.provide(BloodcatServer.class), new BloodcatServer(),
instanceContainer.provide(YaSOnlineServer.class), new YaSOnlineServer(),
instanceContainer.provide(MnetworkServer.class), new MnetworkServer(),
instanceContainer.provide(MengSkyServer.class), new MengSkyServer(),
}; };
} }
@ -555,7 +539,7 @@ public class DownloadsMenu extends ComplexOpsuState {
// focus new beatmap // focus new beatmap
// NOTE: This can't be called in another thread because it makes OpenGL calls. // NOTE: This can't be called in another thread because it makes OpenGL calls.
instanceContainer.provide(SongMenu.class).setFocus(importedNode, -1, true, true); songMenuState.setFocus(importedNode, -1, true, true);
} }
importThread = null; importThread = null;
} }
@ -633,7 +617,7 @@ public class DownloadsMenu extends ComplexOpsuState {
// back // back
if (UI.getBackButton().contains(x, y)) { if (UI.getBackButton().contains(x, y)) {
SoundController.playSound(SoundEffect.MENUBACK); SoundController.playSound(SoundEffect.MENUBACK);
displayContainer.switchState(MainMenu.class); displayContainer.switchState(mainmenuState);
return true; return true;
} }
@ -918,7 +902,7 @@ public class DownloadsMenu extends ComplexOpsuState {
} else { } else {
// return to main menu // return to main menu
SoundController.playSound(SoundEffect.MENUBACK); SoundController.playSound(SoundEffect.MENUBACK);
displayContainer.switchState(MainMenu.class); displayContainer.switchState(mainmenuState);
} }
return true; return true;
case Input.KEY_ENTER: case Input.KEY_ENTER:

View File

@ -57,17 +57,13 @@ import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException; import org.newdawn.slick.SlickException;
import org.newdawn.slick.util.Log; import org.newdawn.slick.util.Log;
import yugecin.opsudance.*; import yugecin.opsudance.*;
import yugecin.opsudance.core.DisplayContainer;
import yugecin.opsudance.core.events.EventBus; import yugecin.opsudance.core.events.EventBus;
import yugecin.opsudance.core.inject.Inject;
import yugecin.opsudance.core.inject.InstanceContainer;
import yugecin.opsudance.core.state.ComplexOpsuState; import yugecin.opsudance.core.state.ComplexOpsuState;
import yugecin.opsudance.events.BarNotificationEvent; import yugecin.opsudance.events.BarNotificationEvent;
import yugecin.opsudance.events.BubbleNotificationEvent; import yugecin.opsudance.events.BubbleNotificationEvent;
import yugecin.opsudance.objects.curves.FakeCombinedCurve; import yugecin.opsudance.objects.curves.FakeCombinedCurve;
import yugecin.opsudance.options.OptionGroups; import yugecin.opsudance.options.OptionGroups;
import yugecin.opsudance.options.Options; import yugecin.opsudance.options.Options;
import yugecin.opsudance.render.GameObjectRenderer;
import yugecin.opsudance.sbv2.MoveStoryboard; import yugecin.opsudance.sbv2.MoveStoryboard;
import yugecin.opsudance.skinning.SkinService; import yugecin.opsudance.skinning.SkinService;
import yugecin.opsudance.ui.OptionsOverlay; import yugecin.opsudance.ui.OptionsOverlay;
@ -75,21 +71,13 @@ import yugecin.opsudance.ui.StoryboardOverlay;
import yugecin.opsudance.utils.GLHelper; import yugecin.opsudance.utils.GLHelper;
import static yugecin.opsudance.options.Options.*; import static yugecin.opsudance.options.Options.*;
import static yugecin.opsudance.core.InstanceContainer.*;
/** /**
* "Game" state. * "Game" state.
*/ */
public class Game extends ComplexOpsuState { public class Game extends ComplexOpsuState {
@Inject
private InstanceContainer instanceContainer;
@Inject
private GameObjectRenderer gameObjectRenderer;
@Inject
private BeatmapParser beatmapParser;
public static boolean isInGame; // TODO delete this when #79 is fixed public static boolean isInGame; // TODO delete this when #79 is fixed
/** Game restart states. */ /** Game restart states. */
public enum Restart { public enum Restart {
@ -327,7 +315,7 @@ public class Game extends ComplexOpsuState {
private boolean skippedToCheckpoint; private boolean skippedToCheckpoint;
public Game(DisplayContainer displayContainer) { public Game() {
super(); super();
mirrorCursor = new Cursor(true); mirrorCursor = new Cursor(true);
this.moveStoryboardOverlay = new MoveStoryboard(displayContainer); this.moveStoryboardOverlay = new MoveStoryboard(displayContainer);
@ -365,8 +353,7 @@ public class Game extends ComplexOpsuState {
scoreboardStarStream.setDurationSpread(700, 100); scoreboardStarStream.setDurationSpread(700, 100);
// create the associated GameData object // create the associated GameData object
data = instanceContainer.injectFields(new GameData(displayContainer.width, displayContainer.height)); gameObjectRenderer.gameData = data = new GameData();
gameObjectRenderer.setGameData(data);
} }
@ -764,7 +751,7 @@ public class Game extends ComplexOpsuState {
// focus lost: go back to pause screen // focus lost: go back to pause screen
else if (!Display.isActive()) { else if (!Display.isActive()) {
displayContainer.switchState(GamePauseMenu.class); displayContainer.switchState(pauseState);
pausePulse = 0f; pausePulse = 0f;
} }
@ -881,7 +868,7 @@ public class Game extends ComplexOpsuState {
onCloseRequest(); onCloseRequest();
} else { } else {
// go to ranking screen // go to ranking screen
displayContainer.switchState(GameRanking.class); displayContainer.switchState(gameRankingState);
} }
} }
} }
@ -927,11 +914,11 @@ public class Game extends ComplexOpsuState {
} else if (GameMod.AUTO.isActive()) { } else if (GameMod.AUTO.isActive()) {
displayContainer.cursor.setCursorPosition(displayContainer.delta, (int) autoMousePosition.x, (int) autoMousePosition.y); displayContainer.cursor.setCursorPosition(displayContainer.delta, (int) autoMousePosition.x, (int) autoMousePosition.y);
if (OPTION_DANCE_MIRROR.state && GameMod.AUTO.isActive()) { if (OPTION_DANCE_MIRROR.state && GameMod.AUTO.isActive()) {
double dx = autoMousePosition.x - Options.width / 2d; double dx = autoMousePosition.x - displayContainer.width / 2d;
double dy = autoMousePosition.y - Options.height / 2d; double dy = autoMousePosition.y - displayContainer.height / 2d;
double d = Math.sqrt(dx * dx + dy * dy); double d = Math.sqrt(dx * dx + dy * dy);
double a = Math.atan2(dy, dx) + Math.PI; double a = Math.atan2(dy, dx) + Math.PI;
mirrorCursor.setCursorPosition(displayContainer.delta, (int) (Math.cos(a) * d + Options.width / 2), (int) (Math.sin(a) * d + Options.height / 2)); mirrorCursor.setCursorPosition(displayContainer.delta, (int) (Math.cos(a) * d + displayContainer.width / 2), (int) (Math.sin(a) * d + displayContainer.height / 2));
} }
} else if (GameMod.AUTOPILOT.isActive()) { } else if (GameMod.AUTOPILOT.isActive()) {
displayContainer.cursor.setCursorPosition(displayContainer.delta, (int) autoMousePosition.x, (int) autoMousePosition.y); displayContainer.cursor.setCursorPosition(displayContainer.delta, (int) autoMousePosition.x, (int) autoMousePosition.y);
@ -962,7 +949,7 @@ public class Game extends ComplexOpsuState {
// save score and replay // save score and replay
if (!checkpointLoaded) { if (!checkpointLoaded) {
boolean unranked = (GameMod.AUTO.isActive() || GameMod.RELAX.isActive() || GameMod.AUTOPILOT.isActive()); boolean unranked = (GameMod.AUTO.isActive() || GameMod.RELAX.isActive() || GameMod.AUTOPILOT.isActive());
instanceContainer.provide(GameRanking.class).setGameData(data); gameRankingState.setGameData(data);
if (isReplay) if (isReplay)
data.setReplay(replay); data.setReplay(replay);
else if (replayFrames != null) { else if (replayFrames != null) {
@ -1048,7 +1035,7 @@ public class Game extends ComplexOpsuState {
if (MusicController.isPlaying() || isLeadIn()) { if (MusicController.isPlaying() || isLeadIn()) {
pauseTime = trackPosition; pauseTime = trackPosition;
} }
displayContainer.switchStateInstantly(GamePauseMenu.class); displayContainer.switchStateInstantly(pauseState);
} }
// drain health // drain health
@ -1075,7 +1062,7 @@ public class Game extends ComplexOpsuState {
rotations = new IdentityHashMap<>(); rotations = new IdentityHashMap<>();
SoundController.playSound(SoundEffect.FAIL); SoundController.playSound(SoundEffect.FAIL);
displayContainer.switchState(GamePauseMenu.class, MUSIC_FADEOUT_TIME - LOSE_FADEOUT_TIME, 300); displayContainer.switchState(pauseState, MUSIC_FADEOUT_TIME - LOSE_FADEOUT_TIME, 300);
} }
} }
} }
@ -1108,8 +1095,8 @@ public class Game extends ComplexOpsuState {
@Override @Override
public boolean onCloseRequest() { public boolean onCloseRequest() {
instanceContainer.provide(SongMenu.class).resetGameDataOnLoad(); songMenuState.resetGameDataOnLoad();
displayContainer.switchState(SongMenu.class); displayContainer.switchState(songMenuState);
return false; return false;
} }
@ -1156,7 +1143,7 @@ public class Game extends ComplexOpsuState {
if (MusicController.isPlaying() || isLeadIn()) { if (MusicController.isPlaying() || isLeadIn()) {
pauseTime = trackPosition; pauseTime = trackPosition;
} }
displayContainer.switchStateInstantly(GamePauseMenu.class); displayContainer.switchStateInstantly(pauseState);
break; break;
case Input.KEY_SPACE: case Input.KEY_SPACE:
// skip intro // skip intro
@ -1309,7 +1296,7 @@ public class Game extends ComplexOpsuState {
if (MusicController.isPlaying() || isLeadIn()) { if (MusicController.isPlaying() || isLeadIn()) {
pauseTime = trackPosition; pauseTime = trackPosition;
} }
displayContainer.switchStateInstantly(GamePauseMenu.class); displayContainer.switchStateInstantly(pauseState);
return true; return true;
} }
@ -1468,7 +1455,7 @@ public class Game extends ComplexOpsuState {
if (beatmap == null || beatmap.objects == null) { if (beatmap == null || beatmap.objects == null) {
EventBus.post(new BubbleNotificationEvent("Game was running without a beatmap", BubbleNotificationEvent.COMMONCOLOR_RED)); EventBus.post(new BubbleNotificationEvent("Game was running without a beatmap", BubbleNotificationEvent.COMMONCOLOR_RED));
displayContainer.switchStateInstantly(SongMenu.class); displayContainer.switchStateInstantly(songMenuState);
} }
Dancer.instance.reset(); Dancer.instance.reset();
@ -1565,9 +1552,9 @@ public class Game extends ComplexOpsuState {
try { try {
if (hitObject.isCircle()) { if (hitObject.isCircle()) {
gameObjects[i] = instanceContainer.injectFields(new Circle(hitObject, this, data, hitObject.getComboIndex(), comboEnd)); gameObjects[i] = new Circle(hitObject, this, data, hitObject.getComboIndex(), comboEnd);
} else if (hitObject.isSlider()) { } else if (hitObject.isSlider()) {
gameObjects[i] = instanceContainer.injectFields(new Slider(hitObject, this, data, hitObject.getComboIndex(), comboEnd)); gameObjects[i] = new Slider(hitObject, this, data, hitObject.getComboIndex(), comboEnd);
} else if (hitObject.isSpinner()) { } else if (hitObject.isSpinner()) {
gameObjects[i] = new Spinner(hitObject, this, data); gameObjects[i] = new Spinner(hitObject, this, data);
} }
@ -1855,7 +1842,7 @@ public class Game extends ComplexOpsuState {
gameObj.draw(g, trackPosition, false); gameObj.draw(g, trackPosition, false);
if (OPTION_DANCE_MIRROR.state && GameMod.AUTO.isActive() && idx < mirrorTo && idx >= mirrorFrom) { if (OPTION_DANCE_MIRROR.state && GameMod.AUTO.isActive() && idx < mirrorTo && idx >= mirrorFrom) {
g.pushTransform(); g.pushTransform();
g.rotate(Options.width / 2f, Options.height / 2f, 180f); g.rotate(displayContainer.width / 2f, displayContainer.height / 2f, 180f);
gameObj.draw(g, trackPosition, true); gameObj.draw(g, trackPosition, true);
g.popTransform(); g.popTransform();
} }
@ -1999,7 +1986,7 @@ public class Game extends ComplexOpsuState {
skipButton.setHoverExpand(1.1f, MenuButton.Expand.UP_LEFT); skipButton.setHoverExpand(1.1f, MenuButton.Expand.UP_LEFT);
// load other images... // load other images...
instanceContainer.provide(GamePauseMenu.class).loadImages(); pauseState.loadImages();
data.loadImages(); data.loadImages();
} }
@ -2036,7 +2023,7 @@ public class Game extends ComplexOpsuState {
// initialize objects // initialize objects
gameObjectRenderer.initForGame(data, diameter); gameObjectRenderer.initForGame(data, diameter);
Slider.init(gameObjectRenderer.getCircleDiameter(), beatmap); Slider.init(gameObjectRenderer.circleDiameter, beatmap);
Spinner.init(displayContainer, overallDifficulty); Spinner.init(displayContainer, overallDifficulty);
Color sliderBorderColor = SkinService.skin.getSliderBorderColor(); Color sliderBorderColor = SkinService.skin.getSliderBorderColor();
if (!OPTION_IGNORE_BEATMAP_SKINS.state && beatmap.getSliderBorderColor() != null) { if (!OPTION_IGNORE_BEATMAP_SKINS.state && beatmap.getSliderBorderColor() != null) {

View File

@ -30,10 +30,9 @@ import org.lwjgl.input.Keyboard;
import org.newdawn.slick.Color; import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics; import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input; import org.newdawn.slick.Input;
import yugecin.opsudance.core.inject.Inject;
import yugecin.opsudance.core.inject.InstanceContainer;
import yugecin.opsudance.core.state.BaseOpsuState; import yugecin.opsudance.core.state.BaseOpsuState;
import static yugecin.opsudance.core.InstanceContainer.*;
import static yugecin.opsudance.options.Options.*; import static yugecin.opsudance.options.Options.*;
/** /**
@ -44,12 +43,6 @@ import static yugecin.opsudance.options.Options.*;
*/ */
public class GamePauseMenu extends BaseOpsuState { public class GamePauseMenu extends BaseOpsuState {
@Inject
private InstanceContainer instanceContainer;
@Inject
private Game gameState;
private MenuButton continueButton, retryButton, backButton; private MenuButton continueButton, retryButton, backButton;
@Override @Override
@ -105,20 +98,20 @@ public class GamePauseMenu extends BaseOpsuState {
// 'esc' will normally unpause, but will return to song menu if health is zero // 'esc' will normally unpause, but will return to song menu if health is zero
if (gameState.getRestart() == Game.Restart.LOSE) { if (gameState.getRestart() == Game.Restart.LOSE) {
SoundController.playSound(SoundEffect.MENUBACK); SoundController.playSound(SoundEffect.MENUBACK);
instanceContainer.provide(SongMenu.class).resetGameDataOnLoad(); songMenuState.resetGameDataOnLoad();
MusicController.playAt(MusicController.getBeatmap().previewTime, true); MusicController.playAt(MusicController.getBeatmap().previewTime, true);
displayContainer.switchState(SongMenu.class); displayContainer.switchState(songMenuState);
} else { } else {
SoundController.playSound(SoundEffect.MENUBACK); SoundController.playSound(SoundEffect.MENUBACK);
gameState.setRestart(Game.Restart.FALSE); gameState.setRestart(Game.Restart.FALSE);
displayContainer.switchState(Game.class); displayContainer.switchState(gameState);
} }
return true; return true;
} }
if (key == Input.KEY_R && (displayContainer.input.isKeyDown(Input.KEY_RCONTROL) || displayContainer.input.isKeyDown(Input.KEY_LCONTROL))) { if (key == Input.KEY_R && (displayContainer.input.isKeyDown(Input.KEY_RCONTROL) || displayContainer.input.isKeyDown(Input.KEY_LCONTROL))) {
gameState.setRestart(Game.Restart.MANUAL); gameState.setRestart(Game.Restart.MANUAL);
displayContainer.switchState(Game.class); displayContainer.switchState(gameState);
return true; return true;
} }
@ -139,14 +132,14 @@ public class GamePauseMenu extends BaseOpsuState {
if (continueButton.contains(x, y) && !loseState) { if (continueButton.contains(x, y) && !loseState) {
SoundController.playSound(SoundEffect.MENUBACK); SoundController.playSound(SoundEffect.MENUBACK);
gameState.setRestart(Game.Restart.FALSE); gameState.setRestart(Game.Restart.FALSE);
displayContainer.switchState(Game.class); displayContainer.switchState(gameState);
} else if (retryButton.contains(x, y)) { } else if (retryButton.contains(x, y)) {
SoundController.playSound(SoundEffect.MENUHIT); SoundController.playSound(SoundEffect.MENUHIT);
gameState.setRestart(Game.Restart.MANUAL); gameState.setRestart(Game.Restart.MANUAL);
displayContainer.switchState(Game.class); displayContainer.switchState(gameState);
} else if (backButton.contains(x, y)) { } else if (backButton.contains(x, y)) {
SoundController.playSound(SoundEffect.MENUBACK); SoundController.playSound(SoundEffect.MENUBACK);
instanceContainer.provide(SongMenu.class).resetGameDataOnLoad(); songMenuState.resetGameDataOnLoad();
if (loseState) if (loseState)
MusicController.playAt(MusicController.getBeatmap().previewTime, true); MusicController.playAt(MusicController.getBeatmap().previewTime, true);
else else
@ -155,7 +148,7 @@ public class GamePauseMenu extends BaseOpsuState {
displayContainer.resetCursor(); displayContainer.resetCursor();
} }
MusicController.setPitch(1.0f); MusicController.setPitch(1.0f);
displayContainer.switchState(SongMenu.class); displayContainer.switchState(songMenuState);
} }
return true; return true;
@ -188,10 +181,9 @@ public class GamePauseMenu extends BaseOpsuState {
@Override @Override
public boolean onCloseRequest() { public boolean onCloseRequest() {
SongMenu songmenu = instanceContainer.provide(SongMenu.class); songMenuState.resetTrackOnLoad();
songmenu.resetTrackOnLoad(); songMenuState.resetGameDataOnLoad();
songmenu.resetGameDataOnLoad(); displayContainer.switchState(songMenuState);
displayContainer.switchState(SongMenu.class);
return false; return false;
} }

View File

@ -37,11 +37,11 @@ import org.newdawn.slick.Image;
import org.newdawn.slick.Input; import org.newdawn.slick.Input;
import org.newdawn.slick.util.Log; import org.newdawn.slick.util.Log;
import yugecin.opsudance.core.events.EventBus; import yugecin.opsudance.core.events.EventBus;
import yugecin.opsudance.core.inject.Inject;
import yugecin.opsudance.core.inject.InstanceContainer;
import yugecin.opsudance.core.state.BaseOpsuState; import yugecin.opsudance.core.state.BaseOpsuState;
import yugecin.opsudance.events.BarNotificationEvent; import yugecin.opsudance.events.BarNotificationEvent;
import static yugecin.opsudance.core.InstanceContainer.*;
/** /**
* "Game Ranking" (score card) state. * "Game Ranking" (score card) state.
* <p> * <p>
@ -51,9 +51,6 @@ import yugecin.opsudance.events.BarNotificationEvent;
*/ */
public class GameRanking extends BaseOpsuState { public class GameRanking extends BaseOpsuState {
@Inject
private InstanceContainer instanceContainer;
/** Associated GameData object. */ /** Associated GameData object. */
private GameData data; private GameData data;
@ -149,7 +146,6 @@ public class GameRanking extends BaseOpsuState {
} }
// replay // replay
Game gameState = instanceContainer.provide(Game.class);
boolean returnToGame = false; boolean returnToGame = false;
boolean replayButtonPressed = replayButton.contains(x, y); boolean replayButtonPressed = replayButton.contains(x, y);
if (replayButtonPressed && !(data.isGameplay() && GameMod.AUTO.isActive())) { if (replayButtonPressed && !(data.isGameplay() && GameMod.AUTO.isActive())) {
@ -183,7 +179,7 @@ public class GameRanking extends BaseOpsuState {
Beatmap beatmap = MusicController.getBeatmap(); Beatmap beatmap = MusicController.getBeatmap();
gameState.loadBeatmap(beatmap); gameState.loadBeatmap(beatmap);
SoundController.playSound(SoundEffect.MENUHIT); SoundController.playSound(SoundEffect.MENUHIT);
displayContainer.switchState(Game.class); displayContainer.switchState(gameState);
} }
return true; return true;
} }
@ -217,12 +213,11 @@ public class GameRanking extends BaseOpsuState {
@Override @Override
public boolean onCloseRequest() { public boolean onCloseRequest() {
SongMenu songmenu = instanceContainer.provide(SongMenu.class);
if (data != null && data.isGameplay()) { if (data != null && data.isGameplay()) {
songmenu.resetTrackOnLoad(); songMenuState.resetTrackOnLoad();
} }
songmenu.resetGameDataOnLoad(); songMenuState.resetGameDataOnLoad();
displayContainer.switchState(SongMenu.class); displayContainer.switchState(songMenuState);
return false; return false;
} }
@ -232,25 +227,24 @@ public class GameRanking extends BaseOpsuState {
private void returnToSongMenu() { private void returnToSongMenu() {
SoundController.muteSoundComponent(); SoundController.muteSoundComponent();
SoundController.playSound(SoundEffect.MENUBACK); SoundController.playSound(SoundEffect.MENUBACK);
SongMenu songMenu = instanceContainer.provide(SongMenu.class);
if (data.isGameplay()) { if (data.isGameplay()) {
songMenu.resetTrackOnLoad(); songMenuState.resetTrackOnLoad();
} }
songMenu.resetGameDataOnLoad(); songMenuState.resetGameDataOnLoad();
if (displayContainer.cursor.isBeatmapSkinned()) { if (displayContainer.cursor.isBeatmapSkinned()) {
displayContainer.resetCursor(); displayContainer.resetCursor();
} }
displayContainer.switchState(SongMenu.class); displayContainer.switchState(songMenuState);
} }
/** /**
* Sets the associated GameData object. * Sets the associated GameData object.
* @param data the GameData * @param data the GameData
*/ */
public void setGameData(GameData data) { this.data = data; } public void setGameData(GameData data) { this.data = data; } // TODO why is this unused
/** /**
* Returns the current GameData object (usually null unless state active). * Returns the current GameData object (usually null unless state active).
*/ */
public GameData getGameData() { return data; } public GameData getGameData() { return data; } // TODO why is this unused
} }

View File

@ -45,14 +45,14 @@ import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image; import org.newdawn.slick.Image;
import org.newdawn.slick.Input; import org.newdawn.slick.Input;
import org.newdawn.slick.util.Log; import org.newdawn.slick.util.Log;
import yugecin.opsudance.core.Constants;
import yugecin.opsudance.core.events.EventBus; import yugecin.opsudance.core.events.EventBus;
import yugecin.opsudance.core.inject.Inject;
import yugecin.opsudance.core.inject.InstanceContainer;
import yugecin.opsudance.core.state.BaseOpsuState; import yugecin.opsudance.core.state.BaseOpsuState;
import yugecin.opsudance.core.state.OpsuState; import yugecin.opsudance.core.state.OpsuState;
import yugecin.opsudance.events.BarNotificationEvent; import yugecin.opsudance.events.BarNotificationEvent;
import yugecin.opsudance.events.BubbleNotificationEvent; import yugecin.opsudance.events.BubbleNotificationEvent;
import static yugecin.opsudance.core.InstanceContainer.*;
import static yugecin.opsudance.options.Options.*; import static yugecin.opsudance.options.Options.*;
/** /**
@ -62,12 +62,6 @@ import static yugecin.opsudance.options.Options.*;
*/ */
public class MainMenu extends BaseOpsuState { public class MainMenu extends BaseOpsuState {
@Inject
private InstanceContainer instanceContainer;
@Inject
private Updater updater;
/** Idle time, in milliseconds, before returning the logo to its original position. */ /** Idle time, in milliseconds, before returning the logo to its original position. */
private static final short LOGO_IDLE_DELAY = 10000; private static final short LOGO_IDLE_DELAY = 10000;
@ -551,7 +545,7 @@ public class MainMenu extends BaseOpsuState {
} else if (musicPrevious.contains(x, y)) { } else if (musicPrevious.contains(x, y)) {
lastMeasureProgress = 0f; lastMeasureProgress = 0f;
if (!previous.isEmpty()) { if (!previous.isEmpty()) {
instanceContainer.provide(SongMenu.class).setFocus(BeatmapSetList.get().getBaseNode(previous.pop()), -1, true, false); songMenuState.setFocus(BeatmapSetList.get().getBaseNode(previous.pop()), -1, true, false);
if (OPTION_DYNAMIC_BACKGROUND.state) { if (OPTION_DYNAMIC_BACKGROUND.state) {
bgAlpha.setTime(0); bgAlpha.setTime(0);
} }
@ -565,14 +559,14 @@ public class MainMenu extends BaseOpsuState {
// downloads button actions // downloads button actions
if (downloadsButton.contains(x, y)) { if (downloadsButton.contains(x, y)) {
SoundController.playSound(SoundEffect.MENUHIT); SoundController.playSound(SoundEffect.MENUHIT);
displayContainer.switchState(DownloadsMenu.class); displayContainer.switchState(downloadState);
return true; return true;
} }
// repository button actions // repository button actions
if (repoButton != null && repoButton.contains(x, y)) { if (repoButton != null && repoButton.contains(x, y)) {
try { try {
Desktop.getDesktop().browse(config.REPOSITORY_URI); Desktop.getDesktop().browse(Constants.REPOSITORY_URI);
} catch (UnsupportedOperationException e) { } catch (UnsupportedOperationException e) {
EventBus.post(new BarNotificationEvent("The repository web page could not be opened.")); EventBus.post(new BarNotificationEvent("The repository web page could not be opened."));
} catch (IOException e) { } catch (IOException e) {
@ -584,7 +578,7 @@ public class MainMenu extends BaseOpsuState {
if (danceRepoButton != null && danceRepoButton.contains(x, y)) { if (danceRepoButton != null && danceRepoButton.contains(x, y)) {
try { try {
Desktop.getDesktop().browse(config.DANCE_REPOSITORY_URI); Desktop.getDesktop().browse(Constants.DANCE_REPOSITORY_URI);
} catch (UnsupportedOperationException e) { } catch (UnsupportedOperationException e) {
EventBus.post(new BarNotificationEvent("The repository web page could not be opened.")); EventBus.post(new BarNotificationEvent("The repository web page could not be opened."));
} catch (IOException e) { } catch (IOException e) {
@ -665,8 +659,8 @@ public class MainMenu extends BaseOpsuState {
logoTimer = 0; logoTimer = 0;
break; break;
} }
instanceContainer.provide(ButtonMenu.class).setMenuState(MenuState.EXIT); buttonState.setMenuState(MenuState.EXIT);
displayContainer.switchState(ButtonMenu.class); displayContainer.switchState(buttonState);
return true; return true;
case Input.KEY_P: case Input.KEY_P:
SoundController.playSound(SoundEffect.MENUHIT); SoundController.playSound(SoundEffect.MENUHIT);
@ -681,7 +675,7 @@ public class MainMenu extends BaseOpsuState {
return true; return true;
case Input.KEY_D: case Input.KEY_D:
SoundController.playSound(SoundEffect.MENUHIT); SoundController.playSound(SoundEffect.MENUHIT);
displayContainer.switchState(DownloadsMenu.class); displayContainer.switchState(downloadState);
return true; return true;
case Input.KEY_R: case Input.KEY_R:
nextTrack(true); nextTrack(true);
@ -719,7 +713,7 @@ public class MainMenu extends BaseOpsuState {
MusicController.playAt(0, false); MusicController.playAt(0, false);
return; return;
} }
BeatmapSetNode node = instanceContainer.provide(SongMenu.class).setFocus(BeatmapSetList.get().getRandomNode(), -1, true, false); BeatmapSetNode node = songMenuState.setFocus(BeatmapSetList.get().getRandomNode(), -1, true, false);
boolean sameAudio = false; boolean sameAudio = false;
if (node != null) { if (node != null) {
sameAudio = MusicController.getBeatmap().audioFilename.equals(node.getBeatmapSet().get(0).audioFilename); sameAudio = MusicController.getBeatmap().audioFilename.equals(node.getBeatmapSet().get(0).audioFilename);
@ -735,10 +729,10 @@ public class MainMenu extends BaseOpsuState {
* Enters the song menu, or the downloads menu if no beatmaps are loaded. * Enters the song menu, or the downloads menu if no beatmaps are loaded.
*/ */
private void enterSongMenu() { private void enterSongMenu() {
Class<? extends OpsuState> state = SongMenu.class; OpsuState state = songMenuState;
if (BeatmapSetList.get().getMapSetCount() == 0) { if (BeatmapSetList.get().getMapSetCount() == 0) {
instanceContainer.provide(DownloadsMenu.class).notifyOnLoad("Download some beatmaps to get started!"); downloadState.notifyOnLoad("Download some beatmaps to get started!");
state = DownloadsMenu.class; state = downloadState;
} }
displayContainer.switchState(state); displayContainer.switchState(state);
} }

View File

@ -63,16 +63,13 @@ import org.newdawn.slick.Image;
import org.newdawn.slick.Input; import org.newdawn.slick.Input;
import org.newdawn.slick.SpriteSheet; import org.newdawn.slick.SpriteSheet;
import org.newdawn.slick.gui.TextField; import org.newdawn.slick.gui.TextField;
import yugecin.opsudance.core.DisplayContainer;
import yugecin.opsudance.core.events.EventBus; import yugecin.opsudance.core.events.EventBus;
import yugecin.opsudance.core.inject.Inject;
import yugecin.opsudance.core.inject.InstanceContainer;
import yugecin.opsudance.core.state.ComplexOpsuState; import yugecin.opsudance.core.state.ComplexOpsuState;
import yugecin.opsudance.events.BarNotificationEvent; import yugecin.opsudance.events.BarNotificationEvent;
import yugecin.opsudance.options.Configuration;
import yugecin.opsudance.options.OptionGroups; import yugecin.opsudance.options.OptionGroups;
import yugecin.opsudance.ui.OptionsOverlay; import yugecin.opsudance.ui.OptionsOverlay;
import static yugecin.opsudance.core.InstanceContainer.*;
import static yugecin.opsudance.options.Options.*; import static yugecin.opsudance.options.Options.*;
/** /**
@ -83,18 +80,6 @@ import static yugecin.opsudance.options.Options.*;
*/ */
public class SongMenu extends ComplexOpsuState { public class SongMenu extends ComplexOpsuState {
@Inject
private InstanceContainer instanceContainer;
@Inject
private Configuration config;
@Inject
private OszUnpacker oszUnpacker;
@Inject
private BeatmapParser beatmapParser;
/** The max number of song buttons to be shown on each screen. */ /** The max number of song buttons to be shown on each screen. */
public static final int MAX_SONG_BUTTONS = 6; public static final int MAX_SONG_BUTTONS = 6;
@ -246,7 +231,7 @@ public class SongMenu extends ComplexOpsuState {
private void reloadBeatmaps() { private void reloadBeatmaps() {
if (fullReload) { if (fullReload) {
BeatmapDB.clearDatabase(); BeatmapDB.clearDatabase();
oszUnpacker.unpackAll(); oszunpacker.unpackAll();
} }
beatmapParser.parseAll(); beatmapParser.parseAll();
} }
@ -328,7 +313,7 @@ public class SongMenu extends ComplexOpsuState {
private final OptionsOverlay optionsOverlay; private final OptionsOverlay optionsOverlay;
public SongMenu(DisplayContainer displayContainer) { public SongMenu() {
super(); super();
optionsOverlay = new OptionsOverlay(displayContainer, OptionGroups.normalOptions); optionsOverlay = new OptionsOverlay(displayContainer, OptionGroups.normalOptions);
overlays.add(optionsOverlay); overlays.add(optionsOverlay);
@ -761,8 +746,8 @@ public class SongMenu extends ComplexOpsuState {
if (focusNode != null) { if (focusNode != null) {
MenuState state = focusNode.getBeatmapSet().isFavorite() ? MenuState state = focusNode.getBeatmapSet().isFavorite() ?
MenuState.BEATMAP_FAVORITE : MenuState.BEATMAP; MenuState.BEATMAP_FAVORITE : MenuState.BEATMAP;
instanceContainer.provide(ButtonMenu.class).setMenuState(state, focusNode); buttonState.setMenuState(state, focusNode);
displayContainer.switchState(ButtonMenu.class); displayContainer.switchState(buttonState);
} }
return; return;
} }
@ -922,7 +907,7 @@ public class SongMenu extends ComplexOpsuState {
if (UI.getBackButton().contains(x, y)) { if (UI.getBackButton().contains(x, y)) {
SoundController.playSound(SoundEffect.MENUBACK); SoundController.playSound(SoundEffect.MENUBACK);
displayContainer.switchState(MainMenu.class); displayContainer.switchState(mainmenuState);
return true; return true;
} }
@ -1029,12 +1014,12 @@ public class SongMenu extends ComplexOpsuState {
SoundController.playSound(SoundEffect.MENUHIT); SoundController.playSound(SoundEffect.MENUHIT);
if (button != Input.MOUSE_RIGHT_BUTTON) { if (button != Input.MOUSE_RIGHT_BUTTON) {
// view score // view score
instanceContainer.provide(GameRanking.class).setGameData(instanceContainer.injectFields(new GameData(focusScores[rank], displayContainer.width, displayContainer.height))); gameRankingState.setGameData(new GameData(focusScores[rank]));
displayContainer.switchState(GameRanking.class); displayContainer.switchState(gameRankingState);
} else { } else {
// score management // score management
instanceContainer.provide(ButtonMenu.class).setMenuState(MenuState.SCORE, focusScores[rank]); buttonState.setMenuState(MenuState.SCORE, focusScores[rank]);
displayContainer.switchState(ButtonMenu.class); displayContainer.switchState(buttonState);
} }
return true; return true;
} }
@ -1070,13 +1055,13 @@ public class SongMenu extends ComplexOpsuState {
} else { } else {
// return to main menu // return to main menu
SoundController.playSound(SoundEffect.MENUBACK); SoundController.playSound(SoundEffect.MENUBACK);
displayContainer.switchState(MainMenu.class); displayContainer.switchState(mainmenuState);
} }
return true; return true;
case Input.KEY_F1: case Input.KEY_F1:
SoundController.playSound(SoundEffect.MENUHIT); SoundController.playSound(SoundEffect.MENUHIT);
instanceContainer.provide(ButtonMenu.class).setMenuState(MenuState.MODS); buttonState.setMenuState(MenuState.MODS);
displayContainer.switchState(ButtonMenu.class); displayContainer.switchState(buttonState);
return true; return true;
case Input.KEY_F2: case Input.KEY_F2:
if (focusNode == null) if (focusNode == null)
@ -1104,16 +1089,16 @@ public class SongMenu extends ComplexOpsuState {
SoundController.playSound(SoundEffect.MENUHIT); SoundController.playSound(SoundEffect.MENUHIT);
MenuState state = focusNode.getBeatmapSet().isFavorite() ? MenuState state = focusNode.getBeatmapSet().isFavorite() ?
MenuState.BEATMAP_FAVORITE : MenuState.BEATMAP; MenuState.BEATMAP_FAVORITE : MenuState.BEATMAP;
instanceContainer.provide(ButtonMenu.class).setMenuState(state, focusNode); buttonState.setMenuState(state, focusNode);
displayContainer.switchState(ButtonMenu.class); displayContainer.switchState(buttonState);
return true; return true;
case Input.KEY_F5: case Input.KEY_F5:
SoundController.playSound(SoundEffect.MENUHIT); SoundController.playSound(SoundEffect.MENUHIT);
if (songFolderChanged) if (songFolderChanged)
reloadBeatmaps(false); reloadBeatmaps(false);
else { else {
instanceContainer.provide(ButtonMenu.class).setMenuState(MenuState.RELOAD); buttonState.setMenuState(MenuState.RELOAD);
displayContainer.switchState(ButtonMenu.class); displayContainer.switchState(buttonState);
} }
return true; return true;
case Input.KEY_DELETE: case Input.KEY_DELETE:
@ -1123,8 +1108,8 @@ public class SongMenu extends ComplexOpsuState {
SoundController.playSound(SoundEffect.MENUHIT); SoundController.playSound(SoundEffect.MENUHIT);
MenuState ms = (focusNode.beatmapIndex == -1 || focusNode.getBeatmapSet().size() == 1) ? MenuState ms = (focusNode.beatmapIndex == -1 || focusNode.getBeatmapSet().size() == 1) ?
MenuState.BEATMAP_DELETE_CONFIRM : MenuState.BEATMAP_DELETE_SELECT; MenuState.BEATMAP_DELETE_CONFIRM : MenuState.BEATMAP_DELETE_SELECT;
instanceContainer.provide(ButtonMenu.class).setMenuState(ms, focusNode); buttonState.setMenuState(ms, focusNode);
displayContainer.switchState(ButtonMenu.class); displayContainer.switchState(buttonState);
} }
return true; return true;
case Input.KEY_ENTER: case Input.KEY_ENTER:
@ -1310,7 +1295,7 @@ public class SongMenu extends ComplexOpsuState {
// reset game data // reset game data
if (resetGame) { if (resetGame) {
instanceContainer.provide(Game.class).resetGameData(); gameState.resetGameData();
// destroy extra Clips // destroy extra Clips
MultiClip.destroyExtraClips(); MultiClip.destroyExtraClips();
@ -1787,10 +1772,9 @@ public class SongMenu extends ComplexOpsuState {
SoundController.playSound(SoundEffect.MENUHIT); SoundController.playSound(SoundEffect.MENUHIT);
MultiClip.destroyExtraClips(); MultiClip.destroyExtraClips();
Game gameState = instanceContainer.provide(Game.class);
gameState.loadBeatmap(beatmap); gameState.loadBeatmap(beatmap);
gameState.setRestart(Game.Restart.NEW); gameState.setRestart(Game.Restart.NEW);
gameState.setReplay(null); gameState.setReplay(null);
displayContainer.switchState(Game.class); displayContainer.switchState(gameState);
} }
} }

View File

@ -21,19 +21,16 @@ package itdelatrisu.opsu.states;
import itdelatrisu.opsu.GameImage; import itdelatrisu.opsu.GameImage;
import itdelatrisu.opsu.audio.MusicController; import itdelatrisu.opsu.audio.MusicController;
import itdelatrisu.opsu.audio.SoundController; import itdelatrisu.opsu.audio.SoundController;
import itdelatrisu.opsu.beatmap.BeatmapParser;
import itdelatrisu.opsu.beatmap.BeatmapSetList; import itdelatrisu.opsu.beatmap.BeatmapSetList;
import itdelatrisu.opsu.beatmap.OszUnpacker;
import itdelatrisu.opsu.replay.ReplayImporter;
import itdelatrisu.opsu.ui.UI; import itdelatrisu.opsu.ui.UI;
import org.newdawn.slick.Color; import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics; import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input; import org.newdawn.slick.Input;
import org.newdawn.slick.util.Log; import org.newdawn.slick.util.Log;
import yugecin.opsudance.core.inject.Inject;
import yugecin.opsudance.core.state.BaseOpsuState; import yugecin.opsudance.core.state.BaseOpsuState;
import static yugecin.opsudance.core.InstanceContainer.*;
import static yugecin.opsudance.options.Options.*; import static yugecin.opsudance.options.Options.*;
/** /**
@ -43,18 +40,6 @@ import static yugecin.opsudance.options.Options.*;
*/ */
public class Splash extends BaseOpsuState { public class Splash extends BaseOpsuState {
@Inject
private SongMenu songMenu;
@Inject
private ReplayImporter replayImporter;
@Inject
private OszUnpacker oszUnpacker;
@Inject
private BeatmapParser beatmapParser;
/** Whether or not loading has completed. */ /** Whether or not loading has completed. */
private boolean finished; private boolean finished;
@ -72,7 +57,7 @@ public class Splash extends BaseOpsuState {
super.revalidate(); super.revalidate();
// pre-revalidate some states to reduce lag between switching // pre-revalidate some states to reduce lag between switching
songMenu.revalidate(); songMenuState.revalidate();
if (inited) { if (inited) {
return; return;
@ -82,7 +67,7 @@ public class Splash extends BaseOpsuState {
thread = new Thread() { thread = new Thread() {
@Override @Override
public void run() { public void run() {
oszUnpacker.unpackAll(); oszunpacker.unpackAll();
beatmapParser.parseAll(); beatmapParser.parseAll();
replayImporter.importAll(); replayImporter.importAll();
@ -105,7 +90,7 @@ public class Splash extends BaseOpsuState {
// initialize song list // initialize song list
if (BeatmapSetList.get().size() == 0) { if (BeatmapSetList.get().size() == 0) {
MusicController.playThemeSong(config.themeBeatmap); MusicController.playThemeSong(config.themeBeatmap);
displayContainer.switchStateInstantly(MainMenu.class); displayContainer.switchStateInstantly(mainmenuState);
return; return;
} }
@ -113,9 +98,9 @@ public class Splash extends BaseOpsuState {
if (OPTION_ENABLE_THEME_SONG.state) { if (OPTION_ENABLE_THEME_SONG.state) {
MusicController.playThemeSong(config.themeBeatmap); MusicController.playThemeSong(config.themeBeatmap);
} else { } else {
songMenu.setFocus(BeatmapSetList.get().getRandomNode(), -1, true, true); songMenuState.setFocus(BeatmapSetList.get().getRandomNode(), -1, true, true);
} }
displayContainer.switchStateInstantly(MainMenu.class); displayContainer.switchStateInstantly(mainmenuState);
} }
@Override @Override

View File

@ -34,7 +34,7 @@ import org.newdawn.slick.font.effects.ColorEffect;
import org.newdawn.slick.font.effects.Effect; import org.newdawn.slick.font.effects.Effect;
import org.newdawn.slick.util.Log; import org.newdawn.slick.util.Log;
import org.newdawn.slick.util.ResourceLoader; import org.newdawn.slick.util.ResourceLoader;
import yugecin.opsudance.options.Configuration; import yugecin.opsudance.core.Constants;
/** /**
* Fonts used for drawing. * Fonts used for drawing.
@ -54,9 +54,9 @@ public class Fonts {
* @throws FontFormatException if any font stream data does not contain the required font tables * @throws FontFormatException if any font stream data does not contain the required font tables
* @throws IOException if a font stream cannot be completely read * @throws IOException if a font stream cannot be completely read
*/ */
public static void init(Configuration config) throws SlickException, FontFormatException, IOException { public static void init() throws SlickException, FontFormatException, IOException {
float fontBase = 12f * GameImage.getUIscale(); float fontBase = 12f * GameImage.getUIscale();
Font javaFont = Font.createFont(Font.TRUETYPE_FONT, ResourceLoader.getResourceAsStream(config.FONT_NAME)); Font javaFont = Font.createFont(Font.TRUETYPE_FONT, ResourceLoader.getResourceAsStream(Constants.FONT_NAME));
Font font = javaFont.deriveFont(Font.PLAIN, (int) (fontBase * 4 / 3)); Font font = javaFont.deriveFont(Font.PLAIN, (int) (fontBase * 4 / 3));
DEFAULT = new UnicodeFont(font); DEFAULT = new UnicodeFont(font);
BOLD = new UnicodeFont(font.deriveFont(Font.BOLD)); BOLD = new UnicodeFont(font.deriveFont(Font.BOLD));

View File

@ -40,6 +40,7 @@ import yugecin.opsudance.spinners.*;
import java.awt.*; import java.awt.*;
import static yugecin.opsudance.core.InstanceContainer.*;
import static yugecin.opsudance.options.Options.*; import static yugecin.opsudance.options.Options.*;
public class Dancer { public class Dancer {
@ -194,12 +195,12 @@ public class Dancer {
} }
isCurrentLazySlider = false; isCurrentLazySlider = false;
// detect lazy sliders, should work pretty good // detect lazy sliders, should work pretty good
if (c.isSlider() && OPTION_DANCE_LAZY_SLIDERS.state && Utils.distance(c.start.x, c.start.y, c.end.x, c.end.y) <= GameObjectRenderer.instance.getCircleDiameter() * 0.8f) { if (c.isSlider() && OPTION_DANCE_LAZY_SLIDERS.state && Utils.distance(c.start.x, c.start.y, c.end.x, c.end.y) <= gameObjectRenderer.circleDiameter * 0.8f) {
Slider s = (Slider) c; Slider s = (Slider) c;
Vec2f mid = s.getCurve().pointAt(1f); Vec2f mid = s.getCurve().pointAt(1f);
if (s.getRepeats() == 1 || Utils.distance(c.start.x, c.start.y, mid.x, mid.y) <= GameObjectRenderer.instance.getCircleDiameter() * 0.8f) { if (s.getRepeats() == 1 || Utils.distance(c.start.x, c.start.y, mid.x, mid.y) <= gameObjectRenderer.circleDiameter * 0.8f) {
mid = s.getCurve().pointAt(0.5f); mid = s.getCurve().pointAt(0.5f);
if (Utils.distance(c.start.x, c.start.y, mid.x, mid.y) <= GameObjectRenderer.instance.getCircleDiameter() * 0.8f) { if (Utils.distance(c.start.x, c.start.y, mid.x, mid.y) <= gameObjectRenderer.circleDiameter * 0.8f) {
isCurrentLazySlider = true; isCurrentLazySlider = true;
} }
} }
@ -251,8 +252,8 @@ public class Dancer {
} }
} }
Pippi.dance(time, c, isCurrentLazySlider); Pippi.dance(time, c, isCurrentLazySlider);
x = Utils.clamp(x, 10, width - 10); x = Utils.clamp(x, 10, displayContainer.width - 10);
y = Utils.clamp(y, 10, height - 10); y = Utils.clamp(y, 10, displayContainer.height - 10);
} }
private void createNewMover() { private void createNewMover() {

View File

@ -21,22 +21,16 @@ import itdelatrisu.opsu.Utils;
import itdelatrisu.opsu.beatmap.BeatmapWatchService; import itdelatrisu.opsu.beatmap.BeatmapWatchService;
import itdelatrisu.opsu.db.DBController; import itdelatrisu.opsu.db.DBController;
import itdelatrisu.opsu.downloads.DownloadList; import itdelatrisu.opsu.downloads.DownloadList;
import itdelatrisu.opsu.downloads.Updater;
import itdelatrisu.opsu.states.Splash;
import org.newdawn.slick.util.Log; import org.newdawn.slick.util.Log;
import yugecin.opsudance.core.DisplayContainer;
import yugecin.opsudance.core.errorhandling.ErrorHandler; import yugecin.opsudance.core.errorhandling.ErrorHandler;
import yugecin.opsudance.core.inject.Inject;
import yugecin.opsudance.options.Configuration;
import yugecin.opsudance.options.OptionsService;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import static yugecin.opsudance.core.Entrypoint.sout; import static yugecin.opsudance.core.Entrypoint.sout;
import static yugecin.opsudance.core.InstanceContainer.*;
import static yugecin.opsudance.options.Options.*; import static yugecin.opsudance.options.Options.*;
/* /*
@ -44,30 +38,13 @@ import static yugecin.opsudance.options.Options.*;
*/ */
public class OpsuDance { public class OpsuDance {
@Inject
private DisplayContainer container;
@Inject
private OptionsService optionsService;
@Inject
private Configuration config;
@Inject
private Updater updater;
private ServerSocket singleInstanceSocket; private ServerSocket singleInstanceSocket;
@Inject
public OpsuDance() {
}
public void start(String[] args) { public void start(String[] args) {
try { try {
sout("initialized"); sout("initialized");
checkRunningDirectory(); optionservice.loadOptions();
optionsService.loadOptions();
ensureSingleInstance(); ensureSingleInstance();
sout("prechecks done and options parsed"); sout("prechecks done and options parsed");
@ -75,15 +52,15 @@ public class OpsuDance {
initUpdater(args); initUpdater(args);
sout("database & updater initialized"); sout("database & updater initialized");
container.init(Splash.class); displayContainer.init(splashState);
} catch (Exception e) { } catch (Exception e) {
errorAndExit("startup failure", e); errorAndExit("startup failure", e);
} }
while (rungame()); while (rungame());
container.teardownAL(); displayContainer.teardownAL();
optionsService.saveOptions(); optionservice.saveOptions();
closeSingleInstanceSocket(); closeSingleInstanceSocket();
DBController.closeConnections(); DBController.closeConnections();
DownloadList.get().cancelAllDownloads(); DownloadList.get().cancelAllDownloads();
@ -95,20 +72,20 @@ public class OpsuDance {
private boolean rungame() { private boolean rungame() {
try { try {
container.setup(); displayContainer.setup();
container.resume(); displayContainer.resume();
} catch (Exception e) { } catch (Exception e) {
ErrorHandler.error("could not initialize GL", e).allowTerminate().preventContinue().show(); ErrorHandler.error("could not initialize GL", e).allowTerminate().preventContinue().show();
return false; return false;
} }
Exception caughtException = null; Exception caughtException = null;
try { try {
container.run(); displayContainer.run();
} catch (Exception e) { } catch (Exception e) {
caughtException = e; caughtException = e;
} }
container.teardown(); displayContainer.teardown();
container.pause(); displayContainer.pause();
return caughtException != null && ErrorHandler.error("update/render error", caughtException).allowTerminate().show().shouldIgnoreAndContinue(); return caughtException != null && ErrorHandler.error("update/render error", caughtException).allowTerminate().show().shouldIgnoreAndContinue();
} }
@ -142,20 +119,6 @@ public class OpsuDance {
}.start(); }.start();
} }
private void checkRunningDirectory() {
if (!Utils.isJarRunning()) {
return;
}
File runningDir = Utils.getRunningDirectory();
if (runningDir == null) {
return;
}
if (runningDir.getAbsolutePath().indexOf('!') == -1) {
return;
}
errorAndExit("Cannot run from a path that contains a '!'. Please move or rename the jar and try again.");
}
private void ensureSingleInstance() { private void ensureSingleInstance() {
if (OPTION_NOSINGLEINSTANCE.state) { if (OPTION_NOSINGLEINSTANCE.state) {
return; return;

View File

@ -19,9 +19,9 @@ package yugecin.opsudance;
import itdelatrisu.opsu.objects.GameObject; import itdelatrisu.opsu.objects.GameObject;
import itdelatrisu.opsu.objects.Slider; import itdelatrisu.opsu.objects.Slider;
import yugecin.opsudance.render.GameObjectRenderer;
import static yugecin.opsudance.options.Options.*; import static yugecin.opsudance.options.Options.*;
import static yugecin.opsudance.core.InstanceContainer.*;
public class Pippi { public class Pippi {
@ -38,14 +38,14 @@ public class Pippi {
public static void setRadiusPercent(int radiusPercent) { public static void setRadiusPercent(int radiusPercent) {
Pippi.radiusPercent = radiusPercent; Pippi.radiusPercent = radiusPercent;
pippiminrad = pippirad = (GameObjectRenderer.instance.getCircleDiameter() / 2d - 10d) * radiusPercent / 100d; pippiminrad = pippirad = (gameObjectRenderer.circleDiameter / 2d - 10d) * radiusPercent / 100d;
} }
public static void reset() { public static void reset() {
angle = 0; angle = 0;
currentdelta = 0; currentdelta = 0;
setRadiusPercent(radiusPercent); setRadiusPercent(radiusPercent);
pippimaxrad = GameObjectRenderer.instance.getCircleDiameter() - 10d; pippimaxrad = gameObjectRenderer.circleDiameter - 10d;
} }
public static void dance(int time, GameObject c, boolean isCurrentLazySlider) { public static void dance(int time, GameObject c, boolean isCurrentLazySlider) {
@ -92,7 +92,7 @@ public class Pippi {
} }
public static boolean shouldPreventWobblyStream(double distance) { public static boolean shouldPreventWobblyStream(double distance) {
return OPTION_PIPPI_ENABLE.state && distance < GameObjectRenderer.instance.getCircleDiameter() * 0.93f && OPTION_PIPPI_PREVENT_WOBBLY_STREAMS.state; return OPTION_PIPPI_ENABLE.state && distance < gameObjectRenderer.circleDiameter * 0.93f && OPTION_PIPPI_PREVENT_WOBBLY_STREAMS.state;
} }
} }

View File

@ -1,73 +0,0 @@
/*
* opsu!dance - fork of opsu! with cursordance auto
* Copyright (C) 2017 yugecin
*
* opsu!dance 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!dance 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!dance. If not, see <http://www.gnu.org/licenses/>.
*/
package yugecin.opsudance;
import itdelatrisu.opsu.NativeLoader;
import org.newdawn.slick.util.FileSystemLocation;
import org.newdawn.slick.util.Log;
import org.newdawn.slick.util.ResourceLoader;
import yugecin.opsudance.core.inject.Inject;
import yugecin.opsudance.options.Configuration;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
public class PreStartupInitializer {
private final Configuration config;
@Inject
public PreStartupInitializer(Configuration config) {
this.config = config;
loadNatives();
setResourcePath();
}
private void loadNatives() {
File nativeDir = loadNativesUsingOptionsPath();
System.setProperty("org.lwjgl.librarypath", nativeDir.getAbsolutePath());
System.setProperty("java.library.path", nativeDir.getAbsolutePath());
try {
// Workaround for "java.library.path" property being read-only.
// http://stackoverflow.com/a/24988095
Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
fieldSysPath.setAccessible(true);
fieldSysPath.set(null, null);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
Log.warn("Failed to set 'sys_paths' field.", e);
}
}
private File loadNativesUsingOptionsPath() {
File nativeDir = config.NATIVE_DIR;
try {
new NativeLoader(nativeDir).loadNatives();
} catch (IOException e) {
Log.error("Error loading natives.", e);
}
return nativeDir;
}
private void setResourcePath() {
ResourceLoader.addResourceLocation(new FileSystemLocation(new File("./res/")));
}
}

View File

@ -0,0 +1,32 @@
/*
* opsu!dance - fork of opsu! with cursordance auto
* Copyright (C) 2017 yugecin
*
* opsu!dance 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!dance 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!dance. If not, see <http://www.gnu.org/licenses/>.
*/
package yugecin.opsudance.core;
import java.net.URI;
public class Constants {
public static final String PROJECT_NAME = "opsu!dance";
public static final String FONT_NAME = "DroidSansFallback.ttf";
public static final String VERSION_FILE = "version";
public static final URI REPOSITORY_URI = URI.create("https://github.com/itdelatrisu/opsu");
public static final URI DANCE_REPOSITORY_URI = URI.create("https://github.com/yugecin/opsu-dance");
public static final String ISSUES_URL = "https://github.com/yugecin/opsu-dance/issues/new?title=%s&body=%s";
public static final String VERSION_REMOTE = "https://raw.githubusercontent.com/yugecin/opsu-dance/master/version";
}

View File

@ -42,21 +42,18 @@ import org.newdawn.slick.util.Log;
import yugecin.opsudance.core.events.EventBus; import yugecin.opsudance.core.events.EventBus;
import yugecin.opsudance.core.errorhandling.ErrorDumpable; import yugecin.opsudance.core.errorhandling.ErrorDumpable;
import yugecin.opsudance.core.events.EventListener; import yugecin.opsudance.core.events.EventListener;
import yugecin.opsudance.core.inject.Inject;
import yugecin.opsudance.core.inject.InstanceContainer;
import yugecin.opsudance.core.state.OpsuState; import yugecin.opsudance.core.state.OpsuState;
import yugecin.opsudance.core.state.specialstates.BarNotificationState; import yugecin.opsudance.core.state.specialstates.BarNotificationState;
import yugecin.opsudance.core.state.specialstates.BubbleNotificationState; import yugecin.opsudance.core.state.specialstates.BubbleNotificationState;
import yugecin.opsudance.core.state.specialstates.FpsRenderState; import yugecin.opsudance.core.state.specialstates.FpsRenderState;
import yugecin.opsudance.events.BubbleNotificationEvent; import yugecin.opsudance.events.BubbleNotificationEvent;
import yugecin.opsudance.events.ResolutionOrSkinChangedEvent; import yugecin.opsudance.events.ResolutionOrSkinChangedEvent;
import yugecin.opsudance.options.Configuration;
import yugecin.opsudance.skinning.SkinService;
import yugecin.opsudance.utils.GLHelper; import yugecin.opsudance.utils.GLHelper;
import java.io.StringWriter; import java.io.StringWriter;
import static yugecin.opsudance.core.Entrypoint.sout; import static yugecin.opsudance.core.Entrypoint.sout;
import static yugecin.opsudance.core.InstanceContainer.*;
import static yugecin.opsudance.options.Options.*; import static yugecin.opsudance.options.Options.*;
/** /**
@ -64,16 +61,8 @@ import static yugecin.opsudance.options.Options.*;
*/ */
public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListener { public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListener {
@Inject
private SkinService skinService;
@Inject
private Configuration config;
private static SGL GL = Renderer.get(); private static SGL GL = Renderer.get();
private final InstanceContainer instanceContainer;
private FpsRenderState fpsState; private FpsRenderState fpsState;
private BarNotificationState barNotifState; private BarNotificationState barNotifState;
private BubbleNotificationState bubNotifState; private BubbleNotificationState bubNotifState;
@ -156,9 +145,7 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
private final Transition transition = new Transition(); private final Transition transition = new Transition();
@Inject public DisplayContainer() {
public DisplayContainer(InstanceContainer instanceContainer) {
this.instanceContainer = instanceContainer;
this.cursor = new Cursor(); this.cursor = new Cursor();
drawCursor = true; drawCursor = true;
@ -183,7 +170,7 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
setFPS(targetFPS[targetFPSIndex]); setFPS(targetFPS[targetFPSIndex]);
MusicController.setMusicVolume(OPTION_MUSIC_VOLUME.val / 100f * OPTION_MASTER_VOLUME.val / 100f); MusicController.setMusicVolume(OPTION_MUSIC_VOLUME.val / 100f * OPTION_MASTER_VOLUME.val / 100f);
skinService.loadSkin(); skinservice.loadSkin();
// initialize game images // initialize game images
for (GameImage img : GameImage.values()) { for (GameImage img : GameImage.values()) {
@ -210,16 +197,16 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
targetRenderInterval = 1000 / targetRendersPerSecond; targetRenderInterval = 1000 / targetRendersPerSecond;
} }
public void init(Class<? extends OpsuState> startingState) { public void init(OpsuState startingState) {
setUPS(OPTION_TARGET_UPS.val); setUPS(OPTION_TARGET_UPS.val);
setFPS(targetFPS[targetFPSIndex]); setFPS(targetFPS[targetFPSIndex]);
state = instanceContainer.provide(startingState); state = startingState;
state.enter(); state.enter();
fpsState = instanceContainer.provide(FpsRenderState.class); fpsState = new FpsRenderState();
bubNotifState = instanceContainer.provide(BubbleNotificationState.class); bubNotifState = new BubbleNotificationState();
barNotifState = instanceContainer.provide(BarNotificationState.class); barNotifState = new BarNotificationState();
} }
@ -352,7 +339,7 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
exitconfirmation = System.currentTimeMillis(); exitconfirmation = System.currentTimeMillis();
return false; return false;
} }
if (Updater.get().getStatus() == Updater.Status.UPDATE_DOWNLOADING) { if (updater.getStatus() == Updater.Status.UPDATE_DOWNLOADING) {
EventBus.post(new BubbleNotificationEvent(Updater.EXIT_CONFIRMATION, BubbleNotificationEvent.COMMONCOLOR_PURPLE)); EventBus.post(new BubbleNotificationEvent(Updater.EXIT_CONFIRMATION, BubbleNotificationEvent.COMMONCOLOR_PURPLE));
exitRequested = false; exitRequested = false;
exitconfirmation = System.currentTimeMillis(); exitconfirmation = System.currentTimeMillis();
@ -447,7 +434,7 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
sout("GL ready"); sout("GL ready");
GameImage.init(width, height); GameImage.init(width, height);
Fonts.init(config); Fonts.init();
EventBus.post(new ResolutionOrSkinChangedEvent(null, width, height)); EventBus.post(new ResolutionOrSkinChangedEvent(null, width, height));
} }
@ -478,33 +465,25 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
return state.isInstance(state); return state.isInstance(state);
} }
public void switchState(Class<? extends OpsuState> newState, int outtime, int intime) { public void switchState(OpsuState state) {
switchState(state, 200, 300);
}
public void switchState(OpsuState newstate, int outtime, int intime) {
if (transition.progress != -1) { if (transition.progress != -1) {
return; return;
} }
// TODO remove this v
OpsuState _newstate = instanceContainer.provide(newState);
if (outtime == 0) { if (outtime == 0) {
switchStateInstantly(_newstate); switchStateInstantly(newstate);
_newstate = null; newstate = null;
} }
transition.nextstate = _newstate; transition.nextstate = newstate;
transition.total = transition.in = intime; transition.total = transition.in = intime;
transition.out = outtime; transition.out = outtime;
transition.total += outtime; transition.total += outtime;
transition.progress = 0; transition.progress = 0;
} }
@Deprecated // TODO instcontainer
public void switchState(Class<? extends OpsuState> state) {
switchState(state, 200, 300);
}
@Deprecated // TODO instcontainer
public void switchStateInstantly(Class<? extends OpsuState> state) {
switchStateInstantly(instanceContainer.provide(state));
}
public void switchStateInstantly(OpsuState state) { public void switchStateInstantly(OpsuState state) {
this.state.leave(); this.state.leave();
this.state = state; this.state = state;

View File

@ -19,7 +19,11 @@ package yugecin.opsudance.core;
import itdelatrisu.opsu.downloads.Updater; import itdelatrisu.opsu.downloads.Updater;
import yugecin.opsudance.OpsuDance; import yugecin.opsudance.OpsuDance;
import yugecin.opsudance.core.inject.OpsuDanceInjector;
import javax.swing.*;
import static yugecin.opsudance.core.Constants.PROJECT_NAME;
import static yugecin.opsudance.core.InstanceContainer.*;
public class Entrypoint { public class Entrypoint {
@ -27,10 +31,18 @@ public class Entrypoint {
public static void main(String[] args) { public static void main(String[] args) {
sout("launched"); sout("launched");
(new OpsuDanceInjector()).provide(OpsuDance.class).start(args);
if (Updater.get().getStatus() == Updater.Status.UPDATE_FINAL) { try {
Updater.get().runUpdate(); InstanceContainer.kickstart();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage(), "Cannot start " + PROJECT_NAME, JOptionPane.ERROR_MESSAGE);
// TODO replace with errorhandler
}
new OpsuDance().start(args);
if (updater.getStatus() == Updater.Status.UPDATE_FINAL) {
updater.runUpdate();
} }
} }
@ -39,7 +51,7 @@ public class Entrypoint {
} }
public static void sout(String message) { public static void sout(String message) {
System.out.println(String.format("[%7d] %s", runtime(), message)); System.out.println(String.format("[%8d] %s", runtime(), message));
} }
} }

View File

@ -0,0 +1,62 @@
/*
* opsu!dance - fork of opsu! with cursordance auto
* Copyright (C) 2017 yugecin
*
* opsu!dance 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!dance 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!dance. If not, see <http://www.gnu.org/licenses/>.
*/
package yugecin.opsudance.core;
import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.jar.JarFile;
import static yugecin.opsudance.core.Constants.PROJECT_NAME;
public class Environment {
public final boolean isJarRunning;
public final File workingdir;
public final JarFile jarfile;
public Environment() {
Class thiz = Environment.class;
String thisClassLocation = thiz.getResource(thiz.getSimpleName() + ".class").toString();
this.isJarRunning = thisClassLocation.startsWith("jar:");
if (!isJarRunning) {
this.workingdir = Paths.get(".").toAbsolutePath().normalize().toFile();
this.jarfile = null;
} else {
String wdir = thisClassLocation.substring(6); // remove the jar://
String separator = "!/";
int separatorIdx = wdir.indexOf(separator);
int lastSeparatorIdx = wdir.lastIndexOf(separator);
if (separatorIdx != lastSeparatorIdx) {
String msg = String.format("%s cannot run from paths containing '!/', please move the file. Current directory: %s",
PROJECT_NAME, thisClassLocation.substring(0, lastSeparatorIdx));
throw new RuntimeException(msg);
}
File jar = new File(wdir.substring(0, separatorIdx));
this.workingdir = jar.getParentFile();
try {
this.jarfile = new JarFile(jar);
} catch (IOException e) {
String msg = String.format("Cannot read from jarfile (%s): %s", jar.getAbsolutePath(),
e.getMessage());
throw new RuntimeException(msg, e);
}
}
}
}

View File

@ -0,0 +1,89 @@
/*
* opsu!dance - fork of opsu! with cursordance auto
* Copyright (C) 2017 yugecin
*
* opsu!dance 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!dance 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!dance. If not, see <http://www.gnu.org/licenses/>.
*/
package yugecin.opsudance.core;
import itdelatrisu.opsu.NativeLoader;
import itdelatrisu.opsu.beatmap.BeatmapParser;
import itdelatrisu.opsu.beatmap.OszUnpacker;
import itdelatrisu.opsu.downloads.Updater;
import itdelatrisu.opsu.replay.ReplayImporter;
import itdelatrisu.opsu.states.*;
import org.newdawn.slick.util.FileSystemLocation;
import org.newdawn.slick.util.ResourceLoader;
import yugecin.opsudance.options.Configuration;
import yugecin.opsudance.options.OptionsService;
import yugecin.opsudance.render.GameObjectRenderer;
import yugecin.opsudance.skinning.SkinService;
import java.io.File;
public class InstanceContainer {
public static Environment env;
public static Configuration config;
public static OptionsService optionservice;
public static SkinService skinservice;
public static OszUnpacker oszunpacker;
public static ReplayImporter replayImporter;
public static BeatmapParser beatmapParser;
public static Updater updater;
public static DisplayContainer displayContainer;
public static GameObjectRenderer gameObjectRenderer;
public static Splash splashState;
public static MainMenu mainmenuState;
public static ButtonMenu buttonState;
public static SongMenu songMenuState;
public static DownloadsMenu downloadState;
public static Game gameState;
public static GameRanking gameRankingState;
public static GamePauseMenu pauseState;
public static void kickstart() {
updater = new Updater();
env = new Environment();
config = new Configuration();
NativeLoader.loadNatives();
ResourceLoader.addResourceLocation(new FileSystemLocation(new File("./res/")));
optionservice = new OptionsService();
skinservice = new SkinService();
oszunpacker = new OszUnpacker();
replayImporter = new ReplayImporter();
beatmapParser = new BeatmapParser();
updater = new Updater();
displayContainer = new DisplayContainer();
gameObjectRenderer = new GameObjectRenderer();
splashState = new Splash();
mainmenuState = new MainMenu();
buttonState = new ButtonMenu();
songMenuState = new SongMenu();
downloadState = new DownloadsMenu();
gameState = new Game();
gameRankingState = new GameRanking();
pauseState = new GamePauseMenu();
}
}

View File

@ -0,0 +1,23 @@
/*
* opsu!dance - fork of opsu! with cursordance auto
* Copyright (C) 2017 yugecin
*
* opsu!dance 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!dance 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!dance. If not, see <http://www.gnu.org/licenses/>.
*/
package yugecin.opsudance.core;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.SOURCE) public @interface NotNull {}

View File

@ -0,0 +1,23 @@
/*
* opsu!dance - fork of opsu! with cursordance auto
* Copyright (C) 2017 yugecin
*
* opsu!dance 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!dance 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!dance. If not, see <http://www.gnu.org/licenses/>.
*/
package yugecin.opsudance.core;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.SOURCE) public @interface Nullable {}

View File

@ -19,6 +19,7 @@ package yugecin.opsudance.core.errorhandling;
import itdelatrisu.opsu.Utils; import itdelatrisu.opsu.Utils;
import org.newdawn.slick.util.Log; import org.newdawn.slick.util.Log;
import yugecin.opsudance.core.Constants;
import yugecin.opsudance.core.DisplayContainer; import yugecin.opsudance.core.DisplayContainer;
import yugecin.opsudance.options.Configuration; import yugecin.opsudance.options.Configuration;
import yugecin.opsudance.utils.MiscUtils; import yugecin.opsudance.utils.MiscUtils;
@ -232,7 +233,7 @@ public class ErrorHandler {
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
Log.warn("URLEncoder failed to encode the auto-filled issue report URL.", e); Log.warn("URLEncoder failed to encode the auto-filled issue report URL.", e);
} }
return URI.create(String.format(config.ISSUES_URL, issueTitle, issueBody)); return URI.create(String.format(Constants.ISSUES_URL, issueTitle, issueBody));
} }
private String truncateGithubIssueBody(String body) { private String truncateGithubIssueBody(String body) {

View File

@ -23,7 +23,6 @@ import itdelatrisu.opsu.beatmap.OszUnpacker;
import itdelatrisu.opsu.downloads.Updater; import itdelatrisu.opsu.downloads.Updater;
import itdelatrisu.opsu.replay.ReplayImporter; import itdelatrisu.opsu.replay.ReplayImporter;
import itdelatrisu.opsu.states.*; import itdelatrisu.opsu.states.*;
import yugecin.opsudance.PreStartupInitializer;
import yugecin.opsudance.core.DisplayContainer; import yugecin.opsudance.core.DisplayContainer;
import yugecin.opsudance.core.state.specialstates.BarNotificationState; import yugecin.opsudance.core.state.specialstates.BarNotificationState;
import yugecin.opsudance.core.state.specialstates.BubbleNotificationState; import yugecin.opsudance.core.state.specialstates.BubbleNotificationState;
@ -46,7 +45,7 @@ public class OpsuDanceInjector extends Injector {
bind(Updater.class).asLazySingleton(); bind(Updater.class).asLazySingleton();
bind(SkinService.class).asEagerSingleton(); bind(SkinService.class).asEagerSingleton();
bind(PreStartupInitializer.class).asEagerSingleton(); //bind(PreStartupInitializer.class).asEagerSingleton();
bind(DisplayContainer.class).asEagerSingleton(); bind(DisplayContainer.class).asEagerSingleton();
bind(ErrorHandler.class).asEagerSingleton(); bind(ErrorHandler.class).asEagerSingleton();

View File

@ -21,30 +21,18 @@ import itdelatrisu.opsu.states.Game;
import itdelatrisu.opsu.ui.UI; import itdelatrisu.opsu.ui.UI;
import org.newdawn.slick.Graphics; import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input; import org.newdawn.slick.Input;
import yugecin.opsudance.core.DisplayContainer;
import yugecin.opsudance.core.events.EventBus; import yugecin.opsudance.core.events.EventBus;
import yugecin.opsudance.core.events.EventListener; import yugecin.opsudance.core.events.EventListener;
import yugecin.opsudance.core.inject.Inject;
import yugecin.opsudance.events.BarNotificationEvent; import yugecin.opsudance.events.BarNotificationEvent;
import yugecin.opsudance.events.ResolutionOrSkinChangedEvent; import yugecin.opsudance.events.ResolutionOrSkinChangedEvent;
import yugecin.opsudance.options.Configuration;
import yugecin.opsudance.skinning.SkinService;
import java.io.StringWriter; import java.io.StringWriter;
import static yugecin.opsudance.options.Options.*; import static yugecin.opsudance.options.Options.*;
import static yugecin.opsudance.core.InstanceContainer.*;
public abstract class BaseOpsuState implements OpsuState, EventListener<ResolutionOrSkinChangedEvent> { public abstract class BaseOpsuState implements OpsuState, EventListener<ResolutionOrSkinChangedEvent> {
@Inject
protected DisplayContainer displayContainer;
@Inject
protected Configuration config;
@Inject
protected SkinService skinService;
/** /**
* state is dirty when resolution or skin changed but hasn't rendered yet * state is dirty when resolution or skin changed but hasn't rendered yet
*/ */
@ -120,7 +108,7 @@ public abstract class BaseOpsuState implements OpsuState, EventListener<Resoluti
} }
Input input = displayContainer.input; Input input = displayContainer.input;
if (key == Input.KEY_S && input.isKeyDown(Input.KEY_LMENU) && input.isKeyDown(Input.KEY_LSHIFT) &&input.isKeyDown(Input.KEY_LCONTROL) && !displayContainer.isInState(Game.class)) { if (key == Input.KEY_S && input.isKeyDown(Input.KEY_LMENU) && input.isKeyDown(Input.KEY_LSHIFT) &&input.isKeyDown(Input.KEY_LCONTROL) && !displayContainer.isInState(Game.class)) {
skinService.reloadSkin(); skinservice.reloadSkin();
} }
return false; return false;
} }

View File

@ -23,6 +23,8 @@ import yugecin.opsudance.core.components.Component;
import java.util.LinkedList; import java.util.LinkedList;
import static yugecin.opsudance.core.InstanceContainer.*;
public abstract class ComplexOpsuState extends BaseOpsuState { public abstract class ComplexOpsuState extends BaseOpsuState {
protected final LinkedList<Component> components; protected final LinkedList<Component> components;

View File

@ -21,7 +21,6 @@ import itdelatrisu.opsu.ui.Fonts;
import itdelatrisu.opsu.ui.animations.AnimationEquation; import itdelatrisu.opsu.ui.animations.AnimationEquation;
import org.newdawn.slick.Color; import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics; import org.newdawn.slick.Graphics;
import yugecin.opsudance.core.DisplayContainer;
import yugecin.opsudance.core.events.EventBus; import yugecin.opsudance.core.events.EventBus;
import yugecin.opsudance.core.events.EventListener; import yugecin.opsudance.core.events.EventListener;
import yugecin.opsudance.events.BarNotificationEvent; import yugecin.opsudance.events.BarNotificationEvent;
@ -29,6 +28,8 @@ import yugecin.opsudance.events.ResolutionOrSkinChangedEvent;
import java.util.List; import java.util.List;
import static yugecin.opsudance.core.InstanceContainer.displayContainer;
public class BarNotificationState implements EventListener<BarNotificationEvent> { public class BarNotificationState implements EventListener<BarNotificationEvent> {
private final int IN_TIME = 200; private final int IN_TIME = 200;
@ -36,7 +37,6 @@ public class BarNotificationState implements EventListener<BarNotificationEvent>
private final int OUT_TIME = 200; private final int OUT_TIME = 200;
private final int TOTAL_TIME = DISPLAY_TIME + OUT_TIME; private final int TOTAL_TIME = DISPLAY_TIME + OUT_TIME;
private final DisplayContainer displayContainer;
private final Color bgcol; private final Color bgcol;
private final Color textCol; private final Color textCol;
@ -49,8 +49,7 @@ public class BarNotificationState implements EventListener<BarNotificationEvent>
private int barHalfTargetHeight; private int barHalfTargetHeight;
private int barHalfHeight; private int barHalfHeight;
public BarNotificationState(DisplayContainer displayContainer) { public BarNotificationState() {
this.displayContainer = displayContainer;
this.bgcol = new Color(Color.black); this.bgcol = new Color(Color.black);
this.textCol = new Color(Color.white); this.textCol = new Color(Color.white);
this.timeShown = TOTAL_TIME; this.timeShown = TOTAL_TIME;

View File

@ -21,7 +21,6 @@ import itdelatrisu.opsu.ui.Fonts;
import itdelatrisu.opsu.ui.animations.AnimationEquation; import itdelatrisu.opsu.ui.animations.AnimationEquation;
import org.newdawn.slick.Color; import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics; import org.newdawn.slick.Graphics;
import yugecin.opsudance.core.DisplayContainer;
import yugecin.opsudance.core.events.EventBus; import yugecin.opsudance.core.events.EventBus;
import yugecin.opsudance.core.events.EventListener; import yugecin.opsudance.core.events.EventListener;
import yugecin.opsudance.events.BubbleNotificationEvent; import yugecin.opsudance.events.BubbleNotificationEvent;
@ -31,6 +30,8 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.ListIterator; import java.util.ListIterator;
import static yugecin.opsudance.core.InstanceContainer.displayContainer;
public class BubbleNotificationState implements EventListener<BubbleNotificationEvent> { public class BubbleNotificationState implements EventListener<BubbleNotificationEvent> {
public static final int IN_TIME = 633; public static final int IN_TIME = 633;
@ -38,14 +39,12 @@ public class BubbleNotificationState implements EventListener<BubbleNotification
public static final int OUT_TIME = 433; public static final int OUT_TIME = 433;
public static final int TOTAL_TIME = DISPLAY_TIME + OUT_TIME; public static final int TOTAL_TIME = DISPLAY_TIME + OUT_TIME;
private final DisplayContainer displayContainer;
private final LinkedList<Notification> bubbles; private final LinkedList<Notification> bubbles;
private int addAnimationTime; private int addAnimationTime;
private int addAnimationHeight; private int addAnimationHeight;
public BubbleNotificationState(DisplayContainer displayContainer) { public BubbleNotificationState() {
this.displayContainer = displayContainer;
this.bubbles = new LinkedList<>(); this.bubbles = new LinkedList<>();
this.addAnimationTime = IN_TIME; this.addAnimationTime = IN_TIME;
EventBus.subscribe(BubbleNotificationEvent.class, this); EventBus.subscribe(BubbleNotificationEvent.class, this);

View File

@ -20,13 +20,13 @@ package yugecin.opsudance.core.state.specialstates;
import itdelatrisu.opsu.ui.Fonts; import itdelatrisu.opsu.ui.Fonts;
import org.newdawn.slick.Color; import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics; import org.newdawn.slick.Graphics;
import yugecin.opsudance.core.DisplayContainer;
import yugecin.opsudance.core.events.EventBus; import yugecin.opsudance.core.events.EventBus;
import yugecin.opsudance.core.events.EventListener; import yugecin.opsudance.core.events.EventListener;
import yugecin.opsudance.events.ResolutionOrSkinChangedEvent; import yugecin.opsudance.events.ResolutionOrSkinChangedEvent;
import yugecin.opsudance.utils.FPSMeter; import yugecin.opsudance.utils.FPSMeter;
import static yugecin.opsudance.options.Options.*; import static yugecin.opsudance.options.Options.*;
import static yugecin.opsudance.core.InstanceContainer.displayContainer;
public class FpsRenderState implements EventListener<ResolutionOrSkinChangedEvent> { public class FpsRenderState implements EventListener<ResolutionOrSkinChangedEvent> {
@ -34,7 +34,6 @@ public class FpsRenderState implements EventListener<ResolutionOrSkinChangedEven
private final static Color ORANGE = new Color(255, 204, 34); private final static Color ORANGE = new Color(255, 204, 34);
private final static Color DARKORANGE = new Color(255, 149, 24); private final static Color DARKORANGE = new Color(255, 149, 24);
private final DisplayContainer displayContainer;
private final FPSMeter fpsMeter; private final FPSMeter fpsMeter;
private final FPSMeter upsMeter; private final FPSMeter upsMeter;
@ -42,8 +41,7 @@ public class FpsRenderState implements EventListener<ResolutionOrSkinChangedEven
private int y; private int y;
private int singleHeight; private int singleHeight;
public FpsRenderState(DisplayContainer displayContainer) { public FpsRenderState() {
this.displayContainer = displayContainer;
fpsMeter = new FPSMeter(10); fpsMeter = new FPSMeter(10);
upsMeter = new FPSMeter(10); upsMeter = new FPSMeter(10);
EventBus.subscribe(ResolutionOrSkinChangedEvent.class, this); EventBus.subscribe(ResolutionOrSkinChangedEvent.class, this);

View File

@ -19,7 +19,8 @@ package yugecin.opsudance.movers;
import itdelatrisu.opsu.Utils; import itdelatrisu.opsu.Utils;
import itdelatrisu.opsu.objects.GameObject; import itdelatrisu.opsu.objects.GameObject;
import yugecin.opsudance.options.Options;
import static yugecin.opsudance.core.InstanceContainer.*;
public class CircleMover extends Mover { public class CircleMover extends Mover {
@ -63,7 +64,7 @@ public class CircleMover extends Mover {
double a = ang + SOME_CONSTANT * t; double a = ang + SOME_CONSTANT * t;
pos[0] = (startX + (endX - startX) * t) - middlexoffset - Math.cos(a) * radius; pos[0] = (startX + (endX - startX) * t) - middlexoffset - Math.cos(a) * radius;
pos[1] = (startY + (endY - startY) * t) - middleyoffset - Math.sin(a) * radius; pos[1] = (startY + (endY - startY) * t) - middleyoffset - Math.sin(a) * radius;
if (pos[0] < 0 || Options.width < pos[0] || pos[1] < 0 || Options.height < pos[1]) { if (pos[0] < 0 || displayContainer.width < pos[0] || pos[1] < 0 || displayContainer.height < pos[1]) {
pass = false; pass = false;
break; break;
} }

View File

@ -18,11 +18,11 @@
package yugecin.opsudance.movers; package yugecin.opsudance.movers;
import itdelatrisu.opsu.objects.GameObject; import itdelatrisu.opsu.objects.GameObject;
import yugecin.opsudance.options.Options;
import java.util.Random; import java.util.Random;
import static yugecin.opsudance.options.Options.*; import static yugecin.opsudance.options.Options.*;
import static yugecin.opsudance.core.InstanceContainer.*;
public class ExgonMover extends Mover { public class ExgonMover extends Mover {
@ -44,8 +44,8 @@ public class ExgonMover extends Mover {
pos[0] = endX; pos[0] = endX;
pos[1] = endY; pos[1] = endY;
} else { } else {
pos[0] = randgen.nextInt(Options.width); pos[0] = randgen.nextInt(displayContainer.width);
pos[1] = randgen.nextInt(Options.height); pos[1] = randgen.nextInt(displayContainer.height);
} }
} }
return pos; return pos;

View File

@ -22,9 +22,8 @@ import itdelatrisu.opsu.beatmap.HitObject;
import itdelatrisu.opsu.objects.GameObject; import itdelatrisu.opsu.objects.GameObject;
import yugecin.opsudance.Pippi; import yugecin.opsudance.Pippi;
import yugecin.opsudance.movers.*; import yugecin.opsudance.movers.*;
import yugecin.opsudance.options.Options;
import yugecin.opsudance.render.GameObjectRenderer;
import static yugecin.opsudance.core.InstanceContainer.*;
import static yugecin.opsudance.options.Options.*; import static yugecin.opsudance.options.Options.*;
public class AutoMoverFactory implements MoverFactory { public class AutoMoverFactory implements MoverFactory {
@ -45,7 +44,7 @@ public class AutoMoverFactory implements MoverFactory {
// stacked: circles if not too quick // stacked: circles if not too quick
int circle_stream = OPTION_DANCE_CIRCLE_STREAMS.state ? 58: 85; int circle_stream = OPTION_DANCE_CIRCLE_STREAMS.state ? 58: 85;
if (distance < GameObjectRenderer.instance.getCircleDiameter() && ((dt > circle_stream && !OPTION_DANCE_ONLY_CIRCLE_STACKS.state) || distance < HitObject.getStackOffset() * 5.2f)) { // TODO get the correct multiplier for stackoffsets if (distance < gameObjectRenderer.circleDiameter && ((dt > circle_stream && !OPTION_DANCE_ONLY_CIRCLE_STACKS.state) || distance < HitObject.getStackOffset() * 5.2f)) { // TODO get the correct multiplier for stackoffsets
return new CircleMover(start, end, dir); return new CircleMover(start, end, dir);
} }
@ -103,7 +102,8 @@ public class AutoMoverFactory implements MoverFactory {
} }
private boolean checkBounds( double[] pos ) { private boolean checkBounds( double[] pos ) {
return 0 < pos[0] && pos[0] < Options.width - Options.width / 8 && 0 < pos[1] && pos[1] < Options.height - Options.height / 8; return 0 < pos[0] && pos[0] < displayContainer.width - displayContainer.width / 8 &&
0 < pos[1] && pos[1] < displayContainer.height - displayContainer.height / 8;
} }
@Override @Override

View File

@ -20,7 +20,6 @@ package yugecin.opsudance.options;
import com.sun.jna.platform.win32.Advapi32Util; import com.sun.jna.platform.win32.Advapi32Util;
import com.sun.jna.platform.win32.Win32Exception; import com.sun.jna.platform.win32.Win32Exception;
import com.sun.jna.platform.win32.WinReg; import com.sun.jna.platform.win32.WinReg;
import itdelatrisu.opsu.Utils;
import itdelatrisu.opsu.audio.SoundController; import itdelatrisu.opsu.audio.SoundController;
import itdelatrisu.opsu.audio.SoundEffect; import itdelatrisu.opsu.audio.SoundEffect;
import itdelatrisu.opsu.beatmap.Beatmap; import itdelatrisu.opsu.beatmap.Beatmap;
@ -30,31 +29,26 @@ import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import yugecin.opsudance.core.errorhandling.ErrorHandler; import yugecin.opsudance.core.errorhandling.ErrorHandler;
import yugecin.opsudance.core.events.EventBus; import yugecin.opsudance.core.events.EventBus;
import yugecin.opsudance.core.inject.Inject;
import yugecin.opsudance.events.BubbleNotificationEvent; import yugecin.opsudance.events.BubbleNotificationEvent;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URI;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.file.Paths;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.jar.Attributes; import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.jar.Manifest; import java.util.jar.Manifest;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import static yugecin.opsudance.options.Options.*; import static yugecin.opsudance.options.Options.*;
import static yugecin.opsudance.core.InstanceContainer.*;
public class Configuration { public class Configuration {
public static Configuration instance;
public final boolean USE_XDG; public final boolean USE_XDG;
public final File CONFIG_DIR; public final File CONFIG_DIR;
public final File DATA_DIR; public final File DATA_DIR;
@ -69,13 +63,6 @@ public class Configuration {
public final File LOG_FILE; public final File LOG_FILE;
public final File OPTIONS_FILE; public final File OPTIONS_FILE;
public final String FONT_NAME;
public final String VERSION_FILE;
public final URI REPOSITORY_URI;
public final URI DANCE_REPOSITORY_URI;
public final String ISSUES_URL;
public final String VERSION_REMOTE;
public final File osuInstallationDirectory; public final File osuInstallationDirectory;
public final Beatmap themeBeatmap; public final Beatmap themeBeatmap;
@ -87,10 +74,7 @@ public class Configuration {
public File replayImportDir; public File replayImportDir;
public File skinRootDir; public File skinRootDir;
@Inject
public Configuration() { public Configuration() {
instance = this;
USE_XDG = areXDGDirectoriesEnabled(); USE_XDG = areXDGDirectoriesEnabled();
CONFIG_DIR = getXDGBaseDir("XDG_CONFIG_HOME", ".config"); CONFIG_DIR = getXDGBaseDir("XDG_CONFIG_HOME", ".config");
@ -107,13 +91,6 @@ public class Configuration {
LOG_FILE = new File(CONFIG_DIR, ".opsu.log"); LOG_FILE = new File(CONFIG_DIR, ".opsu.log");
OPTIONS_FILE = new File(CONFIG_DIR, ".opsu.cfg"); OPTIONS_FILE = new File(CONFIG_DIR, ".opsu.cfg");
FONT_NAME = "DroidSansFallback.ttf";
VERSION_FILE = "version";
REPOSITORY_URI = URI.create("https://github.com/itdelatrisu/opsu");
DANCE_REPOSITORY_URI = URI.create("https://github.com/yugecin/opsu-dance");
ISSUES_URL = "https://github.com/yugecin/opsu-dance/issues/new?title=%s&body=%s";
VERSION_REMOTE = "https://raw.githubusercontent.com/yugecin/opsu-dance/master/version";
osuInstallationDirectory = loadOsuInstallationDirectory(); osuInstallationDirectory = loadOsuInstallationDirectory();
themeBeatmap = createThemeBeatmap(); themeBeatmap = createThemeBeatmap();
@ -200,12 +177,11 @@ public class Configuration {
} }
private boolean areXDGDirectoriesEnabled() { private boolean areXDGDirectoriesEnabled() {
JarFile jarFile = Utils.getJarFile(); if (env.jarfile == null) {
if (jarFile == null) {
return false; return false;
} }
try { try {
Manifest manifest = jarFile.getManifest(); Manifest manifest = env.jarfile.getManifest();
if (manifest == null) { if (manifest == null) {
return false; return false;
} }
@ -220,28 +196,21 @@ public class Configuration {
/** /**
* Returns the directory based on the XDG base directory specification for * Returns the directory based on the XDG base directory specification for
* Unix-like operating systems, only if the "XDG" flag is enabled. * Unix-like operating systems, only if the "XDG" flag is enabled.
* @param env the environment variable to check (XDG_*_*) * @param envvar the environment variable to check (XDG_*_*)
* @param fallback the fallback directory relative to ~home * @param fallback the fallback directory relative to ~home
* @return the XDG base directory, or the working directory if unavailable * @return the XDG base directory, or the working directory if unavailable
*/ */
private File getXDGBaseDir(String env, String fallback) { private File getXDGBaseDir(String envvar, String fallback) {
File workingdir;
if (Utils.isJarRunning()) {
workingdir = Utils.getRunningDirectory().getParentFile();
} else {
workingdir = Paths.get(".").toAbsolutePath().normalize().toFile();
}
if (!USE_XDG) { if (!USE_XDG) {
return workingdir; return env.workingdir;
} }
String OS = System.getProperty("os.name").toLowerCase(); String OS = System.getProperty("os.name").toLowerCase();
if (OS.indexOf("nix") == -1 && OS.indexOf("nux") == -1 && OS.indexOf("aix") == -1){ if (OS.indexOf("nix") == -1 && OS.indexOf("nux") == -1 && OS.indexOf("aix") == -1){
return workingdir; return env.workingdir;
} }
String rootPath = System.getenv(env); String rootPath = System.getenv(envvar);
if (rootPath == null) { if (rootPath == null) {
String home = System.getProperty("user.home"); String home = System.getProperty("user.home");
if (home == null) { if (home == null) {

View File

@ -17,22 +17,10 @@
*/ */
package yugecin.opsudance.options; package yugecin.opsudance.options;
import yugecin.opsudance.core.DisplayContainer; import static yugecin.opsudance.core.InstanceContainer.*;
import yugecin.opsudance.core.inject.InstanceContainer;
public class Option { public class Option {
// keep a reference to the instancecontainer so that not every option instance needs to be injected
protected static InstanceContainer instanceContainer;
// caching some commonly used classes
protected static Configuration config;
protected static DisplayContainer displayContainer;
public static void setInstanceContainer(InstanceContainer instanceContainer) {
Option.instanceContainer = instanceContainer;
Option.config = instanceContainer.provide(Configuration.class);
Option.displayContainer = instanceContainer.provide(DisplayContainer.class);
}
public final String name; public final String name;
public final String configurationName; public final String configurationName;
public final String description; public final String description;
@ -54,7 +42,7 @@ public class Option {
this.name = name; this.name = name;
this.configurationName = configurationName; this.configurationName = configurationName;
this.description = description; this.description = description;
OptionsService.registerOption(this); optionservice.registerOption(this);
} }
/** /**

View File

@ -29,40 +29,23 @@ import org.newdawn.slick.openal.SoundStore;
import org.newdawn.slick.util.Log; import org.newdawn.slick.util.Log;
import yugecin.opsudance.*; import yugecin.opsudance.*;
import yugecin.opsudance.core.events.EventBus; import yugecin.opsudance.core.events.EventBus;
import yugecin.opsudance.core.events.EventListener;
import yugecin.opsudance.events.BarNotificationEvent; import yugecin.opsudance.events.BarNotificationEvent;
import yugecin.opsudance.events.ResolutionOrSkinChangedEvent;
import yugecin.opsudance.movers.factories.ExgonMoverFactory; import yugecin.opsudance.movers.factories.ExgonMoverFactory;
import yugecin.opsudance.movers.factories.QuadraticBezierMoverFactory; import yugecin.opsudance.movers.factories.QuadraticBezierMoverFactory;
import yugecin.opsudance.movers.slidermovers.DefaultSliderMoverController; import yugecin.opsudance.movers.slidermovers.DefaultSliderMoverController;
import yugecin.opsudance.skinning.SkinService;
import yugecin.opsudance.utils.CachedVariable; import yugecin.opsudance.utils.CachedVariable;
import yugecin.opsudance.utils.CachedVariable.Getter; import yugecin.opsudance.utils.CachedVariable.Getter;
import java.io.File; import java.io.File;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static yugecin.opsudance.core.InstanceContainer.*;
/** /**
* @author itdelatrisu (https://github.com/itdelatrisu) most functions are copied from itdelatrisu.opsu.Options.java * @author itdelatrisu (https://github.com/itdelatrisu) most functions are copied from itdelatrisu.opsu.Options.java
*/ */
public class Options { public class Options {
// TODO remove this?
public static int width;
public static int height;
static {
EventBus.subscribe(ResolutionOrSkinChangedEvent.class, new EventListener<ResolutionOrSkinChangedEvent>() {
@Override
public void onEvent(ResolutionOrSkinChangedEvent event) {
if (event.width > 0) {
width = event.width;
height = event.height;
}
}
});
}
// internal options (not displayed in-game) // internal options (not displayed in-game)
public static final Option OPTION_BEATMAP_DIRECTORY = new Option("BeatmapDirectory") { public static final Option OPTION_BEATMAP_DIRECTORY = new Option("BeatmapDirectory") {
@Override @Override
@ -204,37 +187,31 @@ public class Options {
public static final ToggleOption OPTION_ALLOW_LARGER_RESOLUTIONS = new ToggleOption("Allow large resolutions", "AllowLargeRes", "Allow resolutions larger than the native resolution", false); public static final ToggleOption OPTION_ALLOW_LARGER_RESOLUTIONS = new ToggleOption("Allow large resolutions", "AllowLargeRes", "Allow resolutions larger than the native resolution", false);
public static final ToggleOption OPTION_FULLSCREEN = new ToggleOption("Fullscreen Mode", "Fullscreen", "Restart to apply changes.", false); public static final ToggleOption OPTION_FULLSCREEN = new ToggleOption("Fullscreen Mode", "Fullscreen", "Restart to apply changes.", false);
public static final ListOption OPTION_SKIN = new ListOption("Skin", "Skin", "Change how the game looks.") { public static final ListOption OPTION_SKIN = new ListOption("Skin", "Skin", "Change how the game looks.") {
private CachedVariable<SkinService> skinService = new CachedVariable<>(new Getter<SkinService>() {
@Override
public SkinService get() {
return instanceContainer.provide(SkinService.class);
}
});
@Override @Override
public String getValueString () { public String getValueString () {
return skinService.get().usedSkinName; return skinservice.usedSkinName;
} }
@Override @Override
public Object[] getListItems () { public Object[] getListItems () {
return skinService.get().availableSkinDirectories; return skinservice.availableSkinDirectories;
} }
@Override @Override
public void clickListItem(int index){ public void clickListItem(int index){
skinService.get().usedSkinName = skinService.get().availableSkinDirectories[index]; skinservice.usedSkinName = skinservice.availableSkinDirectories[index];
skinService.get().reloadSkin(); skinservice.reloadSkin();
} }
@Override @Override
public void read (String s){ public void read (String s){
skinService.get().usedSkinName = s; skinservice.usedSkinName = s;
} }
@Override @Override
public String write() { public String write() {
return skinService.get().usedSkinName; return skinservice.usedSkinName;
} }
}; };

View File

@ -19,8 +19,6 @@ package yugecin.opsudance.options;
import org.newdawn.slick.util.Log; import org.newdawn.slick.util.Log;
import yugecin.opsudance.core.events.EventBus; import yugecin.opsudance.core.events.EventBus;
import yugecin.opsudance.core.inject.Inject;
import yugecin.opsudance.core.inject.InstanceContainer;
import yugecin.opsudance.events.BubbleNotificationEvent; import yugecin.opsudance.events.BubbleNotificationEvent;
import java.io.*; import java.io.*;
@ -28,22 +26,21 @@ import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import static yugecin.opsudance.core.InstanceContainer.*;
/** /**
* @author itdelatrisu (https://github.com/itdelatrisu) most functions are copied from itdelatrisu.opsu.Options.java * @author itdelatrisu (https://github.com/itdelatrisu)
* most functions are copied from itdelatrisu.opsu.Options.java
*/ */
public class OptionsService { public class OptionsService {
@Inject public final HashMap<String, Option> optionMap;
private Configuration config;
public static final HashMap<String, Option> optionMap = new HashMap<>(); public OptionsService() {
optionMap = new HashMap<>();
@Inject
public OptionsService(InstanceContainer instanceContainer) {
Option.setInstanceContainer(instanceContainer);
} }
public static void registerOption(Option option) { public void registerOption(Option option) {
optionMap.put(option.configurationName, option); optionMap.put(option.configurationName, option);
} }

View File

@ -26,33 +26,21 @@ import itdelatrisu.opsu.ui.Colors;
import itdelatrisu.opsu.ui.animations.AnimationEquation; import itdelatrisu.opsu.ui.animations.AnimationEquation;
import org.newdawn.slick.Color; import org.newdawn.slick.Color;
import org.newdawn.slick.Image; import org.newdawn.slick.Image;
import yugecin.opsudance.core.DisplayContainer;
import yugecin.opsudance.core.inject.Inject;
import yugecin.opsudance.skinning.SkinService; import yugecin.opsudance.skinning.SkinService;
import static yugecin.opsudance.options.Options.*; import static yugecin.opsudance.options.Options.*;
public class GameObjectRenderer { public class GameObjectRenderer {
@Inject public GameData gameData;
private DisplayContainer displayContainer;
private GameData gameData; public float circleDiameter;
public int circleDiameterInt;
private float circleDiameter;
private int circleDiameterInt;
private Image hitcircle; private Image hitcircle;
private Image hitcircleOverlay; private Image hitcircleOverlay;
private Image approachCircle; private Image approachCircle;
@Deprecated
public static GameObjectRenderer instance;
public GameObjectRenderer() {
instance = this; // TODO get rid of this
}
public void initForGame(GameData gameData, float circleDiameter) { public void initForGame(GameData gameData, float circleDiameter) {
this.gameData = gameData; this.gameData = gameData;
this.circleDiameter = circleDiameter * HitObject.getXMultiplier(); // convert from Osupixels (640x480) this.circleDiameter = circleDiameter * HitObject.getXMultiplier(); // convert from Osupixels (640x480)
@ -65,14 +53,6 @@ public class GameObjectRenderer {
approachCircle = GameImage.APPROACHCIRCLE.getImage(); approachCircle = GameImage.APPROACHCIRCLE.getImage();
} }
public float getCircleDiameter() {
return circleDiameter;
}
public void setGameData(GameData gameData) {
this.gameData = gameData;
}
public void initForFrame() { public void initForFrame() {
if (!OPTION_DANCING_CIRCLES.state) { if (!OPTION_DANCING_CIRCLES.state) {
return; return;

View File

@ -24,28 +24,20 @@ import org.newdawn.slick.util.ClasspathLocation;
import org.newdawn.slick.util.FileSystemLocation; import org.newdawn.slick.util.FileSystemLocation;
import org.newdawn.slick.util.ResourceLoader; import org.newdawn.slick.util.ResourceLoader;
import yugecin.opsudance.core.events.EventBus; import yugecin.opsudance.core.events.EventBus;
import yugecin.opsudance.core.inject.Inject;
import yugecin.opsudance.events.ResolutionOrSkinChangedEvent; import yugecin.opsudance.events.ResolutionOrSkinChangedEvent;
import yugecin.opsudance.options.Configuration;
import java.io.File; import java.io.File;
import static yugecin.opsudance.core.InstanceContainer.*;
/** /**
* @author itdelatrisu (https://github.com/itdelatrisu) most functions are copied from itdelatrisu.opsu.Options.java * @author itdelatrisu (https://github.com/itdelatrisu) most functions are copied from itdelatrisu.opsu.Options.java
*/ */
public class SkinService { public class SkinService {
@Inject
private Configuration config;
public String[] availableSkinDirectories; public String[] availableSkinDirectories;
public String usedSkinName = "Default"; public String usedSkinName = "Default";
public static Skin skin; public static Skin skin;
@Inject
public SkinService() {
}
public void reloadSkin() { public void reloadSkin() {
loadSkin(); loadSkin();
SoundController.init(); SoundController.init();

View File

@ -17,7 +17,7 @@
*/ */
package yugecin.opsudance.spinners; package yugecin.opsudance.spinners;
import yugecin.opsudance.options.Options; import static yugecin.opsudance.core.InstanceContainer.*;
public class ApproachCircleSpinner extends Spinner { public class ApproachCircleSpinner extends Spinner {
@ -38,10 +38,10 @@ public class ApproachCircleSpinner extends Spinner {
ang += 15; ang += 15;
} }
double rad = Options.width / 4.0f * (1d - Spinner.PROGRESS); double rad = displayContainer.width / 4.0f * (1d - Spinner.PROGRESS);
point[0] = Options.width / 2.0f + rad * Math.sin(ang / 180d * Math.PI); point[0] = displayContainer.width / 2.0f + rad * Math.sin(ang / 180d * Math.PI);
point[1] = Options.height / 2.0f - rad * Math.cos(ang / 180d * Math.PI); point[1] = displayContainer.height / 2.0f - rad * Math.cos(ang / 180d * Math.PI);
return point; return point;
} }

View File

@ -17,7 +17,7 @@
*/ */
package yugecin.opsudance.spinners; package yugecin.opsudance.spinners;
import yugecin.opsudance.options.Options; import static yugecin.opsudance.core.InstanceContainer.*;
public class BeamSpinner extends Spinner { public class BeamSpinner extends Spinner {
@ -26,16 +26,14 @@ public class BeamSpinner extends Spinner {
private int index; private int index;
@Override @Override
public void init() public void init() {
{
ang = 0; ang = 0;
index = 0; index = 0;
point = new double[2]; point = new double[2];
} }
@Override @Override
public double[] getPoint() public double[] getPoint() {
{
if (!waitForDelay()) { if (!waitForDelay()) {
return point; return point;
} }
@ -43,26 +41,19 @@ public class BeamSpinner extends Spinner {
index = ++index % 4; index = ++index % 4;
final int MOD = 60; final int MOD = 60;
point[0] = Options.width / 2d; point[0] = displayContainer.width / 2d;
point[1] = Options.height / 2d; point[1] = displayContainer.height / 2d;
if( index == 0 ) if( index == 0 ) {
{
add( MOD, 90 ); add( MOD, 90 );
add( MOD, 180 ); add( MOD, 180 );
} } else if( index == 1 ) {
else if( index == 1 )
{
add( MOD, 90 ); add( MOD, 90 );
add( Options.height / 2 * 0.8d, 0 ); add( displayContainer.height / 2 * 0.8d, 0 );
} } else if( index == 2 ) {
else if( index == 2 )
{
add( MOD, -90 ); add( MOD, -90 );
add( Options.height / 2 * 0.8d, 0 ); add( displayContainer.height / 2 * 0.8d, 0 );
} } else if( index == 3 ) {
else if( index == 3 )
{
add( MOD, -90 ); add( MOD, -90 );
add( MOD, 180 ); add( MOD, 180 );
ang += 0.3; ang += 0.3;
@ -71,8 +62,7 @@ public class BeamSpinner extends Spinner {
return point; return point;
} }
private void add( double rad, double ang ) private void add( double rad, double ang ) {
{
point[0] += rad * Math.cos( (this.ang + ang) / 180d * Math.PI); point[0] += rad * Math.cos( (this.ang + ang) / 180d * Math.PI);
point[1] -= rad * Math.sin( (this.ang + ang) / 180d * Math.PI); point[1] -= rad * Math.sin( (this.ang + ang) / 180d * Math.PI);
} }

View File

@ -17,7 +17,7 @@
*/ */
package yugecin.opsudance.spinners; package yugecin.opsudance.spinners;
import yugecin.opsudance.options.Options; import static yugecin.opsudance.core.InstanceContainer.*;
public class CircleSpinner extends Spinner { public class CircleSpinner extends Spinner {
@ -26,22 +26,20 @@ public class CircleSpinner extends Spinner {
private double[] point = new double[2]; private double[] point = new double[2];
@Override @Override
public void init() public void init() {
{
ang = 0; ang = 0;
} }
@Override @Override
public double[] getPoint() public double[] getPoint() {
{
if (waitForDelay()) { if (waitForDelay()) {
ang += 15; ang += 15;
} }
double rad = Options.width / 4.0f; double rad = displayContainer.width / 4.0f;
point[0] = Options.width / 2.0f + rad * Math.sin(ang / 180d * Math.PI); point[0] = displayContainer.width / 2.0f + rad * Math.sin(ang / 180d * Math.PI);
point[1] = Options.height / 2.0f - rad * Math.cos(ang / 180d * Math.PI); point[1] = displayContainer.height / 2.0f - rad * Math.cos(ang / 180d * Math.PI);
return point; return point;
} }

View File

@ -17,7 +17,7 @@
*/ */
package yugecin.opsudance.spinners; package yugecin.opsudance.spinners;
import yugecin.opsudance.options.Options; import static yugecin.opsudance.core.InstanceContainer.displayContainer;
public class CubeSpinner extends Spinner { public class CubeSpinner extends Spinner {
@ -90,10 +90,10 @@ public class CubeSpinner extends Spinner {
x *= 3.0d / ( z + 3.0d + 5.0d + 0.5 ); x *= 3.0d / ( z + 3.0d + 5.0d + 0.5 );
y *= 3.0d / ( z + 3.0d + 5.0d + 0.5 ); y *= 3.0d / ( z + 3.0d + 5.0d + 0.5 );
double scale = Options.width / (3.0f + 0.5f * Math.cos(size / 180f * Math.PI)); double scale = displayContainer.width / (3.0f + 0.5f * Math.cos(size / 180f * Math.PI));
//double scale = Options.width / (3.0f + -1f * ((float)(Options.s.ElapsedMilliseconds % Options.beatTimeMs)/(float)Options.beatTimeMs)); //double scale = Options.width / (3.0f + -1f * ((float)(Options.s.ElapsedMilliseconds % Options.beatTimeMs)/(float)Options.beatTimeMs));
point[0] = (int) ( Options.width / 2.0f + scale * x ); point[0] = (int) ( displayContainer.width / 2.0f + scale * x );
point[1] = (int) ( Options.height / 2.0f - scale * y ); point[1] = (int) ( displayContainer.height / 2.0f - scale * y );
return point; return point;
} }

View File

@ -17,7 +17,7 @@
*/ */
package yugecin.opsudance.spinners; package yugecin.opsudance.spinners;
import yugecin.opsudance.options.Options; import static yugecin.opsudance.core.InstanceContainer.*;
public class DonutSpinner extends Spinner { public class DonutSpinner extends Spinner {
@ -38,10 +38,10 @@ public class DonutSpinner extends Spinner {
ang += 15; ang += 15;
} }
double rad = Options.width / 4.0f; double rad = displayContainer.width / 4.0f;
point[0] = Options.width / 2.0f + rad * Math.sin(ang); point[0] = displayContainer.width / 2.0f + rad * Math.sin(ang);
point[1] = Options.height / 2.0f - rad * Math.cos(ang); point[1] = displayContainer.height / 2.0f - rad * Math.cos(ang);
return point; return point;
} }

View File

@ -17,7 +17,7 @@
*/ */
package yugecin.opsudance.spinners; package yugecin.opsudance.spinners;
import yugecin.opsudance.options.Options; import static yugecin.opsudance.core.InstanceContainer.*;
public class FivePointStarApproachSpinner extends Spinner { public class FivePointStarApproachSpinner extends Spinner {
@ -39,12 +39,12 @@ public class FivePointStarApproachSpinner extends Spinner {
odd = !odd; odd = !odd;
} }
double rad = Options.width / 4.0f * (1d - Spinner.PROGRESS); double rad = displayContainer.width / 4.0f * (1d - Spinner.PROGRESS);
if (!odd) { if (!odd) {
rad /= 3d; rad /= 3d;
} }
point[0] = Options.width / 2d + Math.cos(ang) * rad; point[0] = displayContainer.width / 2d + Math.cos(ang) * rad;
point[1] = Options.height / 2d + Math.sin(ang) * rad; point[1] = displayContainer.height / 2d + Math.sin(ang) * rad;
return point; return point;
} }

View File

@ -17,18 +17,18 @@
*/ */
package yugecin.opsudance.spinners; package yugecin.opsudance.spinners;
import yugecin.opsudance.options.Options; import static yugecin.opsudance.core.InstanceContainer.*;
public class FivePointStarSpinner extends Spinner { public class FivePointStarSpinner extends Spinner {
@Override @Override
public void init() { public void init() {
double[][] points = new double[10][]; double[][] points = new double[10][];
double midx = Options.width / 2d; double midx = displayContainer.width / 2d;
double midy = Options.height / 2d; double midy = displayContainer.height / 2d;
double angleIncRads = Math.PI * 36d / 180d; double angleIncRads = Math.PI * 36d / 180d;
double ang = -Math.PI / 2d; double ang = -Math.PI / 2d;
double maxrad = Options.width / 4d; double maxrad = displayContainer.width / 4d;
double minrad = maxrad / 3d; double minrad = maxrad / 3d;
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
double rad = maxrad; double rad = maxrad;

View File

@ -19,6 +19,8 @@ package yugecin.opsudance.spinners;
import yugecin.opsudance.options.Options; import yugecin.opsudance.options.Options;
import static yugecin.opsudance.core.InstanceContainer.displayContainer;
public class HalfCircleSpinner extends Spinner { public class HalfCircleSpinner extends Spinner {
private int ang = 0; private int ang = 0;
@ -45,8 +47,8 @@ public class HalfCircleSpinner extends Spinner {
skipang += 359; skipang += 359;
} }
point[0] = Options.width / 2.0d + Options.height / 2 * 0.8d * Math.cos(ang/180d*Math.PI); point[0] = displayContainer.width / 2.0d + displayContainer.height / 2 * 0.8d * Math.cos(ang/180d*Math.PI);
point[1] = Options.height / 2.0d + Options.height / 2 * 0.8d * Math.sin(ang/180d*Math.PI); point[1] = displayContainer.height / 2.0d + displayContainer.height / 2 * 0.8d * Math.sin(ang/180d*Math.PI);
return point; return point;
} }

View File

@ -17,17 +17,16 @@
*/ */
package yugecin.opsudance.spinners; package yugecin.opsudance.spinners;
import yugecin.opsudance.options.Options; import static yugecin.opsudance.core.InstanceContainer.*;
public class IlluminatiSpinner extends Spinner { public class IlluminatiSpinner extends Spinner {
@Override @Override
public void init() public void init() {
{
init( new double[][] { init( new double[][] {
new double[] { Options.width / 2d - 120, Options.height / 2d + 80 }, new double[] { displayContainer.width / 2d - 120, displayContainer.height / 2d + 80 },
new double[] { Options.width / 2d, Options.height / 2d - 160 }, new double[] { displayContainer.width / 2d, displayContainer.height / 2d - 160 },
new double[] { Options.width / 2d + 120, Options.height / 2d + 80 } new double[] { displayContainer.width / 2d + 120, displayContainer.height / 2d + 80 }
} ); } );
} }

View File

@ -17,7 +17,7 @@
*/ */
package yugecin.opsudance.spinners; package yugecin.opsudance.spinners;
import yugecin.opsudance.options.Options; import static yugecin.opsudance.core.InstanceContainer.*;
public class LessThanThreeSpinner extends Spinner { public class LessThanThreeSpinner extends Spinner {
@ -38,8 +38,8 @@ public class LessThanThreeSpinner extends Spinner {
if( angle > 360 ) angle = 0; if( angle > 360 ) angle = 0;
double theta = angle / 180d * Math.PI; double theta = angle / 180d * Math.PI;
double[] pos = new double[] { double[] pos = new double[] {
Options.width / 2d, displayContainer.width / 2d,
Options.height / 2d displayContainer.height / 2d
}; };
double r = 2 - 2 * Math.sin( theta ) + Math.sin( theta ) * Math.sqrt( Math.abs( Math.cos( theta ) ) ) / ( Math.sin( theta ) + 1.4 ); double r = 2 - 2 * Math.sin( theta ) + Math.sin( theta ) * Math.sqrt( Math.abs( Math.cos( theta ) ) ) / ( Math.sin( theta ) + 1.4 );

View File

@ -17,7 +17,7 @@
*/ */
package yugecin.opsudance.spinners; package yugecin.opsudance.spinners;
import yugecin.opsudance.options.Options; import static yugecin.opsudance.core.InstanceContainer.*;
public class RektCircleSpinner extends Spinner { public class RektCircleSpinner extends Spinner {
@ -25,51 +25,39 @@ public class RektCircleSpinner extends Spinner {
private int index; private int index;
private int pos; private int pos;
private double size; private double size;
private int delay = 0;
@Override @Override
public void init() public void init() {
{
index = 0; index = 0;
size = Options.height * 0.8d; size = displayContainer.height * 0.8d;
point = new double[2]; point = new double[2];
} }
@Override @Override
public double[] getPoint() public double[] getPoint() {
{
if (!waitForDelay()) { if (!waitForDelay()) {
return point; return point;
} }
delay = 0;
final int INC = 50; final int INC = 50;
if( index == 0 ) if( index == 0 ) {
{ point[0] = displayContainer.width / 2d + size / 2d - pos;
point[0] = Options.width / 2d + size / 2d - pos; point[1] = displayContainer.height / 2d - size / 2d;
point[1] = Options.height / 2d - size / 2d;
index++; index++;
} } else if( index == 1 ) {
else if( index == 1 ) point[0] = displayContainer.width / 2 - size / 2;
{ point[1] = displayContainer.height / 2 - size / 2 + pos;
point[0] = Options.width / 2 - size / 2;
point[1] = Options.height / 2 - size / 2 + pos;
index++; index++;
} } else if( index == 2 ) {
else if( index == 2 ) point[0] = displayContainer.width / 2 - size / 2 + pos;
{ point[1] = displayContainer.height / 2 + size / 2;
point[0] = Options.width / 2 - size / 2 + pos;
point[1] = Options.height / 2 + size / 2;
index++; index++;
} } else if( index == 3 ) {
else if( index == 3 ) point[0] = displayContainer.width / 2 + size / 2;
{ point[1] = displayContainer.height / 2 + size / 2 - pos;
point[0] = Options.width / 2 + size / 2;
point[1] = Options.height / 2 + size / 2 - pos;
pos += INC; pos += INC;
if( pos > size ) if( pos > size ) {
{
pos = INC; pos = INC;
} }
index = 0; index = 0;

View File

@ -17,7 +17,7 @@
*/ */
package yugecin.opsudance.spinners; package yugecin.opsudance.spinners;
import yugecin.opsudance.options.Options; import static yugecin.opsudance.core.InstanceContainer.*;
public class RektSpinner extends Spinner { public class RektSpinner extends Spinner {
@ -25,11 +25,11 @@ public class RektSpinner extends Spinner {
public void init() { public void init() {
init(new double[][] { init(new double[][] {
{ 10, 10 }, { 10, 10 },
{ Options.width / 2d, 10 }, { displayContainer.width / 2d, 10 },
{ Options.width - 10, 10 }, { displayContainer.width - 10, 10 },
{ Options.width - 10, Options.height - 10 }, { displayContainer.width - 10, displayContainer.height - 10 },
{ Options.width / 2d, Options.height - 10 }, { displayContainer.width / 2d, displayContainer.height - 10 },
{ 10, Options.height - 10 } { 10, displayContainer.height - 10 }
}); });
} }

View File

@ -19,7 +19,7 @@ package yugecin.opsudance.utils;
import org.newdawn.slick.util.Log; import org.newdawn.slick.util.Log;
import org.newdawn.slick.util.ResourceLoader; import org.newdawn.slick.util.ResourceLoader;
import yugecin.opsudance.options.Configuration; import yugecin.opsudance.core.Constants;
import java.io.IOException; import java.io.IOException;
import java.util.Properties; import java.util.Properties;
@ -31,7 +31,7 @@ public class MiscUtils {
public Properties get() { public Properties get() {
Properties props = new Properties(); Properties props = new Properties();
try { try {
props.load(ResourceLoader.getResourceAsStream(Configuration.instance.VERSION_FILE)); props.load(ResourceLoader.getResourceAsStream(Constants.VERSION_FILE));
} catch (IOException e) { } catch (IOException e) {
Log.error("Could not read version file", e); Log.error("Could not read version file", e);
} }