Skip to content

Commit

Permalink
reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
Prospector committed Jun 16, 2024
1 parent ea135e4 commit 73829e6
Show file tree
Hide file tree
Showing 46 changed files with 981 additions and 472 deletions.
15 changes: 1 addition & 14 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,8 @@ charset = utf-8
end_of_line = lf
insert_final_newline = true
tab_width = 4

[*.gradle]
indent_style = tab

[*.java]
indent_style = tab

[*.json]
indent_style = space
indent_size = 2

[*.properties]
indent_style = space
indent_size = 2

[.editorconfig]
indent_style = space
indent_size = 4
indent_size = 2
23 changes: 11 additions & 12 deletions src/main/java/com/terraformersmc/modmenu/ModMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ public class ModMenu implements ClientModInitializer {
public static final Gson GSON_MINIFIED;

static {
GsonBuilder builder = new GsonBuilder()
.registerTypeHierarchyAdapter(Enum.class, new EnumToLowerCaseJsonConverter())
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);
GsonBuilder builder = new GsonBuilder().registerTypeHierarchyAdapter(Enum.class,
new EnumToLowerCaseJsonConverter()
)
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);
GSON = builder.setPrettyPrinting().create();
GSON_MINIFIED = builder.create();
}
Expand Down Expand Up @@ -191,11 +192,7 @@ public static String getDisplayedModCount() {
if (!includeLibraries && isLibrary) {
return false;
}
if (!includeHidden && mod.isHidden()) {
return false;
}

return true;
return includeHidden || !mod.isHidden();
}).count());
}
return NumberFormat.getInstance().format(cachedDisplayedModCount);
Expand All @@ -204,10 +201,12 @@ public static String getDisplayedModCount() {
public static Text createModsButtonText(boolean title) {
var titleStyle = ModMenuConfig.MODS_BUTTON_STYLE.getValue();
var gameMenuStyle = ModMenuConfig.GAME_MENU_BUTTON_STYLE.getValue();
var isIcon = title ? titleStyle == ModMenuConfig.TitleMenuButtonStyle.ICON : gameMenuStyle ==
ModMenuConfig.GameMenuButtonStyle.ICON;
var isShort = title ? titleStyle == ModMenuConfig.TitleMenuButtonStyle.SHRINK : gameMenuStyle ==
ModMenuConfig.GameMenuButtonStyle.REPLACE_BUGS;
var isIcon = title ?
titleStyle == ModMenuConfig.TitleMenuButtonStyle.ICON :
gameMenuStyle == ModMenuConfig.GameMenuButtonStyle.ICON;
var isShort = title ?
titleStyle == ModMenuConfig.TitleMenuButtonStyle.SHRINK :
gameMenuStyle == ModMenuConfig.GameMenuButtonStyle.REPLACE_BUGS;
MutableText modsText = ModMenuScreenTexts.TITLE.copy();
if (ModMenuConfig.MOD_COUNT_LOCATION.getValue().isOnModsButton() && !isIcon) {
String count = ModMenu.getDisplayedModCount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.terraformersmc.modmenu.gui.ModMenuOptionsScreen;
import com.terraformersmc.modmenu.util.mod.fabric.FabricLoaderUpdateChecker;
import com.terraformersmc.modmenu.util.mod.quilt.QuiltLoaderUpdateChecker;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.option.OptionsScreen;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,5 @@ default Map<String, UpdateChecker> getProvidedUpdateCheckers() {
* provided by a modpack.
*/
default void attachModpackBadges(Consumer<String> consumer) {
return;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
* Supported update channels, in ascending order by stability.
*/
public enum UpdateChannel {
ALPHA,
BETA,
RELEASE;
ALPHA, BETA, RELEASE;

/**
* @return the user's preferred update channel.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface FileOnlyConfig {
}
public @interface FileOnlyConfig { }
56 changes: 32 additions & 24 deletions src/main/java/com/terraformersmc/modmenu/config/ModMenuConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@ public class ModMenuConfig {
public static final BooleanConfigOption COUNT_LIBRARIES = new BooleanConfigOption("count_libraries", true);
public static final BooleanConfigOption COMPACT_LIST = new BooleanConfigOption("compact_list", false);
public static final BooleanConfigOption COUNT_CHILDREN = new BooleanConfigOption("count_children", true);
public static final EnumConfigOption<TitleMenuButtonStyle> MODS_BUTTON_STYLE = new EnumConfigOption<>("mods_button_style",
TitleMenuButtonStyle.CLASSIC
public static final EnumConfigOption<TitleMenuButtonStyle> MODS_BUTTON_STYLE = new EnumConfigOption<>(
"mods_button_style",
TitleMenuButtonStyle.CLASSIC
);
public static final EnumConfigOption<GameMenuButtonStyle> GAME_MENU_BUTTON_STYLE = new EnumConfigOption<>("game_menu_button_style",
GameMenuButtonStyle.REPLACE_BUGS
public static final EnumConfigOption<GameMenuButtonStyle> GAME_MENU_BUTTON_STYLE = new EnumConfigOption<>(
"game_menu_button_style",
GameMenuButtonStyle.REPLACE_BUGS
);
public static final BooleanConfigOption COUNT_HIDDEN_MODS = new BooleanConfigOption("count_hidden_mods", true);
public static final EnumConfigOption<ModCountLocation> MOD_COUNT_LOCATION = new EnumConfigOption<>("mod_count_location",
ModCountLocation.TITLE_SCREEN
public static final EnumConfigOption<ModCountLocation> MOD_COUNT_LOCATION = new EnumConfigOption<>(
"mod_count_location",
ModCountLocation.TITLE_SCREEN
);
public static final BooleanConfigOption HIDE_MOD_LINKS = new BooleanConfigOption("hide_mod_links", false);
public static final BooleanConfigOption SHOW_LIBRARIES = new BooleanConfigOption("show_libraries", false);
Expand All @@ -38,10 +41,14 @@ public class ModMenuConfig {
public static final BooleanConfigOption EASTER_EGGS = new BooleanConfigOption("easter_eggs", true);
public static final BooleanConfigOption RANDOM_JAVA_COLORS = new BooleanConfigOption("random_java_colors", false);
public static final BooleanConfigOption TRANSLATE_NAMES = new BooleanConfigOption("translate_names", true);
public static final BooleanConfigOption TRANSLATE_DESCRIPTIONS = new BooleanConfigOption("translate_descriptions", true);
public static final BooleanConfigOption TRANSLATE_DESCRIPTIONS = new BooleanConfigOption("translate_descriptions",
true
);
public static final BooleanConfigOption UPDATE_CHECKER = new BooleanConfigOption("update_checker", true);
public static final BooleanConfigOption BUTTON_UPDATE_BADGE = new BooleanConfigOption("button_update_badge", true);
public static final EnumConfigOption<UpdateChannel> UPDATE_CHANNEL = new EnumConfigOption<>("update_channel", UpdateChannel.RELEASE);
public static final EnumConfigOption<UpdateChannel> UPDATE_CHANNEL = new EnumConfigOption<>("update_channel",
UpdateChannel.RELEASE
);
public static final BooleanConfigOption QUICK_CONFIGURE = new BooleanConfigOption("quick_configure", true);

@FileOnlyConfig
Expand All @@ -53,13 +60,20 @@ public class ModMenuConfig {
@FileOnlyConfig
public static final BooleanConfigOption CONFIG_MODE = new BooleanConfigOption("config_mode", false);
@FileOnlyConfig
public static final BooleanConfigOption DISABLE_DRAG_AND_DROP = new BooleanConfigOption("disable_drag_and_drop", false);
public static final BooleanConfigOption DISABLE_DRAG_AND_DROP = new BooleanConfigOption("disable_drag_and_drop",
false
);
@FileOnlyConfig
public static final StringSetConfigOption HIDDEN_MODS = new StringSetConfigOption("hidden_mods", new HashSet<>());
@FileOnlyConfig
public static final StringSetConfigOption HIDDEN_CONFIGS = new StringSetConfigOption("hidden_configs", new HashSet<>());
public static final StringSetConfigOption HIDDEN_CONFIGS = new StringSetConfigOption("hidden_configs",
new HashSet<>()
);
@FileOnlyConfig
public static final StringSetConfigOption DISABLE_UPDATE_CHECKER = new StringSetConfigOption("disable_update_checker", new HashSet<>());
public static final StringSetConfigOption DISABLE_UPDATE_CHECKER = new StringSetConfigOption(
"disable_update_checker",
new HashSet<>()
);

public static SimpleOption<?>[] asOptions() {
ArrayList<SimpleOption<?>> options = new ArrayList<>();
Expand All @@ -77,8 +91,8 @@ public static SimpleOption<?>[] asOptions() {
}

public enum Sorting {
ASCENDING(Comparator.comparing(mod -> mod.getTranslatedName().toLowerCase(Locale.ROOT))),
DESCENDING(ASCENDING.getComparator().reversed());
ASCENDING(Comparator.comparing(mod -> mod.getTranslatedName()
.toLowerCase(Locale.ROOT))), DESCENDING(ASCENDING.getComparator().reversed());

private final Comparator<Mod> comparator;

Expand All @@ -92,10 +106,9 @@ public Comparator<Mod> getComparator() {
}

public enum ModCountLocation {
TITLE_SCREEN(true, false),
MODS_BUTTON(false, true),
TITLE_SCREEN_AND_MODS_BUTTON(true, true),
NONE(false, false);
TITLE_SCREEN(true, false), MODS_BUTTON(false, true), TITLE_SCREEN_AND_MODS_BUTTON(true, true), NONE(false,
false
);

private final boolean titleScreen, modsButton;

Expand All @@ -114,15 +127,10 @@ public boolean isOnModsButton() {
}

public enum TitleMenuButtonStyle {
CLASSIC(),
REPLACE_REALMS(),
SHRINK(),
ICON();
CLASSIC(), REPLACE_REALMS(), SHRINK(), ICON()
}

public enum GameMenuButtonStyle {
REPLACE_BUGS,
BELOW_BUGS,
ICON;
REPLACE_BUGS, BELOW_BUGS, ICON
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import com.terraformersmc.modmenu.config.option.StringSetConfigOption;
import net.fabricmc.loader.api.FabricLoader;

import java.io.*;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
Expand Down Expand Up @@ -51,16 +53,24 @@ private static void load() {
JsonArray jsonArray = json.getAsJsonArray(field.getName().toLowerCase(Locale.ROOT));
if (jsonArray != null) {
StringSetConfigOption option = (StringSetConfigOption) field.get(null);
ConfigOptionStorage.setStringSet(option.getKey(), Sets.newHashSet(jsonArray).stream().map(JsonElement::getAsString).collect(Collectors.toSet()));
ConfigOptionStorage.setStringSet(
option.getKey(),
Sets.newHashSet(jsonArray)
.stream()
.map(JsonElement::getAsString)
.collect(Collectors.toSet())
);
}
} else if (BooleanConfigOption.class.isAssignableFrom(field.getType())) {
JsonPrimitive jsonPrimitive = json.getAsJsonPrimitive(field.getName().toLowerCase(Locale.ROOT));
JsonPrimitive jsonPrimitive = json.getAsJsonPrimitive(field.getName()
.toLowerCase(Locale.ROOT));
if (jsonPrimitive != null && jsonPrimitive.isBoolean()) {
BooleanConfigOption option = (BooleanConfigOption) field.get(null);
ConfigOptionStorage.setBoolean(option.getKey(), jsonPrimitive.getAsBoolean());
}
} else if (EnumConfigOption.class.isAssignableFrom(field.getType()) && field.getGenericType() instanceof ParameterizedType) {
JsonPrimitive jsonPrimitive = json.getAsJsonPrimitive(field.getName().toLowerCase(Locale.ROOT));
JsonPrimitive jsonPrimitive = json.getAsJsonPrimitive(field.getName()
.toLowerCase(Locale.ROOT));
if (jsonPrimitive != null && jsonPrimitive.isString()) {
Type generic = ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0];
if (generic instanceof Class<?>) {
Expand Down Expand Up @@ -99,7 +109,9 @@ public static void save() {
if (Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers())) {
if (BooleanConfigOption.class.isAssignableFrom(field.getType())) {
BooleanConfigOption option = (BooleanConfigOption) field.get(null);
config.addProperty(field.getName().toLowerCase(Locale.ROOT), ConfigOptionStorage.getBoolean(option.getKey()));
config.addProperty(field.getName().toLowerCase(Locale.ROOT),
ConfigOptionStorage.getBoolean(option.getKey())
);
} else if (StringSetConfigOption.class.isAssignableFrom(field.getType())) {
StringSetConfigOption option = (StringSetConfigOption) field.get(null);
JsonArray array = new JsonArray();
Expand All @@ -109,7 +121,11 @@ public static void save() {
Type generic = ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0];
if (generic instanceof Class<?>) {
EnumConfigOption<?> option = (EnumConfigOption<?>) field.get(null);
config.addProperty(field.getName().toLowerCase(Locale.ROOT), ConfigOptionStorage.getEnumTypeless(option.getKey(), (Class<Enum<?>>) generic).name().toLowerCase(Locale.ROOT));
config.addProperty(field.getName().toLowerCase(Locale.ROOT),
ConfigOptionStorage.getEnumTypeless(option.getKey(), (Class<Enum<?>>) generic)
.name()
.toLowerCase(Locale.ROOT)
);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,25 @@ public boolean getDefaultValue() {
}

public Text getButtonText() {
return ScreenTexts.composeGenericOptionText(Text.translatable(translationKey), getValue() ? enabledText : disabledText);
return ScreenTexts.composeGenericOptionText(Text.translatable(translationKey),
getValue() ? enabledText : disabledText
);
}

@Override
public SimpleOption<Boolean> asOption() {
if (enabledText != null && disabledText != null) {
return new SimpleOption<>(translationKey, SimpleOption.emptyTooltip(),
(text, value) -> value ? enabledText : disabledText, SimpleOption.BOOLEAN, getValue(),
newValue -> ConfigOptionStorage.setBoolean(key, newValue));
return new SimpleOption<>(translationKey,
SimpleOption.emptyTooltip(),
(text, value) -> value ? enabledText : disabledText,
SimpleOption.BOOLEAN,
getValue(),
newValue -> ConfigOptionStorage.setBoolean(key, newValue)
);
}
return SimpleOption.ofBoolean(translationKey, getValue(), (value) -> ConfigOptionStorage.setBoolean(key, value));
return SimpleOption.ofBoolean(translationKey,
getValue(),
(value) -> ConfigOptionStorage.setBoolean(key, value)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,17 @@ public Text getButtonText() {

@Override
public SimpleOption<E> asOption() {
return new SimpleOption<>(translationKey, SimpleOption.emptyTooltip(),
(text, value) -> getValueText(this, value),
new SimpleOption.PotentialValuesBasedCallbacks<>(Arrays.asList(enumClass.getEnumConstants()),
Codec.STRING.xmap(
string -> Arrays.stream(enumClass.getEnumConstants()).filter(e -> e.name().toLowerCase().equals(string)).findAny().orElse(null),
newValue -> newValue.name().toLowerCase()
)),
getValue(), value -> ConfigOptionStorage.setEnum(key, value));
return new SimpleOption<>(translationKey,
SimpleOption.emptyTooltip(),
(text, value) -> getValueText(this, value),
new SimpleOption.PotentialValuesBasedCallbacks<>(Arrays.asList(enumClass.getEnumConstants()),
Codec.STRING.xmap(string -> Arrays.stream(enumClass.getEnumConstants())
.filter(e -> e.name().toLowerCase().equals(string))
.findAny()
.orElse(null), newValue -> newValue.name().toLowerCase())
),
getValue(),
value -> ConfigOptionStorage.setEnum(key, value)
);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.terraformersmc.modmenu.config.option;

import net.minecraft.text.Text;

import com.terraformersmc.modmenu.util.TranslationUtil;
import net.minecraft.text.Text;

import java.util.Set;

Expand Down
Loading

0 comments on commit 73829e6

Please sign in to comment.