Config Optimizations
This commit is contained in:
parent
9cb54346a2
commit
a7efcd25ba
15 changed files with 161 additions and 77 deletions
|
@ -4,12 +4,40 @@ import org.betterx.bclib.BCLib;
|
|||
import org.betterx.bclib.api.v2.dataexchange.handler.autosync.AutoSync;
|
||||
|
||||
public class ClientConfig extends NamedPathConfig {
|
||||
|
||||
@ConfigUI(hide = true)
|
||||
public static final ConfigToken<Boolean> DID_SHOW_WELCOME = ConfigToken.Boolean(
|
||||
false,
|
||||
"didShowWelcome",
|
||||
"version"
|
||||
);
|
||||
@ConfigUI(topPadding = 12)
|
||||
public static final ConfigToken<Boolean> CHECK_VERSIONS = ConfigToken.Boolean(
|
||||
true,
|
||||
"check",
|
||||
"version"
|
||||
);
|
||||
@ConfigUI(leftPadding = 8)
|
||||
public static final ConfigToken<Boolean> SHOW_UPDATE_INFO = ConfigToken.Boolean(
|
||||
true,
|
||||
"showUpdateInfo",
|
||||
"ui"
|
||||
);
|
||||
public static final ConfigToken<Boolean> SUPPRESS_EXPERIMENTAL_DIALOG = ConfigToken.Boolean(
|
||||
false,
|
||||
"suppressExperimentalDialogOnLoad",
|
||||
"ui"
|
||||
);
|
||||
|
||||
|
||||
@ConfigUI(hide = true)
|
||||
public static final ConfigToken<Boolean> NO_DONOR = ConfigToken.Boolean(
|
||||
false,
|
||||
"iAmNotTheDonorType",
|
||||
"ui"
|
||||
);
|
||||
|
||||
|
||||
@ConfigUI(topPadding = 12)
|
||||
public static final ConfigToken<Boolean> ENABLED = ConfigToken.Boolean(true, "enabled", AutoSync.SYNC_CATEGORY);
|
||||
|
||||
|
@ -41,48 +69,38 @@ public class ClientConfig extends NamedPathConfig {
|
|||
true,
|
||||
"displayModInfo",
|
||||
AutoSync.SYNC_CATEGORY,
|
||||
(config) -> config.get(
|
||||
ENABLED)
|
||||
(config) -> config.get(ENABLED)
|
||||
);
|
||||
|
||||
@ConfigUI(topPadding = 12)
|
||||
@ConfigUI(leftPadding = 8)
|
||||
public static final ConfigToken<Boolean> DEBUG_HASHES = ConfigToken.Boolean(
|
||||
false,
|
||||
"debugHashes",
|
||||
AutoSync.SYNC_CATEGORY
|
||||
);
|
||||
|
||||
@ConfigUI(leftPadding = 8)
|
||||
@ConfigUI(topPadding = 12)
|
||||
public static final ConfigToken<Boolean> CUSTOM_FOG_RENDERING = ConfigToken.Boolean(
|
||||
true,
|
||||
"customFogRendering",
|
||||
"rendering"
|
||||
);
|
||||
@ConfigUI(leftPadding = 8)
|
||||
public static final ConfigToken<Boolean> NETHER_THICK_FOG = ConfigToken.Boolean(
|
||||
public static final ConfigToken<Boolean> NETHER_THICK_FOG = DependendConfigToken.Boolean(
|
||||
true,
|
||||
"netherThickFog",
|
||||
"rendering"
|
||||
"rendering",
|
||||
(config) -> config.get(CUSTOM_FOG_RENDERING)
|
||||
);
|
||||
|
||||
public static final ConfigToken<Float> FOG_DENSITY = ConfigToken.Float(
|
||||
@ConfigUI(leftPadding = 8, minValue = 0, maxValue = 2)
|
||||
public static final ConfigToken<Float> FOG_DENSITY = DependendConfigToken.Float(
|
||||
1.0f,
|
||||
"FogDensity",
|
||||
"rendering"
|
||||
"rendering",
|
||||
(config) -> config.get(CUSTOM_FOG_RENDERING)
|
||||
);
|
||||
|
||||
public static final ConfigToken<Boolean> SHOW_UPDATE_INFO = ConfigToken.Boolean(
|
||||
true,
|
||||
"showUpdateInfo",
|
||||
"ui"
|
||||
);
|
||||
|
||||
@ConfigUI(leftPadding = 8)
|
||||
public static final ConfigToken<Boolean> NO_DONOR = ConfigToken.Boolean(
|
||||
false,
|
||||
"no_donor",
|
||||
"version"
|
||||
);
|
||||
|
||||
public ClientConfig() {
|
||||
super(BCLib.MOD_ID, "client", false);
|
||||
|
@ -135,4 +153,21 @@ public class ClientConfig extends NamedPathConfig {
|
|||
public float fogDensity() {
|
||||
return get(FOG_DENSITY);
|
||||
}
|
||||
|
||||
public boolean checkVersions() {
|
||||
return get(ClientConfig.CHECK_VERSIONS);
|
||||
}
|
||||
|
||||
|
||||
public void setCheckVersions(boolean newValue) {
|
||||
set(ClientConfig.CHECK_VERSIONS, newValue);
|
||||
}
|
||||
|
||||
public boolean didShowWelcomeScreen() {
|
||||
return get(ClientConfig.DID_SHOW_WELCOME);
|
||||
}
|
||||
|
||||
public void setDidShowWelcomeScreen() {
|
||||
set(ClientConfig.DID_SHOW_WELCOME, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -198,6 +198,7 @@ public abstract class Config {
|
|||
protected boolean setBoolean(ConfigKey key, boolean value) {
|
||||
try {
|
||||
ConfigKeeper.BooleanEntry entry = keeper.getEntry(key, ConfigKeeper.BooleanEntry.class);
|
||||
|
||||
if (entry == null) return false;
|
||||
entry.setValue(value);
|
||||
return true;
|
||||
|
|
|
@ -57,11 +57,17 @@ public final class ConfigKeeper {
|
|||
}
|
||||
|
||||
private static Pair<JsonElement, Pair<String, String>> find(JsonObject json, Pair<String, String> key) {
|
||||
String kk = key.first + key.second;
|
||||
for (var entry : json.entrySet()) {
|
||||
final Pair<String, String> otherKey = ConfigKey.realKey(entry.getKey());
|
||||
if (otherKey.first.equals(key.first)) return new Pair<>(entry.getValue(), otherKey);
|
||||
if (kk.equals(entry)) return new Pair<>(entry.getValue(), otherKey);
|
||||
}
|
||||
|
||||
// for (var entry : json.entrySet()) {
|
||||
// final Pair<String, String> otherKey = ConfigKey.realKey(entry.getKey());
|
||||
// if (otherKey.first.equals(key.first)) return new Pair<>(entry.getValue(), otherKey);
|
||||
// }
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,4 +22,14 @@ public @interface ConfigUI {
|
|||
* When a Widget is generated for this option, it will be indented by this Value
|
||||
*/
|
||||
int topPadding() default 0;
|
||||
|
||||
/**
|
||||
* When a Slider is generated, this will be the minimum Value
|
||||
*/
|
||||
int minValue() default 0;
|
||||
|
||||
/**
|
||||
* When a Slider is generated, this will be the maximu Value
|
||||
*/
|
||||
int maxValue() default 0;
|
||||
}
|
||||
|
|
|
@ -19,21 +19,6 @@ public class MainConfig extends NamedPathConfig {
|
|||
);
|
||||
|
||||
|
||||
@ConfigUI(hide = true)
|
||||
public static final ConfigToken<Boolean> DID_SHOW_WELCOME = ConfigToken.Boolean(
|
||||
false,
|
||||
"did_show_welcome",
|
||||
"version"
|
||||
);
|
||||
|
||||
public static final ConfigToken<Boolean> CHECK_VERSIONS = DependendConfigToken.Boolean(
|
||||
true,
|
||||
"check",
|
||||
"version",
|
||||
(config) -> !config.get(DID_SHOW_WELCOME)
|
||||
);
|
||||
|
||||
|
||||
public MainConfig() {
|
||||
super(BCLib.MOD_ID, "main", true, true);
|
||||
}
|
||||
|
@ -45,21 +30,4 @@ public class MainConfig extends NamedPathConfig {
|
|||
public boolean repairBiomes() {
|
||||
return get(REPAIR_BIOMES);
|
||||
}
|
||||
|
||||
public boolean checkVersions() {
|
||||
return get(CHECK_VERSIONS);
|
||||
}
|
||||
|
||||
public boolean didShowWelcomeScreen() {
|
||||
return get(DID_SHOW_WELCOME);
|
||||
}
|
||||
|
||||
public void setDidShowWelcomeScreen() {
|
||||
set(DID_SHOW_WELCOME, true);
|
||||
}
|
||||
|
||||
|
||||
public void setCheckVersions(boolean newValue) {
|
||||
set(CHECK_VERSIONS, newValue);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@ public class NamedPathConfig extends PathConfig {
|
|||
public final Boolean hidden;
|
||||
public final int leftPadding;
|
||||
public final int topPadding;
|
||||
public final int minRange;
|
||||
public final int maxRange;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
ConfigTokenDescription(Field fl) throws IllegalAccessException {
|
||||
|
@ -28,10 +30,14 @@ public class NamedPathConfig extends PathConfig {
|
|||
this.hidden = ui.hide();
|
||||
leftPadding = ui.leftPadding();
|
||||
topPadding = ui.topPadding();
|
||||
minRange = ui.minValue();
|
||||
maxRange = ui.maxValue();
|
||||
} else {
|
||||
this.hidden = false;
|
||||
this.leftPadding = 0;
|
||||
topPadding = 0;
|
||||
minRange = 0;
|
||||
maxRange = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -101,6 +107,21 @@ public class NamedPathConfig extends PathConfig {
|
|||
dependenciesTrue
|
||||
);
|
||||
}
|
||||
|
||||
public static DependendConfigToken<Float> Float(
|
||||
float defaultValue,
|
||||
String entry,
|
||||
String path,
|
||||
Predicate<NamedPathConfig> dependenciesTrue
|
||||
) {
|
||||
return new DependendConfigToken<Float>(
|
||||
ConfigKeeper.FloatEntry.class,
|
||||
defaultValue,
|
||||
entry,
|
||||
path,
|
||||
dependenciesTrue
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ConfigToken<T> extends ConfigKey {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue