aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-08-14 12:24:38 +0200
committerGitHub <noreply@github.com>2022-08-14 17:24:38 +0700
commite18629af6aee276b0be6cec473e4099cca9100f1 (patch)
tree39fc264f55b0db96d8794d0a59a4fd19bb53b5db /src/main
parent67a78a550c9d87715b834b4615662cc2d9e65bed (diff)
downloadOneConfig-e18629af6aee276b0be6cec473e4099cca9100f1.tar.gz
OneConfig-e18629af6aee276b0be6cec473e4099cca9100f1.tar.bz2
OneConfig-e18629af6aee276b0be6cec473e4099cca9100f1.zip
fix: fix profile init (#92)
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/Config.java17
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/core/ConfigUtils.java22
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java1
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/config/profiles/Profiles.java5
4 files changed, 35 insertions, 10 deletions
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);
}