Added some api notes and moved JarMain to the jar folder
This commit is contained in:
-1
@@ -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;
|
||||
|
||||
/**
|
||||
|
||||
-1
@@ -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. <br><br>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<Class, ConverterBase> convertObjects = new HashMap<Class, ConverterBase>() {{
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,8 +25,10 @@ public abstract class AbstractConfigType<T, S> { // 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
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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<Class, ConfigCategory> {
|
||||
public String destination; // Where the category goes to
|
||||
|
||||
|
||||
@@ -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<T> extends AbstractConfigType<T, ConfigEntry<T>> 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<T> extends AbstractConfigType<T, ConfigEntry<T>> implem
|
||||
/**
|
||||
* Checks if the option is valid
|
||||
*
|
||||
* 0 == valid
|
||||
* 1 == number too high
|
||||
* -1 == number too low
|
||||
* @return 0 == valid
|
||||
* <p> 1 == number too high
|
||||
* <p> -1 == number too low
|
||||
*/
|
||||
@Override
|
||||
public byte isValid() {
|
||||
@@ -139,9 +139,9 @@ public class ConfigEntry<T> extends AbstractConfigType<T, ConfigEntry<T>> 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<T> extends AbstractConfigType<T, ConfigEntry<T>> 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<T> extends AbstractConfigType.Builder<T, Builder<T>> {
|
||||
private String tmpComment = null;
|
||||
private T tmpMin;
|
||||
private T tmpMax;
|
||||
private boolean tmpUseApiOverwrite;
|
||||
private Runnable tmpRunnable;
|
||||
private ConfigEntryPerformance tmpPerformance = ConfigEntryPerformance.DONT_SHOW;
|
||||
|
||||
public Builder<T> comment(String newComment) {
|
||||
@@ -202,6 +184,7 @@ public class ConfigEntry<T> extends AbstractConfigType<T, ConfigEntry<T>> implem
|
||||
return this;
|
||||
}
|
||||
|
||||
/** Allows most values to be set by 1 setter */
|
||||
public Builder<T> setMinDefaultMax(T newMin, T newDefault, T newMax) {
|
||||
this.set(newDefault);
|
||||
this.setMinMax(newMin, newMax);
|
||||
@@ -228,11 +211,6 @@ public class ConfigEntry<T> extends AbstractConfigType<T, ConfigEntry<T>> implem
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<T> setRunnable(Runnable newRunnable) {
|
||||
this.tmpRunnable = newRunnable;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<T> setPerformance(ConfigEntryPerformance newPerformance) {
|
||||
this.tmpPerformance = newPerformance;
|
||||
return this;
|
||||
@@ -241,7 +219,7 @@ public class ConfigEntry<T> extends AbstractConfigType<T, ConfigEntry<T>> implem
|
||||
|
||||
|
||||
public ConfigEntry<T> build() {
|
||||
return new ConfigEntry<T>(tmpAppearance, tmpValue, tmpComment, tmpMin, tmpMax, tmpUseApiOverwrite, tmpRunnable, tmpPerformance, tmpListener);
|
||||
return new ConfigEntry<T>(tmpAppearance, tmpValue, tmpComment, tmpMin, tmpMax, tmpUseApiOverwrite, tmpPerformance, tmpListener);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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)
|
||||
|
||||
+3
-1
@@ -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
|
||||
@@ -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());
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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";
|
||||
|
||||
|
||||
@@ -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/";
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user