From afd88470d801a9fd20432d65ec822ba2909309cd Mon Sep 17 00:00:00 2001 From: coolGi Date: Sun, 18 Sep 2022 15:31:07 +0930 Subject: [PATCH] Added some api notes and moved JarMain to the jar folder --- .../config/client/IDhApiGraphicsConfig.java | 1 - .../client/IDhApiGraphicsFogConfig.java | 1 - .../core/config/file/ConfigFileHandling.java | 7 ++- .../config/file/ConfigTypeConverters.java | 10 +++- .../core/config/types/AbstractConfigType.java | 4 +- .../lod/core/config/types/ConfigCategory.java | 8 ++- .../lod/core/config/types/ConfigEntry.java | 50 ++++++------------- .../config/types/ConfigEntryAppearance.java | 6 +++ .../config/types/ConfigEntryPerformance.java | 1 + .../core/config/types/ConfigUIComment.java | 2 +- .../seibel/lod/core/jar/DarkModeDetector.java | 2 +- .../seibel/lod/core/{ => jar}/JarMain.java | 4 +- .../com/seibel/lod/core/jar/JarUtils.java | 6 +++ .../seibel/lod/core/jar/gui/BaseJFrame.java | 1 + .../com/seibel/lod/core/jar/gui/JSwitch.java | 1 + .../lod/core/jar/gui/cusomJObject/JBox.java | 5 ++ .../lod/core/jar/installer/GitlabGetter.java | 4 +- .../lod/core/jar/installer/WebDownloader.java | 4 +- 18 files changed, 66 insertions(+), 51 deletions(-) rename core/src/main/java/com/seibel/lod/core/{ => jar}/JarMain.java (98%) diff --git a/api/src/main/java/com/seibel/lod/api/interfaces/config/client/IDhApiGraphicsConfig.java b/api/src/main/java/com/seibel/lod/api/interfaces/config/client/IDhApiGraphicsConfig.java index 52b746ff7..a8cb99fa5 100644 --- a/api/src/main/java/com/seibel/lod/api/interfaces/config/client/IDhApiGraphicsConfig.java +++ b/api/src/main/java/com/seibel/lod/api/interfaces/config/client/IDhApiGraphicsConfig.java @@ -22,7 +22,6 @@ package com.seibel.lod.api.interfaces.config.client; import com.seibel.lod.api.enums.config.*; import com.seibel.lod.api.enums.rendering.ERendererMode; import com.seibel.lod.api.interfaces.config.IDhApiConfigValue; -import com.seibel.lod.api.items.enums.config.*; import com.seibel.lod.api.interfaces.config.IDhApiConfigGroup; /** diff --git a/api/src/main/java/com/seibel/lod/api/interfaces/config/client/IDhApiGraphicsFogConfig.java b/api/src/main/java/com/seibel/lod/api/interfaces/config/client/IDhApiGraphicsFogConfig.java index 3802a617b..37035826d 100644 --- a/api/src/main/java/com/seibel/lod/api/interfaces/config/client/IDhApiGraphicsFogConfig.java +++ b/api/src/main/java/com/seibel/lod/api/interfaces/config/client/IDhApiGraphicsFogConfig.java @@ -22,7 +22,6 @@ package com.seibel.lod.api.interfaces.config.client; import com.seibel.lod.api.enums.rendering.*; import com.seibel.lod.api.interfaces.config.IDhApiConfigGroup; import com.seibel.lod.api.interfaces.config.IDhApiConfigValue; -import com.seibel.lod.api.items.enums.rendering.*; /** * Distant Horizons' fog configuration.

diff --git a/core/src/main/java/com/seibel/lod/core/config/file/ConfigFileHandling.java b/core/src/main/java/com/seibel/lod/core/config/file/ConfigFileHandling.java index b56f4816d..4ad9ed329 100644 --- a/core/src/main/java/com/seibel/lod/core/config/file/ConfigFileHandling.java +++ b/core/src/main/java/com/seibel/lod/core/config/file/ConfigFileHandling.java @@ -31,7 +31,7 @@ public class ConfigFileHandling { .getInstallationDirectory().toPath().resolve("config").resolve(this.configBase.modName+".toml"); } - /** Saves the config to the file */ + /** Saves the entire config to the file */ public void saveToFile() { CommentedFileConfig config = CommentedFileConfig.builder(ConfigPath.toFile()).build(); if (!Files.exists(ConfigPath)) // Try to check if the config exists @@ -53,7 +53,10 @@ public class ConfigFileHandling { config.save(); config.close(); } - /** Loads the config from the file */ + /** + * Loads the entire config from the file + * @apiNote This overwrites any value currently stored in the config + */ public void loadFromFile() { CommentedFileConfig config = CommentedFileConfig.builder(ConfigPath.toFile()).build(); // Attempt to load the file and if it fails then save config to file diff --git a/core/src/main/java/com/seibel/lod/core/config/file/ConfigTypeConverters.java b/core/src/main/java/com/seibel/lod/core/config/file/ConfigTypeConverters.java index 874982fdf..4d2a4a1fe 100644 --- a/core/src/main/java/com/seibel/lod/core/config/file/ConfigTypeConverters.java +++ b/core/src/main/java/com/seibel/lod/core/config/file/ConfigTypeConverters.java @@ -7,6 +7,12 @@ import org.json.simple.parser.ParseException; import java.util.HashMap; import java.util.Map; +/** + * Allows for custom varuable types to be saved in the config + * (currently its only used for Map's) + * + * @author coolGi + */ public class ConfigTypeConverters { // Once you've made a converter add it to here where the first value is the type you want to convert and the 2nd value is the converter public static final Map convertObjects = new HashMap() {{ @@ -17,7 +23,7 @@ public class ConfigTypeConverters { try { return convertObjects.get(clazz).convertToString(value); } catch (Exception e) { - System.out.println("Type [" + clazz.toString() + "] isnt a convertible value in the config file handler"); + System.out.println("Type [" + clazz.toString() + "] isn't a convertible value in the config file handler"); return null; } } @@ -25,7 +31,7 @@ public class ConfigTypeConverters { try { return convertObjects.get(clazz).convertFromString(value); } catch (Exception e) { - System.out.println("Type [" + clazz.toString() + "] isnt a convertible value in the config file handler"); + System.out.println("Type [" + clazz.toString() + "] isn't a convertible value in the config file handler"); return null; } } diff --git a/core/src/main/java/com/seibel/lod/core/config/types/AbstractConfigType.java b/core/src/main/java/com/seibel/lod/core/config/types/AbstractConfigType.java index 17d0e1e3d..f81a655df 100644 --- a/core/src/main/java/com/seibel/lod/core/config/types/AbstractConfigType.java +++ b/core/src/main/java/com/seibel/lod/core/config/types/AbstractConfigType.java @@ -25,8 +25,10 @@ public abstract class AbstractConfigType { // The S is the class that is e } public interface Listener { + /** Called whenever the value changes at all (including in the code iself) */ void onModify(); -// void onUiModify(); // TODO + /** Called whenever the value is changed through the UI (only when the done button is pressed) */ + void onUiModify(); // TODO } diff --git a/core/src/main/java/com/seibel/lod/core/config/types/ConfigCategory.java b/core/src/main/java/com/seibel/lod/core/config/types/ConfigCategory.java index fabfc4a32..72a2111d1 100644 --- a/core/src/main/java/com/seibel/lod/core/config/types/ConfigCategory.java +++ b/core/src/main/java/com/seibel/lod/core/config/types/ConfigCategory.java @@ -1,7 +1,11 @@ package com.seibel.lod.core.config.types; -import com.seibel.lod.core.config.types.ConfigEntryAppearance; - +/** + * Adds a categoty to the config + * See our config file for more information on how to use it + * + * @author coolGi + */ public class ConfigCategory extends AbstractConfigType { public String destination; // Where the category goes to diff --git a/core/src/main/java/com/seibel/lod/core/config/types/ConfigEntry.java b/core/src/main/java/com/seibel/lod/core/config/types/ConfigEntry.java index 9fd3464e6..f572d11bd 100644 --- a/core/src/main/java/com/seibel/lod/core/config/types/ConfigEntry.java +++ b/core/src/main/java/com/seibel/lod/core/config/types/ConfigEntry.java @@ -5,6 +5,7 @@ import com.seibel.lod.core.interfaces.config.IConfigEntry; /** * Use for making the config variables + * for types that are not supported by it look in ConfigBase * * @author coolGi * @version 2022-5-26 @@ -29,14 +30,13 @@ public class ConfigEntry extends AbstractConfigType> implem /** Creates the entry */ - private ConfigEntry(ConfigEntryAppearance appearance, T value, String comment, T min, T max, boolean allowApiOverride, Runnable runnable, ConfigEntryPerformance performance, Listener listener) { + private ConfigEntry(ConfigEntryAppearance appearance, T value, String comment, T min, T max, boolean allowApiOverride, ConfigEntryPerformance performance, Listener listener) { super(appearance, value, listener); this.defaultValue = value; this.comment = comment; this.min = min; this.max = max; this.allowApiOverride = allowApiOverride; - this.runnable = runnable; this.performance = performance; } @@ -125,9 +125,9 @@ public class ConfigEntry extends AbstractConfigType> implem /** * Checks if the option is valid * - * 0 == valid - * 1 == number too high - * -1 == number too low + * @return 0 == valid + *

1 == number too high + *

-1 == number too low */ @Override public byte isValid() { @@ -139,9 +139,9 @@ public class ConfigEntry extends AbstractConfigType> implem if (this.configBase.disableMinMax) return 0; if (Number.class.isAssignableFrom(value.getClass())) { // Only check min max if it is a number - if (this.max != null && Double.valueOf(value.toString()) > Double.valueOf(max.toString())) + if (this.max != null && Double.parseDouble(value.toString()) > Double.parseDouble(max.toString())) return 1; - if (this.min != null && Double.valueOf(value.toString()) < Double.valueOf(min.toString())) + if (this.min != null && Double.parseDouble(value.toString()) < Double.parseDouble(min.toString())) return -1; return 0; @@ -160,41 +160,23 @@ public class ConfigEntry extends AbstractConfigType> implem @Override - public boolean equals(IConfigEntry obj) { return obj.getClass() == ConfigEntry.class ? equals((ConfigEntry)obj) : false; } + public boolean equals(IConfigEntry obj) { return obj.getClass() == ConfigEntry.class && equals((ConfigEntry) obj); } /** Is the value of this equal to another */ public boolean equals(ConfigEntry obj) { // Can all of this just be "return this.value.equals(obj.value)"? - if (this.value.getClass() != obj.value.getClass()) - return false; - if (Number.class.isAssignableFrom(this.value.getClass())) { - if (this.value == obj.value) - return true; - else return false; - } else { - if (this.value.equals(obj.value)) - return true; - else return false; - } + if (Number.class.isAssignableFrom(this.value.getClass())) + return this.value == obj.value; + else + return this.value.equals(obj.value); } - public Runnable getRunnable() { - return this.runnable; - } - public void setRunnable(Runnable runnable) { - this.runnable = runnable; - } - public void runRunnable() { - if (runnable != null) - runnable.run(); - } public static class Builder extends AbstractConfigType.Builder> { private String tmpComment = null; private T tmpMin; private T tmpMax; private boolean tmpUseApiOverwrite; - private Runnable tmpRunnable; private ConfigEntryPerformance tmpPerformance = ConfigEntryPerformance.DONT_SHOW; public Builder comment(String newComment) { @@ -202,6 +184,7 @@ public class ConfigEntry extends AbstractConfigType> implem return this; } + /** Allows most values to be set by 1 setter */ public Builder setMinDefaultMax(T newMin, T newDefault, T newMax) { this.set(newDefault); this.setMinMax(newMin, newMax); @@ -228,11 +211,6 @@ public class ConfigEntry extends AbstractConfigType> implem return this; } - public Builder setRunnable(Runnable newRunnable) { - this.tmpRunnable = newRunnable; - return this; - } - public Builder setPerformance(ConfigEntryPerformance newPerformance) { this.tmpPerformance = newPerformance; return this; @@ -241,7 +219,7 @@ public class ConfigEntry extends AbstractConfigType> implem public ConfigEntry build() { - return new ConfigEntry(tmpAppearance, tmpValue, tmpComment, tmpMin, tmpMax, tmpUseApiOverwrite, tmpRunnable, tmpPerformance, tmpListener); + return new ConfigEntry(tmpAppearance, tmpValue, tmpComment, tmpMin, tmpMax, tmpUseApiOverwrite, tmpPerformance, tmpListener); } } } diff --git a/core/src/main/java/com/seibel/lod/core/config/types/ConfigEntryAppearance.java b/core/src/main/java/com/seibel/lod/core/config/types/ConfigEntryAppearance.java index dc76d6f7c..a92f169de 100644 --- a/core/src/main/java/com/seibel/lod/core/config/types/ConfigEntryAppearance.java +++ b/core/src/main/java/com/seibel/lod/core/config/types/ConfigEntryAppearance.java @@ -1,5 +1,11 @@ package com.seibel.lod.core.config.types; +/** + * Allows options or categories to only be shown in the file or only in the ui + * (remember that if you make it only visible in the ui then the option wont save on game restart) + * + * @author coolGi + */ public enum ConfigEntryAppearance { ALL(true, true), ONLY_SHOW(true, false), diff --git a/core/src/main/java/com/seibel/lod/core/config/types/ConfigEntryPerformance.java b/core/src/main/java/com/seibel/lod/core/config/types/ConfigEntryPerformance.java index 7c45aa2e1..85390f68f 100644 --- a/core/src/main/java/com/seibel/lod/core/config/types/ConfigEntryPerformance.java +++ b/core/src/main/java/com/seibel/lod/core/config/types/ConfigEntryPerformance.java @@ -2,6 +2,7 @@ package com.seibel.lod.core.config.types; /** * What is the performance impact of an entry + * (default is DONT_SHOW) * * @author coolGi */ diff --git a/core/src/main/java/com/seibel/lod/core/config/types/ConfigUIComment.java b/core/src/main/java/com/seibel/lod/core/config/types/ConfigUIComment.java index 59bcdf18f..fbec4b6cb 100644 --- a/core/src/main/java/com/seibel/lod/core/config/types/ConfigUIComment.java +++ b/core/src/main/java/com/seibel/lod/core/config/types/ConfigUIComment.java @@ -1,7 +1,7 @@ package com.seibel.lod.core.config.types; /** - * Adds something like a ConfigEntry but without a button to change the input and only in the gui + * Adds something like a ConfigEntry but without a button to change the input * * @author coolGi */ diff --git a/core/src/main/java/com/seibel/lod/core/jar/DarkModeDetector.java b/core/src/main/java/com/seibel/lod/core/jar/DarkModeDetector.java index 0adbb085b..122d5c3e8 100644 --- a/core/src/main/java/com/seibel/lod/core/jar/DarkModeDetector.java +++ b/core/src/main/java/com/seibel/lod/core/jar/DarkModeDetector.java @@ -3,7 +3,7 @@ package com.seibel.lod.core.jar; import java.io.*; import java.util.regex.Pattern; -import static com.seibel.lod.core.JarMain.getOperatingSystem; +import static com.seibel.lod.core.jar.JarMain.getOperatingSystem; /** * A fork of iris'is dark mode detector (https://github.com/IrisShaders/Iris-Installer/blob/master/src/main/java/net/hypercubemc/iris_installer/DarkModeDetector.java) diff --git a/core/src/main/java/com/seibel/lod/core/JarMain.java b/core/src/main/java/com/seibel/lod/core/jar/JarMain.java similarity index 98% rename from core/src/main/java/com/seibel/lod/core/JarMain.java rename to core/src/main/java/com/seibel/lod/core/jar/JarMain.java index 0f409deb4..3010ecf3c 100644 --- a/core/src/main/java/com/seibel/lod/core/JarMain.java +++ b/core/src/main/java/com/seibel/lod/core/jar/JarMain.java @@ -1,7 +1,8 @@ -package com.seibel.lod.core; +package com.seibel.lod.core.jar; import com.formdev.flatlaf.FlatDarkLaf; import com.formdev.flatlaf.FlatLightLaf; +import com.seibel.lod.core.ModInfo; import com.seibel.lod.core.jar.DarkModeDetector; import com.seibel.lod.core.jar.JarUtils; import com.seibel.lod.core.jar.gui.BaseJFrame; @@ -34,6 +35,7 @@ public class JarMain { Locale.setDefault(Locale.US); } // Set up the theme + System.setProperty("apple.awt.application.appearance", "system"); if (isDarkTheme) FlatDarkLaf.setup(); else diff --git a/core/src/main/java/com/seibel/lod/core/jar/JarUtils.java b/core/src/main/java/com/seibel/lod/core/jar/JarUtils.java index 60cfda204..ed4069b9a 100644 --- a/core/src/main/java/com/seibel/lod/core/jar/JarUtils.java +++ b/core/src/main/java/com/seibel/lod/core/jar/JarUtils.java @@ -4,6 +4,12 @@ import java.io.*; import java.nio.charset.StandardCharsets; import java.security.MessageDigest; +/** + * Some general utils for the jar + * this includes stuff like accessing files inside the jar and checking the checksum of a file + * + * @author coolGi + */ public class JarUtils { public static final File jarFile = new File(JarUtils.class.getProtectionDomain().getCodeSource().getLocation().getPath()); diff --git a/core/src/main/java/com/seibel/lod/core/jar/gui/BaseJFrame.java b/core/src/main/java/com/seibel/lod/core/jar/gui/BaseJFrame.java index ac8c80642..7de9d6743 100644 --- a/core/src/main/java/com/seibel/lod/core/jar/gui/BaseJFrame.java +++ b/core/src/main/java/com/seibel/lod/core/jar/gui/BaseJFrame.java @@ -39,6 +39,7 @@ public class BaseJFrame extends JFrame { } catch (Exception e) {e.printStackTrace();} setSize(720, 480); setLocationRelativeTo(null); // Puts the window at the middle of the screen + setLayout(new BorderLayout()); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } diff --git a/core/src/main/java/com/seibel/lod/core/jar/gui/JSwitch.java b/core/src/main/java/com/seibel/lod/core/jar/gui/JSwitch.java index cbca504a0..95f9eb9e6 100644 --- a/core/src/main/java/com/seibel/lod/core/jar/gui/JSwitch.java +++ b/core/src/main/java/com/seibel/lod/core/jar/gui/JSwitch.java @@ -25,6 +25,7 @@ import javax.swing.plaf.ButtonUI; * * @author coolGi */ +// TODO: Make this for the theme (and finish the documentation once it is done) @SuppressWarnings("serial") public class JSwitch extends AbstractButton { private static final String uiClassID = "SwitchUI"; diff --git a/core/src/main/java/com/seibel/lod/core/jar/gui/cusomJObject/JBox.java b/core/src/main/java/com/seibel/lod/core/jar/gui/cusomJObject/JBox.java index 2c5eed583..6ae1d0c7a 100644 --- a/core/src/main/java/com/seibel/lod/core/jar/gui/cusomJObject/JBox.java +++ b/core/src/main/java/com/seibel/lod/core/jar/gui/cusomJObject/JBox.java @@ -3,6 +3,11 @@ package com.seibel.lod.core.jar.gui.cusomJObject; import javax.swing.*; import java.awt.*; +/** + * A rectangular box that can be placed with java swing + * + * @author coolGi + */ public class JBox extends JComponent { private static final String uiClassID = "BoxBarUI"; diff --git a/core/src/main/java/com/seibel/lod/core/jar/installer/GitlabGetter.java b/core/src/main/java/com/seibel/lod/core/jar/installer/GitlabGetter.java index 626633f5e..ca3d30552 100644 --- a/core/src/main/java/com/seibel/lod/core/jar/installer/GitlabGetter.java +++ b/core/src/main/java/com/seibel/lod/core/jar/installer/GitlabGetter.java @@ -12,10 +12,12 @@ import java.util.List; import java.util.stream.Collectors; /** - * Gets the releases available on gitlab and sends out the link + * Gets the releases available on gitlab and sends out the link. + * Please move over to ModrinthGetter for downloading releases of the mod * * @author coolGi */ +// TODO: Change this to a way to get the nightly builds @Deprecated public class GitlabGetter { public static final String GitLabApi = "https://gitlab.com/api/v4/projects/"; diff --git a/core/src/main/java/com/seibel/lod/core/jar/installer/WebDownloader.java b/core/src/main/java/com/seibel/lod/core/jar/installer/WebDownloader.java index 177725d13..9d4be6af5 100644 --- a/core/src/main/java/com/seibel/lod/core/jar/installer/WebDownloader.java +++ b/core/src/main/java/com/seibel/lod/core/jar/installer/WebDownloader.java @@ -9,7 +9,7 @@ import java.security.DigestInputStream; import java.security.MessageDigest; /** - * Does something similar to wget + * Does something similar to wget/curl. * It allows you to download a file from a link * * @author coolGi @@ -17,7 +17,7 @@ import java.security.MessageDigest; public class WebDownloader { public static boolean netIsAvailable() { try { - final URL url = new URL("https://gitlab.com"); + final URL url = new URL("https://www.google.com"); // Google will probably be online forever so we use that to check network connection final URLConnection conn = url.openConnection(); conn.connect(); conn.getInputStream().close();