mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-08 16:56:07 +00:00
meta noise type
This commit is contained in:
@@ -1,17 +1,20 @@
|
||||
package com.dfsek.terra.config.loaders.config.sampler;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.config.Configuration;
|
||||
import com.dfsek.tectonic.exception.ConfigException;
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
import com.dfsek.terra.api.config.meta.MetaValue;
|
||||
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
|
||||
import com.dfsek.terra.registry.config.NoiseRegistry;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class NoiseSamplerBuilderLoader implements TypeLoader<NoiseSeeded> {
|
||||
@@ -25,11 +28,26 @@ public class NoiseSamplerBuilderLoader implements TypeLoader<NoiseSeeded> {
|
||||
public NoiseSeeded load(Type t, Object c, ConfigLoader loader) throws LoadException {
|
||||
Map<String, Object> map = (Map<String, Object>) c;
|
||||
try {
|
||||
ObjectTemplate<NoiseSeeded> normalizerTemplate = noiseRegistry.get(((String) map.get("type")).toUpperCase(Locale.ROOT)).get();
|
||||
loader.load(normalizerTemplate, new Configuration(map));
|
||||
Template typeTemplate = new Template();
|
||||
Configuration configuration = new Configuration(map);
|
||||
loader.load(typeTemplate, configuration);
|
||||
ObjectTemplate<NoiseSeeded> normalizerTemplate = typeTemplate.get().get();
|
||||
loader.load(normalizerTemplate, configuration);
|
||||
return normalizerTemplate.get();
|
||||
} catch(ConfigException e) {
|
||||
throw new LoadException("Unable to load noise function: ", e);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private class Template implements ObjectTemplate<Supplier<ObjectTemplate<NoiseSeeded>>> {
|
||||
@Value("type")
|
||||
private MetaValue<String> type;
|
||||
|
||||
|
||||
@Override
|
||||
public Supplier<ObjectTemplate<NoiseSeeded>> get() {
|
||||
return noiseRegistry.get(type.get().toUpperCase(Locale.ROOT));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user