begin work on automatic config docs

This commit is contained in:
dfsek
2021-04-25 16:53:11 -07:00
parent f396e0e5eb
commit 869d95f5c8
7 changed files with 145 additions and 1 deletions

View File

@@ -1,10 +1,19 @@
import com.dfsek.terra.configureCommon
import com.github.javaparser.ast.body.FieldDeclaration
import com.github.javaparser.ast.expr.StringLiteralExpr
import com.github.javaparser.StaticJavaParser
plugins {
`java-library`
`maven-publish`
}
buildscript {
dependencies {
classpath("com.github.javaparser:javaparser-symbol-solver-core:3.20.2")
}
}
configureCommon()
group = "com.dfsek.terra.common"
@@ -51,4 +60,67 @@ publishing {
}
}
}
}
tasks.create<SourceTask>("tectonicDocs") {
group = "terra"
println("Scanning sources...")
val docs = HashMap<String, String>()
sourceSets.forEach { sourceSet ->
sourceSet.java.forEach { file ->
val doc = StringBuilder()
val name = file.name.substring(0, file.name.length - 5)
val unit = StaticJavaParser.parse(file)
doc.append("# $name\n")
unit.getClassByName(name).ifPresent { declaration ->
declaration.javadoc.ifPresent {
doc.append("${sanitizeJavadoc(it.toText())} \n")
}
declaration.extendedTypes.forEach {
if(!it.name.asString().equals("AbstractableTemplate")) {
doc.append("Inherits from [${it.name}](./${it.name})\n")
}
}
doc.append("\n")
}
var applicable = false
unit.findAll(FieldDeclaration::class.java).filter { it.isAnnotationPresent("Value") }.forEach { fieldDeclaration ->
doc.append("## ${(fieldDeclaration.getAnnotationByName("Value").get().childNodes[1] as StringLiteralExpr).asString()}\n")
if(fieldDeclaration.isAnnotationPresent("Default")) {
doc.append("* Default value: ${fieldDeclaration.variables[0]} \n")
}
val type =fieldDeclaration.commonType.asString()
doc.append("* Type: [$type](./$type) \n")
doc.append("\n")
fieldDeclaration.javadoc.ifPresent {
doc.append(sanitizeJavadoc(it.toText()))
}
doc.append("\n\n")
applicable = true
}
val s = doc.toString()
if (s.isNotEmpty() && applicable) docs[name] = s
}
}
println("Done. Generated ${docs.size} files")
val docsDir = File(buildDir, "tectonic")
docsDir.mkdirs()
docs.forEach {
val save = File(docsDir, "${it.key}.md")
if (save.exists()) save.delete()
save.createNewFile()
save.writeText(it.value)
}
}
fun sanitizeJavadoc(doc:String):String {
return doc.replace("<p>", "").replace("<", "\\<").replace(">", "\\>")
}

View File

@@ -11,16 +11,28 @@ import com.dfsek.terra.api.world.biome.provider.StandardBiomeProvider;
import java.util.List;
/**
* Configures a biome pipeline.
*/
@SuppressWarnings({"FieldMayBeFinal", "unused"})
public class BiomePipelineTemplate extends BiomeProviderTemplate {
private final TerraPlugin main;
/**
* Initial size of biome pipeline chunks.
*/
@Value("pipeline.initial-size")
@Default
private int initialSize = 2;
/**
* Mutator stages to be used in this biome pipeline.
*/
@Value("pipeline.stages")
private List<StageSeeded> stages;
/**
* Biome source to initialize the pipeline.
*/
@Value("pipeline.source")
private SourceSeeded source;

View File

@@ -6,18 +6,35 @@ import com.dfsek.terra.api.math.noise.NoiseSampler;
import com.dfsek.terra.api.math.noise.samplers.DomainWarpedSampler;
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
/**
* Defines a domain-warped noise function.
*/
@SuppressWarnings({"unused", "FieldMayBeFinal"})
public class DomainWarpTemplate extends SamplerTemplate<DomainWarpedSampler> {
/**
* Noise function used to warp input function.
*/
@Value("warp")
private NoiseSeeded warp;
/**
* Input function (function to be warped)
*/
@Value("function")
private NoiseSeeded function;
/**
* Salt for both warp function and
* input function.
*/
@Value("salt")
@Default
private int salt = 0;
/**
* Amplitude of warping. Values provided by
* the warp function are multiplied by this constant.
*/
@Value("amplitude")
@Default
private double amplitude = 1;

View File

@@ -10,6 +10,9 @@ import com.dfsek.terra.api.util.seeded.NoiseSeeded;
@SuppressWarnings("FieldMayBeFinal")
public abstract class SamplerTemplate<T extends NoiseSampler> implements ValidatedConfigTemplate, ObjectTemplate<NoiseSeeded>, NoiseSeeded {
/**
* Number of dimensions for this sampler.
*/
@Value("dimensions")
@Default
private int dimensions = 2;

View File

@@ -5,15 +5,27 @@ import com.dfsek.tectonic.annotations.Value;
import com.dfsek.terra.api.math.noise.NoiseSampler;
import com.dfsek.terra.api.math.noise.samplers.noise.GaborNoiseSampler;
/**
* Defines a Gabor noise function.
*/
public class GaborNoiseTemplate extends NoiseTemplate<GaborNoiseSampler> {
/**
* Rotation to apply to noise. Only has noticeable effects in anisotropic mode.
*/
@Value("rotation")
@Default
private double rotation = 0.25;
/**
* Whether to use anisotropic or isotropic algorithm.
*/
@Value("isotropic")
@Default
private boolean isotropic = true;
/**
* Standard deviation of result values.
*/
@Value("deviation")
@Default
private double deviation = 1.0;

View File

@@ -15,24 +15,52 @@ import java.util.Set;
@SuppressWarnings({"unused", "FieldMayBeFinal"})
public class ConfigPackTemplate implements ConfigTemplate {
/**
* The ID of the config pack.
*/
@Value("id")
private String id;
/**
* Noise functions to be made available
* to noise equations in the config pack.
* <p>
* Keys are Paralithic function IDs,
* values are noise functions.
*/
@Value("noise")
private Map<String, NoiseSeeded> noiseBuilderMap;
/**
* Addons this pack depends on.
*/
@Value("addons")
@Default
private Set<TerraAddon> addons = new HashSet<>();
/**
* Variables to be made available
* to noise equations in the config pack.
* <p>
* Keys are variable IDs,
* values are variable values.
*/
@Value("variables")
@Default
private Map<String, Double> variables = new HashMap<>();
/**
* Whether to enable beta noise
* carvers.
*/
@Value("beta.carving")
@Default
private boolean betaCarvers = false;
/**
*
*/
@Value("functions")
@Default
private LinkedHashMap<String, FunctionTemplate> functions = new LinkedHashMap<>();

View File

@@ -32,7 +32,7 @@ public class FloraTemplate extends AbstractableTemplate {
@Value("irrigable")
@Abstractable
@Default
private MaterialSet irrigable = null;
private MaterialSet irrigable = new MaterialSet();
@Value("rotatable")
@Abstractable