Sfoglia il codice sorgente

Restructure text and tooltip suppliers

Lortseam 4 anni fa
parent
commit
c13a30ec5f

+ 2 - 1
lib/src/main/java/me/lortseam/completeconfig/data/BaseCollection.java

@@ -3,6 +3,7 @@ package me.lortseam.completeconfig.data;
 import com.google.common.collect.Iterables;
 import me.lortseam.completeconfig.api.ConfigContainer;
 import me.lortseam.completeconfig.api.ConfigGroup;
+import me.lortseam.completeconfig.data.client.TextSupplier;
 import me.lortseam.completeconfig.data.structure.DataPart;
 import me.lortseam.completeconfig.data.structure.ParentDataPart;
 import me.lortseam.completeconfig.text.TranslationKey;
@@ -17,7 +18,7 @@ import java.lang.reflect.Modifier;
 import java.util.Arrays;
 import java.util.Collections;
 
-abstract class BaseCollection implements ParentDataPart {
+abstract class BaseCollection implements ParentDataPart, TextSupplier {
 
     @Environment(EnvType.CLIENT)
     protected TranslationKey translation;

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

@@ -5,7 +5,7 @@ import lombok.RequiredArgsConstructor;
 import lombok.extern.log4j.Log4j2;
 import me.lortseam.completeconfig.api.ConfigGroup;
 import me.lortseam.completeconfig.data.structure.Identifiable;
-import me.lortseam.completeconfig.data.structure.TooltipSupplier;
+import me.lortseam.completeconfig.data.client.TooltipSupplier;
 import me.lortseam.completeconfig.text.TranslationKey;
 import net.fabricmc.api.EnvType;
 import net.fabricmc.api.Environment;

+ 1 - 1
lib/src/main/java/me/lortseam/completeconfig/data/Config.java

@@ -60,7 +60,7 @@ public final class Config extends BaseCollection {
     @Override
     public TranslationKey getTranslation() {
         if (translation == null) {
-            translation = TranslationKey.from(source);
+            translation = TranslationKey.from(this);
         }
         return translation;
     }

+ 3 - 2
lib/src/main/java/me/lortseam/completeconfig/data/Entry.java

@@ -7,11 +7,12 @@ import lombok.extern.log4j.Log4j2;
 import me.lortseam.completeconfig.CompleteConfig;
 import me.lortseam.completeconfig.api.ConfigContainer;
 import me.lortseam.completeconfig.api.ConfigEntry;
+import me.lortseam.completeconfig.data.client.TextSupplier;
 import me.lortseam.completeconfig.data.transform.Transformation;
 import me.lortseam.completeconfig.data.transform.Transformer;
 import me.lortseam.completeconfig.data.structure.DataPart;
 import me.lortseam.completeconfig.data.structure.Identifiable;
-import me.lortseam.completeconfig.data.structure.TooltipSupplier;
+import me.lortseam.completeconfig.data.client.TooltipSupplier;
 import me.lortseam.completeconfig.text.TranslationKey;
 import me.lortseam.completeconfig.exception.IllegalAnnotationParameterException;
 import me.lortseam.completeconfig.extensions.CompleteConfigExtension;
@@ -33,7 +34,7 @@ import java.util.Optional;
 import java.util.function.UnaryOperator;
 
 @Log4j2(topic = "CompleteConfig")
-public class Entry<T> implements DataPart, Identifiable, TooltipSupplier {
+public class Entry<T> implements DataPart, Identifiable, TextSupplier, TooltipSupplier {
 
     private static final Transformer DEFAULT_TRANSFORMER = Entry::new;
 

+ 18 - 0
lib/src/main/java/me/lortseam/completeconfig/data/client/TextSupplier.java

@@ -0,0 +1,18 @@
+package me.lortseam.completeconfig.data.client;
+
+import me.lortseam.completeconfig.text.TranslationKey;
+import net.fabricmc.api.EnvType;
+import net.fabricmc.api.Environment;
+import net.minecraft.text.Text;
+
+public interface TextSupplier {
+
+    @Environment(EnvType.CLIENT)
+    TranslationKey getTranslation();
+
+    @Environment(EnvType.CLIENT)
+    default Text getText() {
+        return getTranslation().toText();
+    }
+
+}

+ 1 - 1
lib/src/main/java/me/lortseam/completeconfig/data/structure/TooltipSupplier.java → lib/src/main/java/me/lortseam/completeconfig/data/client/TooltipSupplier.java

@@ -1,4 +1,4 @@
-package me.lortseam.completeconfig.data.structure;
+package me.lortseam.completeconfig.data.client;
 
 import me.lortseam.completeconfig.text.TranslationKey;
 import net.fabricmc.api.EnvType;

+ 0 - 12
lib/src/main/java/me/lortseam/completeconfig/data/structure/DataPart.java

@@ -1,9 +1,5 @@
 package me.lortseam.completeconfig.data.structure;
 
-import me.lortseam.completeconfig.text.TranslationKey;
-import net.fabricmc.api.EnvType;
-import net.fabricmc.api.Environment;
-import net.minecraft.text.Text;
 import org.spongepowered.configurate.CommentedConfigurationNode;
 
 public interface DataPart {
@@ -12,12 +8,4 @@ public interface DataPart {
 
     void fetch(CommentedConfigurationNode node);
 
-    @Environment(EnvType.CLIENT)
-    TranslationKey getTranslation();
-
-    @Environment(EnvType.CLIENT)
-    default Text getText() {
-        return getTranslation().toText();
-    }
-
 }

+ 3 - 3
lib/src/main/java/me/lortseam/completeconfig/text/TranslationKey.java

@@ -1,6 +1,6 @@
 package me.lortseam.completeconfig.text;
 
-import me.lortseam.completeconfig.io.ConfigSource;
+import me.lortseam.completeconfig.data.Config;
 import net.fabricmc.api.EnvType;
 import net.fabricmc.api.Environment;
 import net.minecraft.client.resource.language.I18n;
@@ -18,8 +18,8 @@ public final class TranslationKey {
 
     private static final String DELIMITER = ".";
 
-    public static TranslationKey from(ConfigSource source) {
-        return new TranslationKey("config" + DELIMITER + source.getModId());
+    public static TranslationKey from(Config config) {
+        return new TranslationKey("config" + DELIMITER + config.getMod().getId());
     }
 
     private final String modKey;

+ 3 - 3
lib/src/test/java/me/lortseam/completeconfig/data/BaseCollectionTest.java

@@ -2,13 +2,12 @@ package me.lortseam.completeconfig.data;
 
 import com.google.common.collect.Iterables;
 import me.lortseam.completeconfig.api.ConfigContainer;
-import me.lortseam.completeconfig.text.TranslationKey;
 import me.lortseam.completeconfig.exception.IllegalAnnotationTargetException;
-import me.lortseam.completeconfig.io.ConfigSource;
 import me.lortseam.completeconfig.test.data.containers.*;
 import me.lortseam.completeconfig.test.data.groups.EmptyGroup;
 import me.lortseam.completeconfig.test.data.listeners.EmptyListener;
 import me.lortseam.completeconfig.test.data.listeners.SetterListener;
+import me.lortseam.completeconfig.text.TranslationKey;
 import nl.altindag.log.LogCaptor;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
@@ -16,6 +15,7 @@ import org.junit.jupiter.api.Test;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.Mockito.mock;
 
 public class BaseCollectionTest {
 
@@ -29,7 +29,7 @@ public class BaseCollectionTest {
         baseCollection = new BaseCollection() {
             @Override
             public TranslationKey getTranslation() {
-                return TranslationKey.from(new ConfigSource(MOD_ID, new String[0]));
+                return mock(TranslationKey.class);
             }
         };
     }