Describe module settings for studio as LoadedPack.schema()

PackSchema (com.volmit.host.schema) is a JSON-free description of every catalogued
settings type: features with their module, JSON field and targets, every reachable
class once by name (cycles end at the name), options with value kind, description,
required, bounds, defaults read from a no-argument instance and @Ref references,
plus object generator settings and snippets. Everything is in a fixed order.

The pack load fails, naming class, field and module, on unsupported field types,
@Ref on fields that are not text, classes without a working no-argument constructor
and snippet names that are not folder names or are used twice. GrassSettings.block
becomes a BlockState, a block reference without @Ref.
This commit is contained in:
piexel committed 2026-10-06 12:14:34 +02:00
1 parent 93c755ffe4
commit 3465f8d390
19 files changed
+1302 -6

No files matched your search

@@ -0,0 +1,54 @@
package com.volmit.host.schema;
import com.volmit.FeatureAttachment;
import java.util.Comparator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Objects;
/** What the modules of a loaded pack add to the pack's JSON, for the host to render as JSON Schema and
* studio completion. It holds module-provided entries only: the host describes its own fields.
*
* <p>Everything is in a fixed order, so the same modules always give the same description: features
* by id, the features of a target by JSON field, types by name, snippets by snippet name, options by
* name and enum constants in declaration order.
*
* @param features every catalogued settings type of the pack's modules, built-in ones included
* @param types every class reachable from those settings, each once
*/
public record PackSchema(List<FeatureSchema> features, List<ObjectType> types) {
public PackSchema {
features = features.stream().sorted(Comparator.comparing(FeatureSchema::id)).toList();
types = types.stream().sorted(Comparator.comparing(ObjectType::name)).toList();
}
/** The module fields of one attachment target, by JSON field name. */
public List<FeatureSchema> fields(FeatureAttachment.Target target) {
Objects.requireNonNull(target, "target");
return features.stream()
.filter(feature -> feature.targets().contains(target))
.sorted(Comparator.comparing(FeatureSchema::field))
.toList();
}
/** The settings of object generators, by feature id. */
public List<FeatureSchema> objectGenerators() {
return features.stream().filter(feature -> feature.role() == FeatureRole.OBJECT_GENERATOR).toList();
}
/** The type an {@link ValueKind.ObjectKind} names. */
public ObjectType type(String name) {
return types.stream()
.filter(type -> type.name().equals(name))
.findFirst()
.orElseThrow(() -> new NoSuchElementException("No settings type: " + name));
}
/** The types a pack may write as snippet files, by snippet name; each name belongs to one type. */
public List<ObjectType> snippets() {
return types.stream()
.filter(type -> type.snippet().isPresent())
.sorted(Comparator.comparing(type -> type.snippet().orElseThrow()))
.toList();
}
}