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:
@@ -20,7 +20,6 @@ package yugecin.opsudance.options;
|
||||
import com.sun.jna.platform.win32.Advapi32Util;
|
||||
import com.sun.jna.platform.win32.Win32Exception;
|
||||
import com.sun.jna.platform.win32.WinReg;
|
||||
import itdelatrisu.opsu.Utils;
|
||||
import itdelatrisu.opsu.audio.SoundController;
|
||||
import itdelatrisu.opsu.audio.SoundEffect;
|
||||
import itdelatrisu.opsu.beatmap.Beatmap;
|
||||
@@ -30,31 +29,26 @@ import org.lwjgl.opengl.Display;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import yugecin.opsudance.core.errorhandling.ErrorHandler;
|
||||
import yugecin.opsudance.core.events.EventBus;
|
||||
import yugecin.opsudance.core.inject.Inject;
|
||||
import yugecin.opsudance.events.BubbleNotificationEvent;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.file.Paths;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.jar.Manifest;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static yugecin.opsudance.options.Options.*;
|
||||
import static yugecin.opsudance.core.InstanceContainer.*;
|
||||
|
||||
public class Configuration {
|
||||
|
||||
public static Configuration instance;
|
||||
|
||||
public final boolean USE_XDG;
|
||||
public final File CONFIG_DIR;
|
||||
public final File DATA_DIR;
|
||||
@@ -69,13 +63,6 @@ public class Configuration {
|
||||
public final File LOG_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 Beatmap themeBeatmap;
|
||||
@@ -87,10 +74,7 @@ public class Configuration {
|
||||
public File replayImportDir;
|
||||
public File skinRootDir;
|
||||
|
||||
@Inject
|
||||
public Configuration() {
|
||||
instance = this;
|
||||
|
||||
USE_XDG = areXDGDirectoriesEnabled();
|
||||
|
||||
CONFIG_DIR = getXDGBaseDir("XDG_CONFIG_HOME", ".config");
|
||||
@@ -107,13 +91,6 @@ public class Configuration {
|
||||
LOG_FILE = new File(CONFIG_DIR, ".opsu.log");
|
||||
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();
|
||||
|
||||
themeBeatmap = createThemeBeatmap();
|
||||
@@ -200,12 +177,11 @@ public class Configuration {
|
||||
}
|
||||
|
||||
private boolean areXDGDirectoriesEnabled() {
|
||||
JarFile jarFile = Utils.getJarFile();
|
||||
if (jarFile == null) {
|
||||
if (env.jarfile == null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
Manifest manifest = jarFile.getManifest();
|
||||
Manifest manifest = env.jarfile.getManifest();
|
||||
if (manifest == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -220,28 +196,21 @@ public class Configuration {
|
||||
/**
|
||||
* Returns the directory based on the XDG base directory specification for
|
||||
* 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
|
||||
* @return the XDG base directory, or the working directory if unavailable
|
||||
*/
|
||||
private File getXDGBaseDir(String env, String fallback) {
|
||||
File workingdir;
|
||||
if (Utils.isJarRunning()) {
|
||||
workingdir = Utils.getRunningDirectory().getParentFile();
|
||||
} else {
|
||||
workingdir = Paths.get(".").toAbsolutePath().normalize().toFile();
|
||||
}
|
||||
|
||||
private File getXDGBaseDir(String envvar, String fallback) {
|
||||
if (!USE_XDG) {
|
||||
return workingdir;
|
||||
return env.workingdir;
|
||||
}
|
||||
|
||||
String OS = System.getProperty("os.name").toLowerCase();
|
||||
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) {
|
||||
String home = System.getProperty("user.home");
|
||||
if (home == null) {
|
||||
|
||||
@@ -17,22 +17,10 @@
|
||||
*/
|
||||
package yugecin.opsudance.options;
|
||||
|
||||
import yugecin.opsudance.core.DisplayContainer;
|
||||
import yugecin.opsudance.core.inject.InstanceContainer;
|
||||
import static yugecin.opsudance.core.InstanceContainer.*;
|
||||
|
||||
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 configurationName;
|
||||
public final String description;
|
||||
@@ -54,7 +42,7 @@ public class Option {
|
||||
this.name = name;
|
||||
this.configurationName = configurationName;
|
||||
this.description = description;
|
||||
OptionsService.registerOption(this);
|
||||
optionservice.registerOption(this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,40 +29,23 @@ import org.newdawn.slick.openal.SoundStore;
|
||||
import org.newdawn.slick.util.Log;
|
||||
import yugecin.opsudance.*;
|
||||
import yugecin.opsudance.core.events.EventBus;
|
||||
import yugecin.opsudance.core.events.EventListener;
|
||||
import yugecin.opsudance.events.BarNotificationEvent;
|
||||
import yugecin.opsudance.events.ResolutionOrSkinChangedEvent;
|
||||
import yugecin.opsudance.movers.factories.ExgonMoverFactory;
|
||||
import yugecin.opsudance.movers.factories.QuadraticBezierMoverFactory;
|
||||
import yugecin.opsudance.movers.slidermovers.DefaultSliderMoverController;
|
||||
import yugecin.opsudance.skinning.SkinService;
|
||||
import yugecin.opsudance.utils.CachedVariable;
|
||||
import yugecin.opsudance.utils.CachedVariable.Getter;
|
||||
|
||||
import java.io.File;
|
||||
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
|
||||
*/
|
||||
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)
|
||||
public static final Option OPTION_BEATMAP_DIRECTORY = new Option("BeatmapDirectory") {
|
||||
@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_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.") {
|
||||
private CachedVariable<SkinService> skinService = new CachedVariable<>(new Getter<SkinService>() {
|
||||
@Override
|
||||
public SkinService get() {
|
||||
return instanceContainer.provide(SkinService.class);
|
||||
}
|
||||
});
|
||||
|
||||
@Override
|
||||
public String getValueString () {
|
||||
return skinService.get().usedSkinName;
|
||||
return skinservice.usedSkinName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getListItems () {
|
||||
return skinService.get().availableSkinDirectories;
|
||||
return skinservice.availableSkinDirectories;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clickListItem(int index){
|
||||
skinService.get().usedSkinName = skinService.get().availableSkinDirectories[index];
|
||||
skinService.get().reloadSkin();
|
||||
skinservice.usedSkinName = skinservice.availableSkinDirectories[index];
|
||||
skinservice.reloadSkin();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read (String s){
|
||||
skinService.get().usedSkinName = s;
|
||||
skinservice.usedSkinName = s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String write() {
|
||||
return skinService.get().usedSkinName;
|
||||
return skinservice.usedSkinName;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -19,8 +19,6 @@ package yugecin.opsudance.options;
|
||||
|
||||
import org.newdawn.slick.util.Log;
|
||||
import yugecin.opsudance.core.events.EventBus;
|
||||
import yugecin.opsudance.core.inject.Inject;
|
||||
import yugecin.opsudance.core.inject.InstanceContainer;
|
||||
import yugecin.opsudance.events.BubbleNotificationEvent;
|
||||
|
||||
import java.io.*;
|
||||
@@ -28,22 +26,21 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
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 {
|
||||
|
||||
@Inject
|
||||
private Configuration config;
|
||||
public final HashMap<String, Option> optionMap;
|
||||
|
||||
public static final HashMap<String, Option> optionMap = new HashMap<>();
|
||||
|
||||
@Inject
|
||||
public OptionsService(InstanceContainer instanceContainer) {
|
||||
Option.setInstanceContainer(instanceContainer);
|
||||
public OptionsService() {
|
||||
optionMap = new HashMap<>();
|
||||
}
|
||||
|
||||
public static void registerOption(Option option) {
|
||||
public void registerOption(Option option) {
|
||||
optionMap.put(option.configurationName, option);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user