This commit is contained in:
James Seibel
2023-08-20 14:14:56 -05:00
5 changed files with 42 additions and 37 deletions
@@ -122,9 +122,6 @@ public abstract class AbstractPresetConfigEventHandler<TPresetEnum extends Enum<
LOGGER.info("preset active: " + newPresetEnum);
}
@Override
public void onUiModify() { /* do nothing, we only care about modified config values */ }
/**
* listen for changed graphics settings and set the
* quick quality to "custom" if anything was changed
@@ -175,19 +175,19 @@ public class ConfigFileHandling
{
if (entry.getType().isEnum())
{
entry.setWithoutSaving((T) (workConfig.getEnum(entry.getNameWCategory(), (Class<? extends Enum>) entry.getType())));
entry.pureSet((T) (workConfig.getEnum(entry.getNameWCategory(), (Class<? extends Enum>) entry.getType())));
return;
}
Class<?> originalClass = ConfigTypeConverters.isClassConvertable(entry.getType());
if (originalClass != null)
{
entry.setWithoutSaving((T) ConfigTypeConverters.convertFromString(originalClass, workConfig.get(entry.getNameWCategory())));
entry.pureSet((T) ConfigTypeConverters.convertFromString(originalClass, workConfig.get(entry.getNameWCategory())));
return;
}
if (entry.getType() == workConfig.get(entry.getNameWCategory()).getClass())
{ // If the types are the same
entry.setWithoutSaving((T) workConfig.get(entry.getNameWCategory()));
entry.pureSet((T) workConfig.get(entry.getNameWCategory()));
entry.clampWithinRange();
return;
}
@@ -247,19 +247,11 @@ public class ConfigFileHandling
Files.createDirectory(this.configPath.getParent());
}
try
{
boolean fileDeleted = Files.deleteIfExists(this.configPath);
System.out.println("File at [" + this.configPath + "] was " + (fileDeleted ? "" : "not ") + "able to be deleted.");
}
catch (AccessDeniedException ignored) { /* temporary fix due to windows/Intellij issues either locking or changing the permissions of the file */ }
boolean fileDeleted = Files.deleteIfExists(this.configPath);
System.out.println("File at [" + this.configPath + "] was " + (fileDeleted ? "" : "not ") + "able to be deleted.");
try
{
Files.createFile(this.configPath);
}
catch (FileAlreadyExistsException ignore) { /* temporary fix due to windows/Intellij issues either locking or changing the permissions of the file */ }
Files.createFile(this.configPath);
config.load();
}
@@ -3,12 +3,9 @@ package com.seibel.distanthorizons.core.config.listeners;
public interface IConfigListener
{
/** Called whenever the value is set (including in core DH code) */
void onConfigValueSet();
default void onConfigValueSet() {};
/**
* TODO not implemented
* Called whenever the value is changed through the UI (only when the done button is pressed)
*/
void onUiModify();
/** Called whenever the value is changed through the UI */
default void onUiModify() {};
}
@@ -66,18 +66,42 @@ public class ConfigEntry<T> extends AbstractConfigType<T, ConfigEntry<T>> implem
public T getApiValue() { return this.apiValue; }
@Override
public boolean getAllowApiOverride() { return this.allowApiOverride; }
/**
* DONT USE THIS IN YOUR CODE <br>
* Sets the value without informing the rest of the code (ie, doesnt call listeners, or saves the value). <br>
* Should only be used when loading the config from the file
*/
public void pureSet(T newValue) {
super.set(newValue);
}
/** Sets the value without saving */
@Override
public void setWithoutSaving(T newValue)
{
super.set(newValue);
this.listenerList.forEach(IConfigListener::onConfigValueSet);
}
@Override
public void set(T newValue)
{
super.set(newValue);
this.setWithoutSaving(newValue);
this.save();
this.listenerList.forEach(IConfigListener::onConfigValueSet);
}
public void uiSetWithoutSaving(T newValue)
{
this.setWithoutSaving(newValue);
this.listenerList.forEach(IConfigListener::onUiModify);
}
public void uiSet(T newValue)
{
this.set(newValue);
this.listenerList.forEach(IConfigListener::onUiModify);
}
@Override
public T get()
{
@@ -94,13 +118,6 @@ public class ConfigEntry<T> extends AbstractConfigType<T, ConfigEntry<T>> implem
return super.get();
}
/** Sets the value without saving */
@Override
public void setWithoutSaving(T newValue)
{
super.set(newValue);
this.listenerList.forEach(IConfigListener::onConfigValueSet);
}
/** Gets the min value */
@Override
@@ -301,7 +318,9 @@ public class ConfigEntry<T> extends AbstractConfigType<T, ConfigEntry<T>> implem
return this;
}
public Builder<T> replaceListener(ArrayList<IConfigListener> newConfigListener)
public Builder<T> replaceListeners(ArrayList<IConfigListener> newConfigListener)
{
this.tmpIConfigListener = newConfigListener;
return this;
@@ -19,8 +19,8 @@ public final class ModGitInfo
static
{
String gitMainCommit = "UNKNOWN";
String gitMainBranch = "UNKNOWN";
String gitMainCommit = "UNKNOWN";
String gitCoreCommit = "UNKNOWN";
try
@@ -31,22 +31,22 @@ public final class ModGitInfo
Config jsonObject = Config.inMemory();
JsonFormat.minimalInstance().createParser().parse(jsonString, jsonObject, ParsingMode.REPLACE);
gitCoreCommit = jsonObject.get("git_main_branch");
gitMainCommit = jsonObject.get("git_main_commit");
gitMainBranch = jsonObject.get("git_core_commit");
gitCoreCommit = jsonObject.get("git_main_branch");
}
catch (Exception | Error e)
{
LOGGER.warn("Unable to get the Git information from " + FILE_NAME);
}
Git_Main_Commit = gitMainCommit;
Git_Core_Commit = gitMainBranch;
Git_Main_Commit = gitMainCommit;
Git_Main_Branch = gitCoreCommit;
}
public static final String Git_Main_Branch;
public static final String Git_Main_Commit;
public static final String Git_Core_Commit;
public static final String Git_Main_Branch;
}