Przeglądaj źródła

Rename ConfigCategory to ConfigGroup

Lortseam 4 lat temu
rodzic
commit
bf37076e86

+ 6 - 6
src/main/java/me/lortseam/completeconfig/Config.java

@@ -3,7 +3,7 @@ package me.lortseam.completeconfig;
 import com.google.gson.GsonBuilder;
 import com.google.gson.JsonElement;
 import com.google.gson.JsonSyntaxException;
-import me.lortseam.completeconfig.api.ConfigCategory;
+import me.lortseam.completeconfig.api.ConfigGroup;
 import me.lortseam.completeconfig.data.CollectionMap;
 import me.lortseam.completeconfig.serialization.CollectionMapDeserializer;
 import org.apache.logging.log4j.LogManager;
@@ -15,19 +15,19 @@ public class Config extends CollectionMap {
 
     private static final Logger LOGGER = LogManager.getLogger();
 
-    Config(String modID, List<ConfigCategory> topLevelCategories, JsonElement json) {
+    Config(String modID, List<ConfigGroup> topLevelGroups, JsonElement json) {
         super("config." + modID);
-        for (ConfigCategory category : topLevelCategories) {
-            if (!fill(modTranslationKey, category)) {
+        for (ConfigGroup group : topLevelGroups) {
+            if (!fill(modTranslationKey, group)) {
                 continue;
             }
             try {
                 new GsonBuilder()
-                        .registerTypeAdapter(CollectionMapDeserializer.TYPE, new CollectionMapDeserializer(this, category.getConfigCategoryID()))
+                        .registerTypeAdapter(CollectionMapDeserializer.TYPE, new CollectionMapDeserializer(this, group.getConfigGroupID()))
                         .create()
                         .fromJson(json, CollectionMapDeserializer.TYPE);
             } catch (JsonSyntaxException e) {
-                LOGGER.warn("[CompleteConfig] An error occurred while trying to load the config for category " + category.getClass());
+                LOGGER.warn("[CompleteConfig] An error occurred while trying to load the config for group " + group.getClass());
             }
         }
     }

+ 7 - 7
src/main/java/me/lortseam/completeconfig/ConfigBuilder.java

@@ -1,6 +1,6 @@
 package me.lortseam.completeconfig;
 
-import me.lortseam.completeconfig.api.ConfigCategory;
+import me.lortseam.completeconfig.api.ConfigGroup;
 import me.lortseam.completeconfig.api.ConfigOwner;
 import me.lortseam.completeconfig.gui.GuiBuilder;
 
@@ -18,7 +18,7 @@ public final class ConfigBuilder {
     private final String modID;
     private final String[] branch;
     private final Class<? extends ConfigOwner> owner;
-    private final List<ConfigCategory> topLevelCategories = new ArrayList<>();
+    private final List<ConfigGroup> topLevelGroups = new ArrayList<>();
     private GuiBuilder guiBuilder;
 
     private ConfigBuilder(String modID, String[] branch, Class<? extends ConfigOwner> owner) {
@@ -28,13 +28,13 @@ public final class ConfigBuilder {
     }
 
     /**
-     * Adds one or more top-level categories to the config.
+     * Adds one or more top-level groups to the config.
      *
-     * @param categories one or more top-level categories
+     * @param groups one or more top-level groups
      * @return this config builder
      */
-    public ConfigBuilder add(ConfigCategory... categories) {
-        topLevelCategories.addAll(Arrays.asList(categories));
+    public ConfigBuilder add(ConfigGroup... groups) {
+        topLevelGroups.addAll(Arrays.asList(groups));
         return this;
     }
 
@@ -56,7 +56,7 @@ public final class ConfigBuilder {
      * @return the handler associated with the created config
      */
     public ConfigHandler finish() {
-        return ConfigHandler.registerConfig(modID, branch, owner, topLevelCategories, guiBuilder);
+        return ConfigHandler.registerConfig(modID, branch, owner, topLevelGroups, guiBuilder);
     }
 
 }

+ 6 - 6
src/main/java/me/lortseam/completeconfig/ConfigHandler.java

@@ -1,7 +1,7 @@
 package me.lortseam.completeconfig;
 
 import com.google.gson.*;
-import me.lortseam.completeconfig.api.ConfigCategory;
+import me.lortseam.completeconfig.api.ConfigGroup;
 import me.lortseam.completeconfig.api.ConfigOwner;
 import me.lortseam.completeconfig.gui.GuiBuilder;
 import me.lortseam.completeconfig.serialization.CollectionSerializer;
@@ -41,11 +41,11 @@ public final class ConfigHandler {
         }));
     }
 
-    static ConfigHandler registerConfig(String modID, String[] branch, Class<? extends ConfigOwner> owner, List<ConfigCategory> topLevelCategories, GuiBuilder guiBuilder) {
+    static ConfigHandler registerConfig(String modID, String[] branch, Class<? extends ConfigOwner> owner, List<ConfigGroup> topLevelGroups, GuiBuilder guiBuilder) {
         if (HANDLERS.containsKey(owner)) {
             throw new IllegalArgumentException("The specified owner " + owner + " already created a config!");
         }
-        if (topLevelCategories.isEmpty()) {
+        if (topLevelGroups.isEmpty()) {
             LOGGER.warn("[CompleteConfig] Owner " + owner + " of mod " + modID + " tried to create an empty config!");
             return null;
         }
@@ -55,7 +55,7 @@ public final class ConfigHandler {
         if (HANDLERS.values().stream().anyMatch(handler -> handler.jsonPath.equals(jsonPath))) {
             throw new IllegalArgumentException("A config of the mod " + modID + " with the specified branch " + Arrays.toString(branch) + " already exists!");
         }
-        ConfigHandler handler = new ConfigHandler(modID, jsonPath, topLevelCategories, guiBuilder);
+        ConfigHandler handler = new ConfigHandler(modID, jsonPath, topLevelGroups, guiBuilder);
         HANDLERS.put(owner, handler);
         return handler;
     }
@@ -74,9 +74,9 @@ public final class ConfigHandler {
     private final Config config;
     private GuiBuilder guiBuilder;
 
-    private ConfigHandler(String modID, Path jsonPath, List<ConfigCategory> topLevelCategories, GuiBuilder guiBuilder) {
+    private ConfigHandler(String modID, Path jsonPath, List<ConfigGroup> topLevelGroups, GuiBuilder guiBuilder) {
         this.jsonPath = jsonPath;
-        config = new Config(modID, topLevelCategories, load());
+        config = new Config(modID, topLevelGroups, load());
         this.guiBuilder = guiBuilder;
     }
 

+ 0 - 21
src/main/java/me/lortseam/completeconfig/api/ConfigCategory.java

@@ -1,21 +0,0 @@
-package me.lortseam.completeconfig.api;
-
-import com.google.common.base.CaseFormat;
-
-/**
- * A container of config entries which has a unique identifier additionally.
- */
-public interface ConfigCategory extends ConfigEntryContainer {
-
-    /**
-     * Used to identify this category. Defaults to the class name.
-     *
-     * <p>Override this method to set a custom ID.
-     *
-     * @return the ID of this category
-     */
-    default String getConfigCategoryID() {
-        return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, getClass().getSimpleName());
-    }
-
-}

+ 21 - 0
src/main/java/me/lortseam/completeconfig/api/ConfigGroup.java

@@ -0,0 +1,21 @@
+package me.lortseam.completeconfig.api;
+
+import com.google.common.base.CaseFormat;
+
+/**
+ * A group of config entries. Every group has a unique identifier inside its parent node.
+ */
+public interface ConfigGroup extends ConfigEntryContainer {
+
+    /**
+     * Used to identify this group. Defaults to the class name.
+     *
+     * <p>Override this method to set a custom ID.
+     *
+     * @return the ID of this group
+     */
+    default String getConfigGroupID() {
+        return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, getClass().getSimpleName());
+    }
+
+}

+ 8 - 8
src/main/java/me/lortseam/completeconfig/data/Collection.java

@@ -2,7 +2,7 @@ package me.lortseam.completeconfig.data;
 
 import lombok.AccessLevel;
 import lombok.Getter;
-import me.lortseam.completeconfig.api.ConfigCategory;
+import me.lortseam.completeconfig.api.ConfigGroup;
 import me.lortseam.completeconfig.api.ConfigEntryContainer;
 import me.lortseam.completeconfig.exception.IllegalAnnotationTargetException;
 import net.minecraft.text.Text;
@@ -23,16 +23,16 @@ public class Collection {
     @Getter
     private final CollectionMap collections;
 
-    Collection(String modTranslationKey, String parentTranslationKey, ConfigCategory category) {
-        String categoryID = category.getConfigCategoryID();
+    Collection(String modTranslationKey, String parentTranslationKey, ConfigGroup group) {
+        String groupID = group.getConfigGroupID();
         if (parentTranslationKey == null) {
-            translationKey = categoryID;
+            translationKey = groupID;
         } else {
-            translationKey = parentTranslationKey + "." + categoryID;
+            translationKey = parentTranslationKey + "." + groupID;
         }
         entries = new EntryMap(modTranslationKey);
         collections = new CollectionMap(modTranslationKey);
-        fill(category);
+        fill(group);
     }
 
     public Text getText() {
@@ -70,8 +70,8 @@ public class Collection {
         }
         containers.addAll(Arrays.asList(container.getTransitiveConfigEntryContainers()));
         for (ConfigEntryContainer c : containers) {
-            if (c instanceof ConfigCategory) {
-                collections.fill(translationKey, (ConfigCategory) c);
+            if (c instanceof ConfigGroup) {
+                collections.fill(translationKey, (ConfigGroup) c);
             } else {
                 fill(c);
             }

+ 6 - 6
src/main/java/me/lortseam/completeconfig/data/CollectionMap.java

@@ -1,6 +1,6 @@
 package me.lortseam.completeconfig.data;
 
-import me.lortseam.completeconfig.api.ConfigCategory;
+import me.lortseam.completeconfig.api.ConfigGroup;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 
@@ -12,14 +12,14 @@ public class CollectionMap extends ConfigMap<Collection> {
         super(modTranslationKey);
     }
 
-    protected boolean fill(String parentTranslationKey, ConfigCategory category) {
-        String categoryID = category.getConfigCategoryID();
-        Collection collection = new Collection(modTranslationKey, parentTranslationKey, category);
+    protected boolean fill(String parentTranslationKey, ConfigGroup group) {
+        String groupID = group.getConfigGroupID();
+        Collection collection = new Collection(modTranslationKey, parentTranslationKey, group);
         if (collection.getEntries().isEmpty() && collection.getCollections().isEmpty()) {
-            LOGGER.warn("[CompleteConfig] Category " + categoryID + " is empty!");
+            LOGGER.warn("[CompleteConfig] Group " + groupID + " is empty!");
             return false;
         }
-        putUnique(categoryID, collection);
+        putUnique(groupID, collection);
         return true;
     }