Small property refactor

This commit is contained in:
2025-06-17 10:19:49 -05:00
parent 78097b1d8f
commit 5b77ea7363
20 changed files with 99 additions and 86 deletions
@@ -6,19 +6,19 @@ import org.saturnclient.saturnclient.config.NamedProperty;
import org.saturnclient.saturnclient.config.Property;
public class ModDimensions {
public Property<Integer> x = new Property<>(0);
public Property<Integer> y = new Property<>(0);
public Property<Float> scale = new Property<>(1.0f);
public Property<Integer> bgColor = new Property<>(0x00000000, Property.PropertyType.HEX);
public Property<Integer> fgColor = new Property<>(0xFFffffff, Property.PropertyType.HEX);
public Property<Integer> radius = new Property<>(0);
public Property<Integer> x = Property.integer(0);
public Property<Integer> y = Property.integer(0);
public Property<Float> scale = Property.floatProp(1.0f);
public Property<Integer> bgColor = Property.color(0x00000000);
public Property<Integer> fgColor = Property.color(0xFFffffff);
public Property<Integer> radius = Property.integer(0);
public Property<Integer> font = Property.font(0);
public int width = 0;
public int height = 0;
public NamedProperty<Map<String, Property<?>>> prop() {
return new Property<Map<String, Property<?>>>(Map.of(
return Property.namespace(Map.of(
"X", x,
"Y", y,
"Scale", scale,
@@ -13,7 +13,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
public class ArmorDisplay extends Module implements HudMod {
private static Property<Boolean> enabled = new Property<>(true);
private static Property<Boolean> enabled = Property.bool(true);
private static ModDimensions dimensions = new ModDimensions(40, 60);
public ArmorDisplay() {
@@ -8,7 +8,7 @@ import org.saturnclient.saturnclient.SaturnClient;
import org.saturnclient.saturnclient.config.Property;
public class AutoSprint extends Module {
private static Property<Boolean> enabled = new Property<>(true);
private static Property<Boolean> enabled = Property.bool(false);
public AutoSprint() {
super(
@@ -10,7 +10,7 @@ import org.saturnclient.ui2.resources.Textures;
import net.minecraft.client.render.RenderLayer;
public class Crosshair extends Module {
public static Property<Boolean> enabled = new Property<>(false);
public static Property<Boolean> enabled = Property.bool(false);
public Crosshair() {
super(
@@ -10,8 +10,7 @@ import org.saturnclient.ui2.RenderScope;
import org.saturnclient.ui2.resources.Fonts;
public class Fps extends Module implements HudMod {
private static Property<Boolean> enabled = new Property<>(false);
private static Property<Integer> fgColor = new Property<>(-1, Property.PropertyType.HEX);
private static Property<Boolean> enabled = Property.bool(false);
private static ModDimensions dimensions = new ModDimensions(60, Fonts.getHeight());
public Fps() {
@@ -26,14 +25,14 @@ public class Fps extends Module implements HudMod {
@Override
public void renderHud(RenderScope scope) {
String text = String.valueOf(SaturnClient.client.getCurrentFps()) + " FPS";
scope.drawText(text, 0, 0, dimensions.font.value, fgColor.value);
scope.drawText(text, 0, 0, dimensions.font.value, dimensions.fgColor.value);
dimensions.width = Fonts.getWidth(text, dimensions.font.value);
}
@Override
public void renderDummy(RenderScope scope) {
String text = "369 FPS";
scope.drawText(text, 0, 0, dimensions.font.value, fgColor.value);
scope.drawText(text, 0, 0, dimensions.font.value, dimensions.fgColor.value);
dimensions.width = Fonts.getWidth(text, dimensions.font.value);
}
@@ -21,8 +21,9 @@ import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;
public class PotionDisplay extends Module implements HudMod {
public static Property<Boolean> enabled = new Property<>(false);
public static Property<Boolean> enabled = Property.bool(false);
private static ModDimensions dimensions = new ModDimensions(60, 0);
private final StatusEffectInstance[] dummyEffects = {
new StatusEffectInstance(Registries.STATUS_EFFECT.getEntry(Identifier.ofVanilla("speed")).get(), 12000, 2),
new StatusEffectInstance(Registries.STATUS_EFFECT.getEntry(Identifier.ofVanilla("strength")).get(), 12000, 2),
@@ -10,11 +10,9 @@ import net.minecraft.util.Identifier;
public class SaturnClientConfig {
public static ConfigManager config;
public static Property<Boolean> realisticLogo =
new Property<>(false);
public static Property<Boolean> realisticLogo = Property.bool(false);
public static Property<Boolean> saturnTitleScreen =
new Property<>(true);
public static Property<Boolean> saturnTitleScreen = Property.bool(true);
public static Identifier getLogo() {
return realisticLogo.value ? Textures.REALISTIC_LOGO : Textures.LOGO;
@@ -32,8 +32,7 @@ public class ConfigManager {
public ConfigManager(ConfigManager config, String namespace) {
currentMap = new LinkedHashMap<>();
Property<Map<String, Property<?>>> namespaceProperty = new Property<>(currentMap,
Property.PropertyType.NAMESPACE);
Property<Map<String, Property<?>>> namespaceProperty = Property.namespace(currentMap);
config.property(namespace, namespaceProperty);
// Update the parent's state
config.currentMap.put(namespace, namespaceProperty);
@@ -41,8 +40,7 @@ public class ConfigManager {
}
public void sub(String namespace) {
Property<Map<String, Property<?>>> namespaceProperty = new Property<>(currentMap,
Property.PropertyType.NAMESPACE);
Property<Map<String, Property<?>>> namespaceProperty = Property.namespace(currentMap);
property(namespace, namespaceProperty);
}
@@ -23,43 +23,60 @@ public class Property<T> {
private String[] availableValues;
private PropertyType type;
public Property(T value) {
this.value = value;
this.defaultValue = value;
if (value instanceof Boolean) {
type = PropertyType.BOOLEAN;
} else if (value instanceof Integer) {
type = PropertyType.INTEGER;
} else if (value instanceof Float) {
type = PropertyType.FLOAT;
} else if (value instanceof String) {
type = PropertyType.STRING;
} else if (valueIsNamespace(value)) {
type = PropertyType.NAMESPACE;
}
}
public Property(T value, PropertyType type) {
private Property(T value, PropertyType type) {
this.value = value;
this.defaultValue = value;
this.type = type;
}
public static <T> Property<T> from(T value) {
if (value instanceof Boolean) {
return new Property<>(value, PropertyType.BOOLEAN);
} else if (value instanceof Integer) {
return new Property<>(value, PropertyType.INTEGER);
} else if (value instanceof Float) {
return new Property<>(value, PropertyType.FLOAT);
} else if (value instanceof String) {
return new Property<>(value, PropertyType.STRING);
} else if (valueIsNamespace(value)) {
return new Property<>(value, PropertyType.NAMESPACE);
} else {
return null;
}
}
public static Property<Integer> font(int value) {
return select(value, "Default", "Inter", "Inter bold");
}
public static Property<Integer> select(Integer value, String... availableValues) {
Property<Integer> property = new Property<>(value, PropertyType.SELECT);
property.availableValues = availableValues;
return property;
}
public static Property<Integer> font(int value) {
return select(value, "Default", "Inter", "Inter bold");
public static Property<Map<String, Property<?>>> namespace(Map<String, Property<?>> value) {
return new Property<>(value, PropertyType.NAMESPACE);
}
@SuppressWarnings("unchecked")
public static <T> Property<T> namespace(Map<String, Property<?>> value) {
Property<T> property = new Property<>((T) value, PropertyType.NAMESPACE);
property.type = PropertyType.NAMESPACE;
return property;
public static Property<Boolean> bool(boolean value) {
return new Property<>(value, PropertyType.BOOLEAN);
}
public static Property<Integer> integer(int value) {
return new Property<>(value, PropertyType.INTEGER);
}
public static Property<Float> floatProp(float value) {
return new Property<>(value, PropertyType.FLOAT);
}
public static Property<String> string(String value) {
return new Property<>(value, PropertyType.STRING);
}
public static Property<Integer> color(int value) {
return new Property<>(value, PropertyType.HEX);
}
public void next() {
@@ -74,13 +74,13 @@ public class ThemeManager {
// Generic method to store any type of property
public <T> Property<T> property(String name, Property<T> prop) {
for (String state : states) {
Property<?> property = new Property<T>(prop.value);
Property<?> property = Property.from(prop.value);
properties.get(namespace+"@"+state).put(name, property);
loadProp(state, name, property);
}
loadProp(null, name, prop);
properties.get(namespace).put(name, new Property<T>(prop.value));
properties.get(namespace).put(name, Property.from(prop.value));
currentStyling.put(name, prop);
return prop;
@@ -11,10 +11,10 @@ import net.minecraft.util.Identifier;
public class CosmeticPreview extends Element {
private static ThemeManager theme = new ThemeManager("CosmeticPreview", "selected", "hovering");
private static Property<Integer> bgColor = theme.property("bg-color", new Property<Integer>(0xAA000000));
private static Property<Integer> fgColor = theme.property("fg-color", new Property<Integer>(0xFFFFFFFF));
private static Property<Integer> padding = theme.property("padding", new Property<Integer>(14));
private static Property<Integer> cornerRadius = theme.property("corner-radius", new Property<Integer>(10));
private static Property<Integer> bgColor = theme.property("bg-color", Property.color(0xAA000000));
private static Property<Integer> fgColor = theme.property("fg-color", Property.color(0xFFFFFFFF));
private static Property<Integer> padding = theme.property("padding", Property.integer(14));
private static Property<Integer> cornerRadius = theme.property("corner-radius", Property.integer(10));
static {}
@@ -16,14 +16,14 @@ import net.minecraft.client.render.RenderLayer;
public class SaturnModule extends Element {
private static ThemeManager theme = new ThemeManager("Module", "enabled", "hovering");
private static Property<Integer> bgColor = theme.property("bg", new Property<>(0xFF1d202d));
private static Property<Integer> fgColor = theme.property("fg", new Property<>(0xFFA1A2B8));
private static Property<Integer> iconFg = theme.property("icon-fg", new Property<>(0xFFA1A2B8));
private static Property<Integer> iconBg = theme.property("icon-bg", new Property<>(0xFF2e3248));
private static Property<Integer> tagBg = theme.property("tag-bg", new Property<>(0xFF2e3248));
private static Property<Integer> iconRadius = theme.property("icon-radius", new Property<>(10));
private static Property<Integer> bgColor = theme.property("bg", Property.color(0xFF1d202d));
private static Property<Integer> fgColor = theme.property("fg", Property.color(0xFFA1A2B8));
private static Property<Integer> iconFg = theme.property("icon-fg", Property.color(0xFFA1A2B8));
private static Property<Integer> iconBg = theme.property("icon-bg", Property.color(0xFF2e3248));
private static Property<Integer> tagBg = theme.property("tag-bg", Property.color(0xFF2e3248));
private static Property<Integer> iconRadius = theme.property("icon-radius", Property.color(10));
private static Property<Integer> font = theme.property("font", Property.font(1));
private static Property<Integer> radius = theme.property("radius", new Property<>(10));
private static Property<Integer> radius = theme.property("radius", Property.color(10));
static {
theme.propertyStateDefault("enabled", "bg", 0xFF1d202d);
@@ -18,13 +18,13 @@ import net.minecraft.util.Identifier;
public class Sidebar extends Element {
private static ThemeManager theme = new ThemeManager("SideBar", "hovering");
private static Property<Integer> bgColor = theme.property("bg-color", new Property<Integer>(0x90000000));
private static Property<Integer> iconFg = theme.property("icon-fg", new Property<Integer>(-1));
private static Property<Integer> iconBg = theme.property("icon-bg", new Property<Integer>(0x00000000));
private static Property<Integer> bgColor = theme.property("bg-color", Property.color(0x90000000));
private static Property<Integer> iconFg = theme.property("icon-fg", Property.color(0xFFFFFFFF));
private static Property<Integer> iconBg = theme.property("icon-bg", Property.color(0x00000000));
private static Property<Integer> cornerRadius = theme.property("corner-radius", new Property<Integer>(10));
private static Property<Integer> iconRadius = theme.property("icon-radius", new Property<Integer>(10));
private static Property<Integer> padding = theme.property("padding", new Property<Integer>(10));
private static Property<Integer> cornerRadius = theme.property("corner-radius", Property.integer(10));
private static Property<Integer> iconRadius = theme.property("icon-radius", Property.integer(10));
private static Property<Integer> padding = theme.property("padding", Property.integer(10));
static {
theme.propertyStateDefault("hovering", "icon-bg", -7643914);
@@ -11,8 +11,8 @@ import net.minecraft.client.render.RenderLayer;
public class Select extends Element {
private static ThemeManager theme = new ThemeManager("Toggle");
private static Property<Integer> fgColor = theme.property("fg-color", new Property<Integer>(0xAAAAAA));
private static Property<Integer> arrowColor = theme.property("arrow-color", new Property<Integer>(0xff8B5CF6));
private static Property<Integer> fgColor = theme.property("fg-color", Property.color(0xAAAAAA));
private static Property<Integer> arrowColor = theme.property("arrow-color", Property.color(0xff8B5CF6));
private static Property<Integer> font = theme.property("font", Property.font(1));
private Property<Integer> prop;
@@ -8,9 +8,9 @@ import org.saturnclient.ui2.RenderScope;
public class Toggle extends Element {
private static ThemeManager theme = new ThemeManager("Toggle", "hovering", "enabled");
private static Property<Integer> bgColor = theme.property("bg-color", new Property<Integer>(0xFF808080));
private static Property<Integer> fgColor = theme.property("fg-color", new Property<Integer>(0xFF909090));
private static Property<Integer> cornerRadius = theme.property("corner-radius", new Property<Integer>(30));
private static Property<Integer> bgColor = theme.property("bg-color", Property.color(0xFF808080));
private static Property<Integer> fgColor = theme.property("fg-color", Property.color(0xFF909090));
private static Property<Integer> cornerRadius = theme.property("corner-radius", Property.integer(30));
static {
theme.propertyStateDefault("enabled", "bg-color", 0xaf8B5CF6);
@@ -9,9 +9,9 @@ import org.saturnclient.ui2.resources.Fonts;
public class Button extends Element {
private static ThemeManager theme = new ThemeManager("Button", "hovering");
private static Property<Integer> bgColor = theme.property("bg-color", new Property<Integer>(0xFF000000));
private static Property<Integer> fgColor = theme.property("fg-color", new Property<Integer>(0xFFFFFFFF));
private static Property<Integer> cornerRadius = theme.property("corner-radius", new Property<Integer>(10));
private static Property<Integer> bgColor = theme.property("bg-color", Property.color(0xFF000000));
private static Property<Integer> fgColor = theme.property("fg-color", Property.color(0xFFFFFFFF));
private static Property<Integer> cornerRadius = theme.property("corner-radius", Property.integer(10));
private static Property<Integer> font = theme.property("font", Property.font(1));
static {
@@ -11,7 +11,7 @@ import net.minecraft.util.Identifier;
public class ClickableTexture extends Element {
private static ThemeManager theme = new ThemeManager("ClickableTexture", "hovering");
private static Property<Integer> fgColor = theme.property("fg-color", new Property<Integer>(0xFFFFFFFF));
private static Property<Integer> fgColor = theme.property("fg-color", Property.color(0xFFFFFFFF));
Identifier sprite;
private Runnable onClick;
@@ -12,13 +12,13 @@ import org.saturnclient.ui2.components.ElementRenderer;
public class Scroll extends Element {
private static ThemeManager theme = new ThemeManager("Scroll");
private static Property<Integer> bgColor = theme.property("bg-color", new Property<Integer>(0x90000000));
private static Property<Integer> scrollBarColor = theme.property("scrollbar-color", new Property<Integer>(-7643914));
private static Property<Integer> bgColor = theme.property("bg-color", Property.color(0x90000000));
private static Property<Integer> scrollBarColor = theme.property("scrollbar-color", Property.color(-7643914));
private static Property<Integer> scrollBarRadius = theme.property("scrollbar-radius", new Property<Integer>(10));
private static Property<Integer> scrollBarWidth = theme.property("scrollbar-width", new Property<Integer>(5));
private static Property<Integer> scrollBarPadding = theme.property("scrollbar-padding", new Property<Integer>(5));
private static Property<Integer> cornerRadius = theme.property("corner-radius", new Property<Integer>(10));
private static Property<Integer> scrollBarRadius = theme.property("scrollbar-radius", Property.integer(10));
private static Property<Integer> scrollBarWidth = theme.property("scrollbar-width", Property.integer(5));
private static Property<Integer> scrollBarPadding = theme.property("scrollbar-padding", Property.integer(5));
private static Property<Integer> cornerRadius = theme.property("corner-radius", Property.integer(10));
int padding = 0;
@@ -8,7 +8,7 @@ import org.saturnclient.ui2.RenderScope;
public class Text extends Element {
private static ThemeManager theme = new ThemeManager("Text");
private static Property<Integer> fgColor = theme.property("fg-color", new Property<Integer>(0xFFFFFFFF));
private static Property<Integer> fgColor = theme.property("fg-color", Property.color(0xFFFFFFFF));
public static Property<Integer> font = theme.property("font", Property.font(1));
private String text;
@@ -11,10 +11,10 @@ import net.minecraft.util.Identifier;
public class TextureButton extends Element {
private static ThemeManager theme = new ThemeManager("TextureButton", "hovering");
private static Property<Integer> bgColor = theme.property("bg-color", new Property<Integer>(0xFF000000));
private static Property<Integer> fgColor = theme.property("fg-color", new Property<Integer>(0xFFFFFFFF));
private static Property<Integer> padding = theme.property("padding", new Property<Integer>(14));
private static Property<Integer> cornerRadius = theme.property("corner-radius", new Property<Integer>(10));
private static Property<Integer> bgColor = theme.property("bg-color", Property.color(0xFF000000));
private static Property<Integer> fgColor = theme.property("fg-color", Property.color(0xFFFFFFFF));
private static Property<Integer> padding = theme.property("padding", Property.integer(14));
private static Property<Integer> cornerRadius = theme.property("corner-radius", Property.integer(10));
static {