Skip to content

Commit

Permalink
fix all those issues I just made (#196)
Browse files Browse the repository at this point in the history
* move to serializedNameConvention annotation instead of individual names

* make class tree stat icons configurable

* fix #194

* checkstyle
  • Loading branch information
ix0rai authored Apr 9, 2024
1 parent 2a9b4a9 commit e2adf61
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import org.quiltmc.config.api.ReflectiveConfig;
import org.quiltmc.config.api.annotations.Comment;
import org.quiltmc.config.api.annotations.Processor;
import org.quiltmc.config.api.annotations.SerializedName;
import org.quiltmc.config.api.annotations.SerializedNameConvention;
import org.quiltmc.config.api.metadata.NamingSchemes;
import org.quiltmc.config.api.serializers.TomlSerializer;
import org.quiltmc.config.api.values.ComplexConfigValue;
import org.quiltmc.config.api.values.ConfigSerializableObject;
Expand All @@ -30,6 +31,8 @@
* {@link NetConfig the networking configuration}, {@link KeyBindConfig the keybinding configuration},
* {@link DockerConfig the docker configuration}, and {@link DecompilerConfig the decompiler configuration}.
*/
@SerializedNameConvention(NamingSchemes.SNAKE_CASE)
@Processor("processChange")
public final class Config extends ReflectiveConfig {
private static final String FORMAT = "toml";
private static final String FAMILY = "enigma";
Expand All @@ -41,55 +44,57 @@ public final class Config extends ReflectiveConfig {
private static final DockerConfig DOCKER = ConfigFactory.create(ENVIRONMENT, FAMILY, "docker", DockerConfig.class);
private static final DecompilerConfig DECOMPILER = ConfigFactory.create(ENVIRONMENT, FAMILY, "decompiler", DecompilerConfig.class);

@SerializedName("language")
@Comment("The currently assigned UI language. This will be an ISO-639 two-letter language code, followed by an underscore and an ISO 3166-1 alpha-2 two-letter country code.")
@Processor("grabPossibleLanguages")
public final TrackedValue<String> language = this.value(I18n.DEFAULT_LANGUAGE);
@SerializedName("scale_factor")
@Comment("A float representing the current size of the UI. 1.0 represents 100% scaling.")
public final TrackedValue<Float> scaleFactor = this.value(1.0f);
@SerializedName("max_recent_projects")
@Comment("The maximum number of saved recent projects, for quickly reopening.")
public final TrackedValue<Integer> maxRecentProjects = this.value(10);
@SerializedName("recent_projects")
public final TrackedValue<ValueList<RecentProject>> recentProjects = this.list(new RecentProject("", ""));
@SerializedName("server_notification_level")
@Comment("Modifies how many notifications you'll get while part of a multiplayer mapping server.")
public final TrackedValue<NotificationManager.ServerNotificationLevel> serverNotificationLevel = this.value(NotificationManager.ServerNotificationLevel.FULL);
@SerializedName("window_size")
@Comment("How big the Enigma window will open, in pixels.")
public final TrackedValue<Vec2i> windowSize = this.value(new Vec2i(1024, 576));
@SerializedName("window_pos")
@Comment("The position the top-left corner of Enigma's window will be the next time it opens, in pixels.")
public final TrackedValue<Vec2i> windowPos = this.value(new Vec2i(0, 0));

@Comment("The settings for the statistics window.")
public final StatsSection stats = new StatsSection();

@Comment("You shouldn't enable options in this section unless you know what you're doing")
@Comment("Contains all features that can be toggled on or off.")
public final FeaturesSection features = new FeaturesSection();

@Comment("You shouldn't enable options in this section unless you know what you're doing!")
public final DevSection development = new DevSection();

/**
* The look and feel stored in the config: do not use this unless setting! Use {@link #activeLookAndFeel} instead,
* since look and feel is final once loaded.
*/
@SerializedName("look_and_feel")
public final TrackedValue<LookAndFeel> lookAndFeel = this.value(LookAndFeel.DEFAULT);
/**
* Look and feel is not modifiable at runtime. I have tried and failed multiple times to get this running.
*/
public static LookAndFeel activeLookAndFeel;

@SerializedName("default_theme")
public final Theme defaultTheme = new Theme(LookAndFeel.DEFAULT);
@SerializedName("darcula_theme")
public final Theme darculaTheme = new Theme(LookAndFeel.DARCULA);
@SerializedName("metal_theme")
public final Theme metalTheme = new Theme(LookAndFeel.METAL);
@SerializedName("system_theme")
public final Theme systemTheme = new Theme(LookAndFeel.SYSTEM);
@SerializedName("none_theme")
public final Theme noneTheme = new Theme(LookAndFeel.NONE);

@SuppressWarnings("unused")
public void processChange(org.quiltmc.config.api.Config.Builder builder) {
builder.callback(config -> {
for (var value : config.values()) {
if (value.key().length() > 1 && value.key().getKeyComponent(0).equals("development") && value.value().equals(true)) {
this.development.anyEnabled = true;
}
}
});
}

@SuppressWarnings("all")
public static Config main() {
return MAIN;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,31 @@
import org.quiltmc.config.api.ReflectiveConfig;
import org.quiltmc.config.api.annotations.Comment;
import org.quiltmc.config.api.annotations.Processor;
import org.quiltmc.config.api.annotations.SerializedName;
import org.quiltmc.config.api.annotations.SerializedNameConvention;
import org.quiltmc.config.api.metadata.NamingSchemes;
import org.quiltmc.config.api.values.TrackedValue;
import org.quiltmc.config.api.values.ValueMap;
import org.quiltmc.enigma.impl.source.vineflower.VineflowerPreferences;

import java.util.Map;

@SerializedNameConvention(NamingSchemes.SNAKE_CASE)
public class DecompilerConfig extends ReflectiveConfig {
public DecompilerConfig() {
VineflowerPreferences.OPTIONS.putAll(this.vineflower.stringValues.value());
VineflowerPreferences.OPTIONS.putAll(this.vineflower.intValues.value());
VineflowerPreferences.OPTIONS.putAll(this.vineflower.booleanValues.value());
}

@SerializedName("active_decompiler")
public final TrackedValue<Decompiler> activeDecompiler = this.value(Decompiler.VINEFLOWER);
@Comment("The options passed to the Vineflower decompiler. What these do can be found here: https://vineflower.org/usage/.")
public final VineflowerSection vineflower = new VineflowerSection();

public static final class VineflowerSection extends Section {
@SerializedName("string_values")
@Processor("processStrings")
public final TrackedValue<ValueMap<String>> stringValues = this.map("").build();
@SerializedName("int_values")
@Processor("processIntegers")
public final TrackedValue<ValueMap<Integer>> intValues = this.map(0).build();
@SerializedName("boolean_values")
@Processor("processBooleans")
public final TrackedValue<ValueMap<Boolean>> booleanValues = this.map(true).build();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package org.quiltmc.enigma.gui.config;

import com.google.gson.annotations.SerializedName;
import org.quiltmc.config.api.ReflectiveConfig;
import org.quiltmc.config.api.annotations.Processor;
import org.quiltmc.config.api.annotations.SerializedNameConvention;
import org.quiltmc.config.api.metadata.NamingSchemes;
import org.quiltmc.config.api.values.TrackedValue;
import org.quiltmc.enigma.api.source.DecompiledClassSource;
import org.quiltmc.enigma.gui.network.IntegratedEnigmaClient;

@SerializedNameConvention(NamingSchemes.SNAKE_CASE)
public class DevSection extends ReflectiveConfig.Section {
@SerializedName("show_mapping_source_plugin")
public transient boolean anyEnabled = false;

public final TrackedValue<Boolean> showMappingSourcePlugin = this.value(false);

@SerializedName("debug_token_highlights")
@Processor("processDebugTokenHighlights")
public final TrackedValue<Boolean> debugTokenHighlights = this.value(false);

@SerializedName("log_client_packets")
@Processor("processLogClientPackets")
public final TrackedValue<Boolean> logClientPackets = this.value(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import org.quiltmc.config.api.ReflectiveConfig;
import org.quiltmc.config.api.annotations.Comment;
import org.quiltmc.config.api.annotations.SerializedName;
import org.quiltmc.config.api.annotations.SerializedNameConvention;
import org.quiltmc.config.api.metadata.NamingSchemes;
import org.quiltmc.config.api.values.ComplexConfigValue;
import org.quiltmc.config.api.values.ConfigSerializableObject;
import org.quiltmc.config.api.values.TrackedValue;
Expand All @@ -14,28 +15,21 @@
import java.util.HashMap;
import java.util.Map;

@SerializedNameConvention(NamingSchemes.SNAKE_CASE)
public class DockerConfig extends ReflectiveConfig {
@SerializedName("left_vertical_divider_location")
public final TrackedValue<Integer> leftVerticalDividerLocation = this.value(300);
@SerializedName("right_vertical_divider_location")
public final TrackedValue<Integer> rightVerticalDividerLocation = this.value(300);
@SerializedName("left_horizontal_divider_location")
public final TrackedValue<Integer> leftHorizontalDividerLocation = this.value(300);
@SerializedName("right_horizontal_divider_location")
public final TrackedValue<Integer> rightHorizontalDividerLocation = this.value(700);
@Comment("A bodge to properly offset the right divider location depending on UI state.")
@SerializedName("saved_with_left_docker_open")
public final TrackedValue<Boolean> savedWithLeftDockerOpen = this.value(true);

@Comment("The location of each docker's button in the button sidebars.")
@Comment("Encoded with the side (RIGHT or LEFT) followed by a semicolon (;) and the vertical location (TOP or BOTTOM).")
@SerializedName("button_locations")
public final TrackedValue<ValueMap<Docker.Location>> buttonLocations = this.map(new Docker.Location(Docker.Side.LEFT, Docker.VerticalLocation.TOP)).build();
@Comment("The currently active dockers on the left side of the UI.")
@SerializedName("left_dockers")
public final TrackedValue<SelectedDockers> leftDockers = this.value(new SelectedDockers("", "", "all_classes"));
@Comment("The currently active dockers on the right side of the UI.")
@SerializedName("right_dockers")
public final TrackedValue<SelectedDockers> rightDockers = this.value(new SelectedDockers("", "", "structure"));

public SelectedDockers getSelectedDockers(Docker.Side side) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.quiltmc.enigma.gui.config;

import org.quiltmc.config.api.ReflectiveConfig;
import org.quiltmc.config.api.annotations.Comment;
import org.quiltmc.config.api.annotations.SerializedNameConvention;
import org.quiltmc.config.api.metadata.NamingSchemes;
import org.quiltmc.config.api.values.TrackedValue;

@SerializedNameConvention(NamingSchemes.SNAKE_CASE)
public class FeaturesSection extends ReflectiveConfig.Section {
@Comment("Enables statistic icons in the class tree. This has a major performance impact on JAR files with lots of classes.")
public final TrackedValue<Boolean> enableClassTreeStatIcons = this.value(true);
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package org.quiltmc.enigma.gui.config;

import org.quiltmc.config.api.ReflectiveConfig;
import org.quiltmc.config.api.annotations.SerializedName;
import org.quiltmc.config.api.annotations.SerializedNameConvention;
import org.quiltmc.config.api.metadata.NamingSchemes;
import org.quiltmc.config.api.values.TrackedValue;
import org.quiltmc.config.api.values.ValueList;
import org.quiltmc.config.api.values.ValueMap;
import org.quiltmc.enigma.gui.config.keybind.KeyBind;

@SerializedNameConvention(NamingSchemes.SNAKE_CASE)
public final class KeyBindConfig extends ReflectiveConfig {
@SerializedName("key_codes")
public final TrackedValue<ValueMap<ValueList<String>>> keyCodes = this.map(ValueList.create("")).build();

public String[] getKeyCodes(KeyBind keyBind) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@

import org.quiltmc.config.api.ReflectiveConfig;
import org.quiltmc.config.api.annotations.Comment;
import org.quiltmc.config.api.annotations.SerializedName;
import org.quiltmc.config.api.annotations.SerializedNameConvention;
import org.quiltmc.config.api.metadata.NamingSchemes;
import org.quiltmc.config.api.values.TrackedValue;
import org.quiltmc.enigma.network.EnigmaServer;

@SerializedNameConvention(NamingSchemes.SNAKE_CASE)
public final class NetConfig extends ReflectiveConfig {
@SerializedName("username")
@Comment("Your username for multiplayer mapping. Defaults to the system username.")
public final TrackedValue<String> username = this.value(System.getProperty("user.name", "user"));
@SerializedName("password")
public final TrackedValue<String> password = this.value("");
@SerializedName("remote_address")
public final TrackedValue<String> remoteAddress = this.value("");
@SerializedName("server_password")
public final TrackedValue<String> serverPassword = this.value("");
@SerializedName("server_port")
@Comment("The network port of this server. Interesting fact! The default was decided pretty much at random in the Fabric discord: https://discordapp.com/channels/507304429255393322/566418023372816394/700292322918793347 (server: https://fabricmc.net/discuss/). You can still blame 2xsaiko if it conflicts with anything.")
public final TrackedValue<Integer> serverPort = this.value(EnigmaServer.DEFAULT_PORT);
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package org.quiltmc.enigma.gui.config;

import org.quiltmc.config.api.ReflectiveConfig;
import org.quiltmc.config.api.annotations.SerializedName;
import org.quiltmc.config.api.annotations.SerializedNameConvention;
import org.quiltmc.config.api.metadata.NamingSchemes;
import org.quiltmc.config.api.values.TrackedValue;

@SerializedNameConvention(NamingSchemes.SNAKE_CASE)
public class StatsSection extends ReflectiveConfig.Section {
@SerializedName("last_selected_dir")
public final TrackedValue<String> lastSelectedDir = this.value("");
@SerializedName("last_top_level_package")
public final TrackedValue<String> lastTopLevelPackage = this.value("");
@SerializedName("should_include_synthetic_parameters")
public final TrackedValue<Boolean> shouldIncludeSyntheticParameters = this.value(false);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import org.quiltmc.config.api.ReflectiveConfig;
import org.quiltmc.config.api.annotations.Comment;
import org.quiltmc.config.api.annotations.SerializedName;
import org.quiltmc.config.api.annotations.SerializedNameConvention;
import org.quiltmc.config.api.metadata.NamingSchemes;
import org.quiltmc.config.api.values.ComplexConfigValue;
import org.quiltmc.config.api.values.ConfigSerializableObject;
import org.quiltmc.config.api.values.TrackedValue;
Expand All @@ -11,26 +12,21 @@
import java.awt.Color;
import java.awt.Font;

@SerializedNameConvention(NamingSchemes.SNAKE_CASE)
public class Theme extends ReflectiveConfig.Section {
public final transient LookAndFeel lookAndFeel;
public Theme(LookAndFeel lookAndFeel) {
this.lookAndFeel = lookAndFeel;
}

@Comment("Colors are encoded in the RGBA format.")
@SerializedName("colors")
public final Colors colors = new Colors();
@SerializedName("fonts")
public final Fonts fonts = new Fonts();

public static class Fonts extends ReflectiveConfig.Section {
@SerializedName("default_bold")
public final TrackedValue<SerializableFont> defaultBold = this.value(new SerializableFont(Font.decode(Font.DIALOG).deriveFont(Font.BOLD)));
@SerializedName("default_normal")
public final TrackedValue<SerializableFont> defaultNormal = this.value(new SerializableFont(Font.decode(Font.DIALOG)));
@SerializedName("small")
public final TrackedValue<SerializableFont> small = this.value(new SerializableFont(Font.decode(Font.DIALOG)));
@SerializedName("editor")
public final TrackedValue<SerializableFont> editor = this.value(new SerializableFont(Font.decode(Font.MONOSPACED)));

public static class SerializableFont extends Font implements ConfigSerializableObject<ValueMap<String>> {
Expand Down Expand Up @@ -76,58 +72,32 @@ public String toString() {
* Default values are for light themes.
*/
public static class Colors extends ReflectiveConfig.Section {
@SerializedName("line_numbers_foreground")
public final TrackedValue<SerializableColor> lineNumbersForeground = this.value(new SerializableColor(0xFF333300));
@SerializedName("line_numbers_background")
public final TrackedValue<SerializableColor> lineNumbersBackground = this.value(new SerializableColor(0xFFEEEEFF));
@SerializedName("line_numbers_selected")
public final TrackedValue<SerializableColor> lineNumbersSelected = this.value(new SerializableColor(0xFFCCCCEE));
@SerializedName("obfuscated")
public final TrackedValue<SerializableColor> obfuscated = this.value(new SerializableColor(0xFFFFDCDC));
@SerializedName("obfuscated_outline")
public final TrackedValue<SerializableColor> obfuscatedOutline = this.value(new SerializableColor(0xFFA05050));

@SerializedName("proposed")
public final TrackedValue<SerializableColor> proposed = this.value(new SerializableColor(0x27000000));
@SerializedName("proposed_outline")
public final TrackedValue<SerializableColor> proposedOutline = this.value(new SerializableColor(0xBF000000));

@SerializedName("deobfuscated")
public final TrackedValue<SerializableColor> deobfuscated = this.value(new SerializableColor(0xFFDCFFDC));
@SerializedName("deobfuscated_outline")
public final TrackedValue<SerializableColor> deobfuscatedOutline = this.value(new SerializableColor(0xFF50A050));

@SerializedName("editor_background")
public final TrackedValue<SerializableColor> editorBackground = this.value(new SerializableColor(0xFFFFFFFF));
@SerializedName("highlight")
public final TrackedValue<SerializableColor> highlight = this.value(new SerializableColor(0xFF3333EE));
@SerializedName("caret")
public final TrackedValue<SerializableColor> caret = this.value(new SerializableColor(0xFF000000));
@SerializedName("selection_highlight")
public final TrackedValue<SerializableColor> selectionHighlight = this.value(new SerializableColor(0xFF000000));
@SerializedName("string")
public final TrackedValue<SerializableColor> string = this.value(new SerializableColor(0xFFCC6600));
@SerializedName("number")
public final TrackedValue<SerializableColor> number = this.value(new SerializableColor(0xFF999933));
@SerializedName("operator")
public final TrackedValue<SerializableColor> operator = this.value(new SerializableColor(0xFF000000));
@SerializedName("delimiter")
public final TrackedValue<SerializableColor> delimiter = this.value(new SerializableColor(0xFF000000));
@SerializedName("type")
public final TrackedValue<SerializableColor> type = this.value(new SerializableColor(0xFF000000));
@SerializedName("identifier")
public final TrackedValue<SerializableColor> identifier = this.value(new SerializableColor(0xFF000000));
@SerializedName("comment")
public final TrackedValue<SerializableColor> comment = this.value(new SerializableColor(0xFF339933));
@SerializedName("text")
public final TrackedValue<SerializableColor> text = this.value(new SerializableColor(0xFF000000));

@SerializedName("debug_token")
public final TrackedValue<SerializableColor> debugToken = this.value(new SerializableColor(0xFFD9BEF9));
@SerializedName("debug_token_outline")
public final TrackedValue<SerializableColor> debugTokenOutline = this.value(new SerializableColor(0xFFBD93F9));

@SerializedName("dock_highlight")
public final TrackedValue<SerializableColor> dockHighlight = this.value(new SerializableColor(0xFF0000FF));

public static class SerializableColor extends Color implements ConfigSerializableObject<String> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void display(Entry<?> entry) {
this.tree.expandPath(path);
this.tree.setSelectionRow(this.tree.getRowForPath(path));
} else {
setupTree(null);
this.setupTree(null);
}

this.setVisible(true);
Expand Down
Loading

0 comments on commit e2adf61

Please sign in to comment.