mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 02:20:57 +00:00
metaset impl
This commit is contained in:
@@ -41,7 +41,7 @@ import com.dfsek.terra.config.fileloaders.FolderLoader;
|
||||
import com.dfsek.terra.config.fileloaders.ZIPLoader;
|
||||
import com.dfsek.terra.config.loaders.GenericTemplateSupplierLoader;
|
||||
import com.dfsek.terra.config.loaders.config.BufferedImageLoader;
|
||||
import com.dfsek.terra.config.preprocessor.MetaListPreprocessor;
|
||||
import com.dfsek.terra.config.preprocessor.MetaListLikePreprocessor;
|
||||
import com.dfsek.terra.config.preprocessor.MetaValuePreprocessor;
|
||||
import com.dfsek.terra.config.prototype.ProtoConfig;
|
||||
import com.dfsek.terra.registry.CheckedRegistryImpl;
|
||||
@@ -245,7 +245,7 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
selfLoader.registerPreprocessor(Meta.class, valuePreprocessor);
|
||||
abstractConfigLoader.registerPreprocessor(Meta.class, valuePreprocessor);
|
||||
|
||||
MetaListPreprocessor listPreprocessor = new MetaListPreprocessor(configurations);
|
||||
MetaListLikePreprocessor listPreprocessor = new MetaListLikePreprocessor(configurations);
|
||||
selfLoader.registerPreprocessor(Meta.class, listPreprocessor);
|
||||
abstractConfigLoader.registerPreprocessor(Meta.class, listPreprocessor);
|
||||
|
||||
|
||||
@@ -12,9 +12,10 @@ import java.lang.reflect.ParameterizedType;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class MetaListPreprocessor extends MetaPreprocessor<Meta> {
|
||||
public MetaListPreprocessor(Map<String, Configuration> configs) {
|
||||
public class MetaListLikePreprocessor extends MetaPreprocessor<Meta> {
|
||||
public MetaListLikePreprocessor(Map<String, Configuration> configs) {
|
||||
super(configs);
|
||||
}
|
||||
|
||||
@@ -26,7 +27,7 @@ public class MetaListPreprocessor extends MetaPreprocessor<Meta> {
|
||||
if(parameterizedType.getRawType() instanceof Class) { // Should always be true but we check anyways
|
||||
Class<?> baseClass = (Class<?>) parameterizedType.getRawType();
|
||||
|
||||
if(List.class.isAssignableFrom(baseClass) && c instanceof List) { // List metaconfig
|
||||
if((List.class.isAssignableFrom(baseClass) || Set.class.isAssignableFrom(baseClass)) && c instanceof List) { // List or set metaconfig
|
||||
List<Object> list = (List<Object>) c;
|
||||
|
||||
int offset = 0;
|
||||
@@ -42,7 +43,7 @@ public class MetaListPreprocessor extends MetaPreprocessor<Meta> {
|
||||
Object metaValue = getMetaValue(meta);
|
||||
|
||||
if(!(metaValue instanceof List)) {
|
||||
throw new LoadException("MetaList injection candidate must be list, is type " + metaValue.getClass().getCanonicalName());
|
||||
throw new LoadException("MetaList/Set injection candidate must be list, is type " + metaValue.getClass().getCanonicalName());
|
||||
}
|
||||
|
||||
List<Object> metaList = (List<Object>) metaValue;
|
||||
@@ -4,7 +4,7 @@ import com.dfsek.tectonic.config.Configuration;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.yaml.YamlConfiguration;
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.config.preprocessor.MetaListPreprocessor;
|
||||
import com.dfsek.terra.config.preprocessor.MetaListLikePreprocessor;
|
||||
import com.dfsek.terra.config.preprocessor.MetaMapPreprocessor;
|
||||
import com.dfsek.terra.config.preprocessor.MetaValuePreprocessor;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -26,7 +26,7 @@ public class MetaTest {
|
||||
|
||||
ConfigLoader loader = new ConfigLoader();
|
||||
loader.registerPreprocessor(Meta.class, new MetaValuePreprocessor(configurationMap));
|
||||
loader.registerPreprocessor(Meta.class, new MetaListPreprocessor(configurationMap));
|
||||
loader.registerPreprocessor(Meta.class, new MetaListLikePreprocessor(configurationMap));
|
||||
loader.registerPreprocessor(Meta.class, new MetaMapPreprocessor(configurationMap));
|
||||
|
||||
loader.load(new MetaListConfig(), meta).list.forEach(System.out::println);
|
||||
@@ -49,7 +49,7 @@ public class MetaTest {
|
||||
|
||||
ConfigLoader loader = new ConfigLoader();
|
||||
loader.registerPreprocessor(Meta.class, new MetaValuePreprocessor(configurationMap));
|
||||
loader.registerPreprocessor(Meta.class, new MetaListPreprocessor(configurationMap));
|
||||
loader.registerPreprocessor(Meta.class, new MetaListLikePreprocessor(configurationMap));
|
||||
loader.registerPreprocessor(Meta.class, new MetaMapPreprocessor(configurationMap));
|
||||
|
||||
loader.load(new MetaMapConfig(), meta).map.forEach((k, v) -> System.out.println(k + ": " + v));
|
||||
|
||||
Reference in New Issue
Block a user