diff options
5 files changed, 40 insertions, 10 deletions
diff --git a/api/OneConfig.api b/api/OneConfig.api index b8a8849..751ba76 100644 --- a/api/OneConfig.api +++ b/api/OneConfig.api @@ -151,8 +151,13 @@ public class cc/polyfrost/oneconfig/config/core/ConfigUtils { public static fun findAnnotation (Ljava/lang/reflect/Method;Ljava/lang/Class;)Ljava/lang/annotation/Annotation; public static fun getClassFields (Ljava/lang/Class;)Ljava/util/ArrayList; public static fun getClassOptions (Ljava/lang/Object;)Ljava/util/ArrayList; + public static fun getCurrentProfile ()Ljava/lang/String; public static fun getField (Ljava/lang/reflect/Field;Ljava/lang/Object;)Ljava/lang/Object; + public static fun getNonProfileSpecificFile (Ljava/lang/String;)Ljava/io/File; + public static fun getNonSpecificProfileDir ()Ljava/io/File; public static fun getOption (Lcc/polyfrost/oneconfig/internal/config/annotations/Option;Ljava/lang/reflect/Field;Ljava/lang/Object;)Lcc/polyfrost/oneconfig/config/elements/BasicOption; + public static fun getProfileDir ()Ljava/io/File; + public static fun getProfileFile (Ljava/lang/String;)Ljava/io/File; public static fun getSubCategory (Lcc/polyfrost/oneconfig/config/elements/OptionPage;Ljava/lang/String;Ljava/lang/String;)Lcc/polyfrost/oneconfig/config/elements/OptionSubcategory; public static fun setField (Ljava/lang/reflect/Field;Ljava/lang/Object;Ljava/lang/Object;)V } diff --git a/src/main/java/cc/polyfrost/oneconfig/config/Config.java b/src/main/java/cc/polyfrost/oneconfig/config/Config.java index 7c3b7ed..eb74d2a 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/Config.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/Config.java @@ -37,7 +37,6 @@ import cc.polyfrost.oneconfig.config.elements.OptionSubcategory; import cc.polyfrost.oneconfig.config.gson.NonProfileSpecificExclusionStrategy; import cc.polyfrost.oneconfig.config.gson.ProfileExclusionStrategy; import cc.polyfrost.oneconfig.gui.elements.config.ConfigKeyBind; -import cc.polyfrost.oneconfig.internal.config.profiles.Profiles; import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.gui.elements.config.ConfigPageButton; import cc.polyfrost.oneconfig.gui.pages.ModConfigPage; @@ -91,7 +90,7 @@ public class Config { public void initialize() { boolean migrate = false; - if (Profiles.getProfileFile(configFile).exists()) load(); + if (ConfigUtils.getProfileFile(configFile).exists()) load(); else if (mod.migrator != null) migrate = true; else save(); mod.config = this; @@ -101,7 +100,7 @@ public class Config { } public void reInitialize() { - if (Profiles.getProfileFile(configFile).exists()) load(); + if (ConfigUtils.getProfileFile(configFile).exists()) load(); else save(); } @@ -109,14 +108,14 @@ public class Config { * Save current config to file */ public void save() { - Profiles.getProfileFile(configFile).getParentFile().mkdirs(); - Profiles.getNonProfileSpecificDir(configFile).getParentFile().mkdirs(); - try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(Profiles.getProfileFile(configFile).toPath()), StandardCharsets.UTF_8))) { + ConfigUtils.getProfileFile(configFile).getParentFile().mkdirs(); + ConfigUtils.getNonProfileSpecificFile(configFile).getParentFile().mkdirs(); + try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(ConfigUtils.getProfileFile(configFile).toPath()), StandardCharsets.UTF_8))) { writer.write(gson.toJson(this)); } catch (Exception e) { e.printStackTrace(); } - try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(Profiles.getNonProfileSpecificDir(configFile).toPath()), StandardCharsets.UTF_8))) { + try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(ConfigUtils.getNonProfileSpecificFile(configFile).toPath()), StandardCharsets.UTF_8))) { writer.write(nonProfileSpecificGson.toJson(this)); } catch (Exception e) { e.printStackTrace(); @@ -127,12 +126,12 @@ public class Config { * Load file and overwrite current values */ public void load() { - try (BufferedReader reader = new BufferedReader(new InputStreamReader(Files.newInputStream(Profiles.getProfileFile(configFile).toPath()), StandardCharsets.UTF_8))) { + try (BufferedReader reader = new BufferedReader(new InputStreamReader(Files.newInputStream(ConfigUtils.getProfileFile(configFile).toPath()), StandardCharsets.UTF_8))) { deserializePart(JsonUtils.PARSER.parse(reader).getAsJsonObject(), this); } catch (Exception e) { e.printStackTrace(); } - try (BufferedReader reader = new BufferedReader(new InputStreamReader(Files.newInputStream(Profiles.getNonProfileSpecificDir(configFile).toPath()), StandardCharsets.UTF_8))) { + try (BufferedReader reader = new BufferedReader(new InputStreamReader(Files.newInputStream(ConfigUtils.getNonProfileSpecificFile(configFile).toPath()), StandardCharsets.UTF_8))) { deserializePart(JsonUtils.PARSER.parse(reader).getAsJsonObject(), this); } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigUtils.java b/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigUtils.java index 69235f8..e050899 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigUtils.java @@ -35,9 +35,11 @@ import cc.polyfrost.oneconfig.config.elements.OptionSubcategory; import cc.polyfrost.oneconfig.config.migration.Migrator; import cc.polyfrost.oneconfig.gui.elements.config.*; import cc.polyfrost.oneconfig.internal.config.annotations.Option; +import cc.polyfrost.oneconfig.internal.config.profiles.Profiles; import com.google.gson.FieldAttributes; import org.jetbrains.annotations.Nullable; +import java.io.File; import java.lang.annotation.Annotation; import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -187,4 +189,24 @@ public class ConfigUtils { } catch (Exception ignored) { } } + + public static String getCurrentProfile() { + return Profiles.getCurrentProfile(); + } + + public static File getProfileDir() { + return Profiles.getProfileDir(); + } + + public static File getNonSpecificProfileDir() { + return Profiles.nonProfileSpecificDir; + } + + public static File getProfileFile(String file) { + return Profiles.getProfileFile(file); + } + + public static File getNonProfileSpecificFile(String file) { + return Profiles.getNonProfileSpecificFile(file); + } } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java index dd802b5..ba04aff 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java @@ -101,6 +101,7 @@ public class OneConfigGui extends UScreen implements GuiPause { scale = Preferences.enableCustomScale ? Preferences.customScale : Math.min(UResolution.getWindowWidth() / 1920f, UResolution.getWindowHeight() / 1080f); if (scale < 1 && !Preferences.enableCustomScale) scale = Math.min(Math.min(1f, UResolution.getWindowWidth() / 1280f), Math.min(1f, UResolution.getWindowHeight() / 800f)); + scale = (float) (Math.floor(scale / 0.05f) * 0.05f); int x = (int) ((UResolution.getWindowWidth() - 1280 * scale) / 2f / scale); int y = (int) ((UResolution.getWindowHeight() - 800 * scale) / 2f / scale); RenderManager.scale(vg, scale, scale); diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/config/profiles/Profiles.java b/src/main/java/cc/polyfrost/oneconfig/internal/config/profiles/Profiles.java index baa5d48..6a52d16 100644 --- a/src/main/java/cc/polyfrost/oneconfig/internal/config/profiles/Profiles.java +++ b/src/main/java/cc/polyfrost/oneconfig/internal/config/profiles/Profiles.java @@ -45,6 +45,9 @@ public class Profiles { private static ArrayList<String> profiles; public static String getCurrentProfile() { + if (OneConfigConfig.getInstance() == null) { + OneConfigConfig.getInstance(); + } if (!profileDir.exists() && !profileDir.mkdir()) { LOGGER.fatal("Could not create profiles folder"); return null; @@ -80,7 +83,7 @@ public class Profiles { return new File(getProfileDir(), file); } - public static File getNonProfileSpecificDir(String file) { + public static File getNonProfileSpecificFile(String file) { return new File(nonProfileSpecificDir, file); } |