Upload files to "src/openonyx/history/internal"

This commit is contained in:
winterflyt committed 2026-11-30 06:01:11 +02:00
1 parent 77493827f8
commit e970073a93
3 files changed
+380

No files matched your search

@@ -0,0 +1,123 @@
package openonyx.history.internal;
import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import java.util.function.BooleanSupplier;
import java.util.function.Consumer;
import java.util.function.Predicate;
import openonyx.history.SettingValue;
public class NumberSetting extends SettingValue<Double> {
private String suffix = "";
private final double max;
private final double min;
private final double step;
public NumberSetting withSuffix(String string) {
this.suffix = string;
return this;
}
protected Double sanitize(Double double_) {
double d = Math.clamp(double_, this.min, this.max);
return this.step <= 0.0
? d
: Math.round(Math.clamp(this.min + Math.round((d - this.min) / this.step) * this.step, this.min, this.max) * 1000000.0) / 1000000.0;
}
public String getSuffix() {
return this.suffix;
}
public void setNormalized(double d) {
this.setValue(this.min + Math.clamp(d, 0.0, 1.0) * (this.max - this.min));
}
public <O> NumberSetting visibleWhen(SettingValue<O> settingValue, Predicate<O> predicate) {
super.visibleWhen(settingValue, predicate);
return this;
}
public double getMin() {
return this.min;
}
public double getMax() {
return this.max;
}
public int getInt() {
return (int)Math.round(this.getValue());
}
public NumberSetting visibleWhen(SettingValue<Boolean> settingValue) {
super.visibleWhen(settingValue);
return this;
}
public NumberSetting visibleWhen(BooleanSupplier booleanSupplier) {
super.visibleWhen(booleanSupplier);
return this;
}
public String format() {
StringBuilder stringBuilder = new StringBuilder();
String string;
if (this.isInteger()) {
string = String.valueOf(this.getInt());
} else {
Object[] objects = new Object[1];
boolean bl = true;
objects[0] = this.getValue();
string = String.format("%.2f", objects);
}
return stringBuilder.append(string).append(this.suffix).toString();
}
public float getFloat() {
return this.getValue().floatValue();
}
public double getNormalized() {
return this.max == this.min ? 0.0 : (this.getValue() - this.min) / (this.max - this.min);
}
@Override
public void fromJson(JsonElement jsonElement) {
if (jsonElement.isJsonPrimitive() && jsonElement.getAsJsonPrimitive().isNumber()) {
this.setValue(jsonElement.getAsDouble());
}
}
public NumberSetting(String string, double d, double e, double f, double g) {
super(string, d);
this.min = e;
this.max = f;
this.step = g;
this.setValue(this.sanitize(d));
}
public boolean isInteger() {
return this.step >= 1.0 && this.step == Math.floor(this.step);
}
@Override
public JsonElement toJson() {
return new JsonPrimitive(this.getValue());
}
public NumberSetting onChange(Consumer<Double> consumer) {
super.onChange(consumer);
return this;
}
public NumberSetting describe(String string) {
super.describe(string);
return this;
}
public double getStep() {
return this.step;
}
}
@@ -0,0 +1,202 @@
package openonyx.history.internal;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import java.util.concurrent.ThreadLocalRandom;
import java.util.function.BooleanSupplier;
import java.util.function.Consumer;
import java.util.function.Predicate;
import openonyx.history.Range;
import openonyx.history.SettingValue;
public class RangeSetting extends SettingValue<Range> {
private final double min;
private final double max;
private final double step;
private String suffix = "";
public static RangeSetting ofInt(String string, int i, int j, int k, int l) {
return new RangeSetting(string, i, j, k, l, 1.0);
}
public float getHighFloat() {
return (float)this.getValue().max();
}
public double getLow() {
return this.getValue().min();
}
protected Range sanitize(Range range) {
return new Range(this.d(range.min()), this.d(range.max()));
}
public <O> RangeSetting visibleWhen(SettingValue<O> settingValue, Predicate<O> predicate) {
super.visibleWhen(settingValue, predicate);
return this;
}
public double getMax() {
return this.max;
}
public RangeSetting describe(String string) {
super.describe(string);
return this;
}
public float getLowFloat() {
return (float)this.getValue().min();
}
public RangeSetting withSuffix(String string) {
this.suffix = string;
return this;
}
public int randomInt() {
RangeSetting rangeSetting1 = this;
Range range = rangeSetting1.getValue();
int j = (int)Math.round(range.min());
int i;
return (i = (int)Math.round(range.max())) <= j ? j : ThreadLocalRandom.current().nextInt(j, i + 1);
}
public String format() {
RangeSetting rangeSetting1 = this;
if (rangeSetting1.isInteger()) {
return rangeSetting1.getLowInt() == rangeSetting1.getHighInt()
? rangeSetting1.getLowInt() + rangeSetting1.suffix
: rangeSetting1.getLowInt() + rangeSetting1.suffix + " - " + rangeSetting1.getHighInt() + rangeSetting1.suffix;
} else {
Object[] objects = new Object[1];
boolean bl1 = true;
objects[0] = rangeSetting1.getLow();
String string1 = String.format("%.2f", objects);
objects = new Object[1];
bl1 = true;
objects[0] = rangeSetting1.getHigh();
String string = String.format("%.2f", objects);
boolean bl = string1.equals(string);
StringBuilder stringBuilder = new StringBuilder;
if (bl) {
stringBuilder./* $VF: Unable to resugar constructor */<init>();
return stringBuilder.insert(0, string1).append(rangeSetting1.suffix).toString();
} else {
stringBuilder./* $VF: Unable to resugar constructor */<init>();
return stringBuilder.insert(0, string1).append(rangeSetting1.suffix).append(" - ").append(string).append(rangeSetting1.suffix).toString();
}
}
}
public double fromNormalized(double d) {
return this.d(this.min + Math.clamp(d, 0.0, 1.0) * (this.max - this.min));
}
public RangeSetting onChange(Consumer<Range> consumer) {
super.onChange(consumer);
return this;
}
public void setHigh(double d) {
this.setValue(new Range(this.getLow(), Math.max(this.d(d), this.getLow())));
}
public int getHighInt() {
return (int)Math.round(this.getValue().max());
}
public void setLow(double d) {
this.setValue(new Range(Math.min(this.d(d), this.getHigh()), this.getHigh()));
}
@Override
public void fromJson(JsonElement jsonElement) {
if (jsonElement.isJsonObject()) {
JsonObject jsonObject = jsonElement.getAsJsonObject();
jsonElement = jsonObject.get("min");
JsonElement jsonElement1 = jsonObject.get("max");
if (jsonElement != null && jsonElement1 != null && jsonElement.isJsonPrimitive() && jsonElement1.isJsonPrimitive()) {
if (jsonElement.getAsJsonPrimitive().isNumber() && jsonElement1.getAsJsonPrimitive().isNumber()) {
this.setValue(new Range(jsonElement.getAsDouble(), jsonElement1.getAsDouble()));
}
}
}
}
public int getLowInt() {
return (int)Math.round(this.getValue().min());
}
private double d(double d) {
d = Math.clamp(d, this.min, this.max);
return this.step <= 0.0
? d
: Math.round(Math.clamp(this.min + Math.round((d - this.min) / this.step) * this.step, this.min, this.max) * 1000000.0) / 1000000.0;
}
@Override
public JsonElement toJson() {
RangeSetting rangeSetting1 = this;
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("min", rangeSetting1.getLow());
jsonObject.addProperty("max", rangeSetting1.getHigh());
return jsonObject;
}
public float L() {
return (float)this.random();
}
public static RangeSetting of(String string, double d, double e, double f, double g) {
return new RangeSetting(string, d, e, f, g, 0.01);
}
public double getMin() {
return this.min;
}
public RangeSetting visibleWhen(SettingValue<Boolean> settingValue) {
super.visibleWhen(settingValue);
return this;
}
public double random() {
RangeSetting rangeSetting1 = this;
Range range;
return (range = rangeSetting1.getValue()).d() <= 0.0 ? range.min() : ThreadLocalRandom.current().nextDouble(range.min(), range.max());
}
public RangeSetting(String string, double d, double e, double f, double g, double h) {
super(string, new Range(d, e));
this.min = f;
this.max = g;
this.step = h;
this.setValue(this.sanitize(this.getValue()));
}
public String getSuffix() {
return this.suffix;
}
public RangeSetting visibleWhen(BooleanSupplier booleanSupplier) {
super.visibleWhen(booleanSupplier);
return this;
}
public double getHigh() {
return this.getValue().max();
}
public boolean isInteger() {
return this.step >= 1.0 && this.step == Math.floor(this.step);
}
public double getStep() {
return this.step;
}
public double normalize(double d) {
return this.max == this.min ? 0.0 : (d - this.min) / (this.max - this.min);
}
}
@@ -0,0 +1,55 @@
package openonyx.history.internal;
import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import java.util.function.BooleanSupplier;
import java.util.function.Consumer;
import java.util.function.Predicate;
import openonyx.history.SettingValue;
public class TextSetting extends SettingValue<String> {
public TextSetting visibleWhen(BooleanSupplier booleanSupplier) {
super.visibleWhen(booleanSupplier);
return this;
}
@Override
public JsonElement toJson() {
return new JsonPrimitive(this.getValue());
}
public TextSetting onChange(Consumer<String> consumer) {
super.onChange(consumer);
return this;
}
public TextSetting visibleWhen(SettingValue<Boolean> settingValue) {
super.visibleWhen(settingValue);
return this;
}
public TextSetting describe(String string) {
super.describe(string);
return this;
}
public TextSetting(String string, String string1) {
super(string, string1);
}
public <O> TextSetting visibleWhen(SettingValue<O> settingValue, Predicate<O> predicate) {
super.visibleWhen(settingValue, predicate);
return this;
}
protected String sanitize(String string) {
return string == null ? "" : string;
}
@Override
public void fromJson(JsonElement jsonElement) {
if (jsonElement.isJsonPrimitive() && jsonElement.getAsJsonPrimitive().isString()) {
this.setValue(jsonElement.getAsString());
}
}
}