mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-03 08:25:31 +00:00
working config loading
This commit is contained in:
parent
a78e64a9bb
commit
03ebafc7b6
@ -14,7 +14,7 @@ dependencies {
|
||||
"shadedApi"("commons-io:commons-io:2.4")
|
||||
|
||||
"shadedApi"("com.dfsek:Paralithic:0.3.2")
|
||||
"shadedApi"("com.dfsek:Tectonic:1.3.0")
|
||||
"shadedApi"("com.dfsek:Tectonic:1.3.1")
|
||||
"shadedApi"("net.jafama:jafama:2.3.2")
|
||||
"shadedApi"("org.yaml:snakeyaml:1.27")
|
||||
"shadedApi"("org.ow2.asm:asm:9.0")
|
||||
|
@ -6,6 +6,7 @@ import com.dfsek.terra.registry.OpenRegistry;
|
||||
import com.dfsek.terra.registry.exception.DuplicateEntryException;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
@ -68,7 +69,7 @@ public class CheckedRegistry<T> implements Registry<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<T> entries() {
|
||||
public Collection<T> entries() {
|
||||
return registry.entries();
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
@ -41,7 +42,7 @@ public class LockedRegistry<T> implements Registry<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<T> entries() {
|
||||
public Collection<T> entries() {
|
||||
return registry.entries();
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ package com.dfsek.terra.api.registry;
|
||||
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
@ -42,7 +43,7 @@ public interface Registry<T> extends TypeLoader<T> {
|
||||
*
|
||||
* @return Set containing all entries.
|
||||
*/
|
||||
Set<T> entries();
|
||||
Collection<T> entries();
|
||||
|
||||
/**
|
||||
* Get all the keys in this registry.
|
||||
|
@ -30,7 +30,7 @@ public class ZIPLoader extends Loader {
|
||||
ZipEntry entry = entries.nextElement();
|
||||
if(!entry.isDirectory() && entry.getName().startsWith(directory) && entry.getName().endsWith(extension)) {
|
||||
try {
|
||||
String rel = entry.getName().substring(directory.length() + 1);
|
||||
String rel = entry.getName().substring(directory.length());
|
||||
streams.put(rel, file.getInputStream(entry));
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -66,8 +66,10 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@ -110,13 +112,14 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
|
||||
public ConfigPack(File folder, TerraPlugin main) throws ConfigException {
|
||||
try {
|
||||
floraRegistry = new FloraRegistry(main);
|
||||
paletteRegistry = new PaletteRegistry(main);
|
||||
treeRegistry = new TreeRegistry();
|
||||
this.configTypeRegistry = new ConfigTypeRegistry(this, main);
|
||||
this.loader = new FolderLoader(folder.toPath());
|
||||
this.main = main;
|
||||
long l = System.nanoTime();
|
||||
floraRegistry = new FloraRegistry(main);
|
||||
paletteRegistry = new PaletteRegistry(main);
|
||||
treeRegistry = new TreeRegistry();
|
||||
|
||||
register(abstractConfigLoader);
|
||||
register(selfLoader);
|
||||
|
||||
@ -147,13 +150,14 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
|
||||
public ConfigPack(ZipFile file, TerraPlugin main) throws ConfigException {
|
||||
try {
|
||||
floraRegistry = new FloraRegistry(main);
|
||||
paletteRegistry = new PaletteRegistry(main);
|
||||
treeRegistry = new TreeRegistry();
|
||||
this.configTypeRegistry = new ConfigTypeRegistry(this, main);
|
||||
this.loader = new ZIPLoader(file);
|
||||
this.main = main;
|
||||
long l = System.nanoTime();
|
||||
floraRegistry = new FloraRegistry(main);
|
||||
paletteRegistry = new PaletteRegistry(main);
|
||||
treeRegistry = new TreeRegistry();
|
||||
|
||||
register(abstractConfigLoader);
|
||||
register(selfLoader);
|
||||
|
||||
@ -224,20 +228,19 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
|
||||
List<Configuration> configurations = new ArrayList<>();
|
||||
|
||||
loader.open("", ".yml").then(streams -> streams.forEach(stream -> configurations.add(new Configuration(stream))));
|
||||
loader.open("", ".yml").thenEntries(entries -> entries.forEach(stream -> configurations.add(new Configuration(stream.getValue(), stream.getKey()))));
|
||||
|
||||
ConfigLoader protoLoader = new ConfigLoader();
|
||||
Map<ConfigType<? extends ConfigTemplate>, List<Configuration>> configs = new HashMap<>();
|
||||
|
||||
for(Configuration configuration : configurations) {
|
||||
ProtoConfig config = new ProtoConfig();
|
||||
protoLoader.load(config, configuration);
|
||||
selfLoader.load(config, configuration);
|
||||
configs.computeIfAbsent(config.getType(), configType -> new ArrayList<>()).add(configuration);
|
||||
}
|
||||
|
||||
for(Map.Entry<ConfigType<? extends ConfigTemplate>, List<Configuration>> entry : configs.entrySet()) {
|
||||
for(ConfigTemplate config : abstractConfigLoader.loadConfigs(entry.getValue(), () -> entry.getKey().getTemplate(this, main))) {
|
||||
((ConfigType) entry.getKey()).callback(this, main, config);
|
||||
for(ConfigType<?> configType : configTypeRegistry.entries()) {
|
||||
for(ConfigTemplate config : abstractConfigLoader.loadConfigs(configs.getOrDefault(configType, Collections.emptyList()), () -> configType.getTemplate(this, main))) {
|
||||
((ConfigType) configType).callback(this, main, config);
|
||||
}
|
||||
}
|
||||
|
||||
@ -250,7 +253,7 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
}
|
||||
|
||||
public Set<TerraStructure> getStructures() {
|
||||
return structureRegistry.entries();
|
||||
return new HashSet<>(structureRegistry.entries());
|
||||
}
|
||||
|
||||
public List<String> getStructureIDs() {
|
||||
@ -288,7 +291,7 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
}
|
||||
|
||||
public Set<UserDefinedCarver> getCarvers() {
|
||||
return carverRegistry.entries();
|
||||
return new HashSet<>(carverRegistry.entries());
|
||||
}
|
||||
|
||||
public BiomeProvider.BiomeProviderBuilder getBiomeProviderBuilder() {
|
||||
|
@ -17,6 +17,7 @@ import com.dfsek.terra.world.generation.math.SamplerCache;
|
||||
import com.dfsek.terra.world.population.items.TerraStructure;
|
||||
import com.dfsek.terra.world.population.items.ores.Ore;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class WorldConfig {
|
||||
@ -66,7 +67,7 @@ public class WorldConfig {
|
||||
}
|
||||
|
||||
public Set<UserDefinedCarver> getCarvers() {
|
||||
return carverRegistry.entries();
|
||||
return new HashSet<>(carverRegistry.entries());
|
||||
}
|
||||
|
||||
public LockedRegistry<StructureScript> getScriptRegistry() {
|
||||
@ -110,7 +111,7 @@ public class WorldConfig {
|
||||
}
|
||||
|
||||
public Set<TerraStructure> getStructures() {
|
||||
return structureRegistry.entries();
|
||||
return new HashSet<>(structureRegistry.entries());
|
||||
}
|
||||
|
||||
public ConfigPackTemplate getTemplate() {
|
||||
|
@ -6,6 +6,7 @@ import com.dfsek.terra.api.registry.Registry;
|
||||
import com.dfsek.terra.registry.exception.DuplicateEntryException;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
@ -18,7 +19,15 @@ import java.util.function.Consumer;
|
||||
* @param <T>
|
||||
*/
|
||||
public class OpenRegistry<T> implements Registry<T> {
|
||||
private final Map<String, T> objects = new HashMap<>();
|
||||
private final Map<String, T> objects;
|
||||
|
||||
public OpenRegistry() {
|
||||
objects = new HashMap<>();
|
||||
}
|
||||
|
||||
protected OpenRegistry(Map<String, T> init) {
|
||||
this.objects = init;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T load(Type type, Object o, ConfigLoader configLoader) throws LoadException {
|
||||
@ -74,8 +83,8 @@ public class OpenRegistry<T> implements Registry<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<T> entries() {
|
||||
return new HashSet<>(objects.values());
|
||||
public Collection<T> entries() {
|
||||
return objects.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.registry.config;
|
||||
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
@ -23,18 +24,35 @@ import com.dfsek.terra.config.templates.StructureTemplate;
|
||||
import com.dfsek.terra.config.templates.TreeTemplate;
|
||||
import com.dfsek.terra.registry.OpenRegistry;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class ConfigTypeRegistry extends OpenRegistry<ConfigType<?>> {
|
||||
public ConfigTypeRegistry(ConfigPack pack, TerraPlugin main) {
|
||||
add("BIOME", new ConfigBuilder<>(pack.getBiomeRegistry(), new BiomeFactory(pack), () -> new BiomeTemplate(pack, main)));
|
||||
super(new LinkedHashMap<>()); // Ordered
|
||||
add("PALETTE", new ConfigBuilder<>(pack.getPaletteRegistry(), new PaletteFactory(), PaletteTemplate::new));
|
||||
add("ORE", new ConfigBuilder<>(pack.getOreRegistry(), new OreFactory(), OreTemplate::new));
|
||||
add("FLORA", new ConfigBuilder<>(pack.getFloraRegistry(), new FloraFactory(), FloraTemplate::new));
|
||||
add("CARVER", new ConfigBuilder<>(pack.getCarverRegistry(), new CarverFactory(pack), CarverTemplate::new));
|
||||
add("STRUCTURE", new ConfigBuilder<>(pack.getStructureRegistry(), new StructureFactory(), StructureTemplate::new));
|
||||
add("TREE", new ConfigBuilder<>(pack.getTreeRegistry(), new TreeFactory(), TreeTemplate::new));
|
||||
add("BIOME", new ConfigBuilder<>(pack.getBiomeRegistry(), new BiomeFactory(pack), () -> new BiomeTemplate(pack, main)));
|
||||
add("PACK", new PackBuilder());
|
||||
}
|
||||
|
||||
private static final class PackBuilder implements ConfigType<ConfigTemplate> {
|
||||
|
||||
@Override
|
||||
public ConfigTemplate getTemplate(ConfigPack pack, TerraPlugin main) {
|
||||
return new ConfigTemplate() {
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callback(ConfigPack pack, TerraPlugin main, ConfigTemplate loadedConfig) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static final class ConfigBuilder<T extends AbstractableTemplate, O> implements ConfigType<T> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user