mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 08:14:45 +00:00
Remove feature aliases, the one-option shorthand and reserved host fields
A setting has one JSON key, its feature id, and one shape, its settings object. Aliases were the only reason for reserved host fields (ids contain ':', host fields never do), so ModuleHost.reservingFields goes too.
This commit is contained in:
1 parent
99a914633d
commit
f6c078aade
26 files changed
+112
-305
No files matched your search
@@ -1,33 +1,13 @@
|
||||
package com.volmit;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/** Where settings appear in pack JSON: the targets, and the optional short alias a built-in module
|
||||
* may set besides the feature id, which is always the JSON key.
|
||||
*/
|
||||
public record FeatureAttachment(Optional<String> alias, Set<Target> targets) {
|
||||
/** Where settings appear in pack JSON: the targets. The JSON key is always the feature id. */
|
||||
public record FeatureAttachment(Set<Target> targets) {
|
||||
public enum Target { DIMENSION, REGION, BIOME, OBJECT_PLACEMENT }
|
||||
|
||||
private static final char NAMESPACE_SEPARATOR = ':';
|
||||
|
||||
public FeatureAttachment {
|
||||
Objects.requireNonNull(alias, "alias");
|
||||
alias.ifPresent(FeatureAttachment::requireFieldName);
|
||||
targets = Set.copyOf(targets);
|
||||
if (targets.isEmpty()) throw new IllegalArgumentException("At least one target is required");
|
||||
}
|
||||
|
||||
/** Checks a JSON field name that is not a feature id: an alias or a field the host itself uses.
|
||||
* It is not blank and has no ':', which every feature id has, so the two never collide.
|
||||
*/
|
||||
public static String requireFieldName(String name) {
|
||||
Objects.requireNonNull(name, "name");
|
||||
if (name.isBlank()) throw new IllegalArgumentException("Field must not be blank");
|
||||
if (name.indexOf(NAMESPACE_SEPARATOR) >= 0) {
|
||||
throw new IllegalArgumentException("Field " + name + " contains ':', which only feature ids may contain");
|
||||
}
|
||||
return name;
|
||||
}
|
||||
}
|
||||
@@ -4,16 +4,11 @@ import java.lang.annotation.*;
|
||||
|
||||
/** Identity and JSON attachment for an IrisFeature configuration class. Packs write the settings under
|
||||
* their feature id, such as {@code "example:moss": {...}}, at each of the targets.
|
||||
*
|
||||
* <p>{@code alias} is an optional short JSON key that only modules shipping with the host may set, so
|
||||
* existing pack JSON such as {@code "stilt": {...}} keeps loading. A pack module that sets one fails
|
||||
* the load. An alias contains no ':', so it never equals a feature id.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface Feature {
|
||||
String id();
|
||||
String name();
|
||||
String alias() default "";
|
||||
com.volmit.FeatureAttachment.Target[] targets();
|
||||
}
|
||||
@@ -7,7 +7,6 @@ import com.volmit.config.OptionsMetadata;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/** Validated settings metadata. It describes configuration, not executable ordering. */
|
||||
@@ -42,7 +41,7 @@ public record FeatureDescriptor<F extends IrisFeature>(
|
||||
ResourceId.parse(annotation.id()),
|
||||
annotation.name(),
|
||||
type,
|
||||
new FeatureAttachment(alias(annotation), Set.of(annotation.targets())),
|
||||
new FeatureAttachment(Set.of(annotation.targets())),
|
||||
OptionsMetadata.inspect(type));
|
||||
}
|
||||
|
||||
@@ -51,15 +50,6 @@ public record FeatureDescriptor<F extends IrisFeature>(
|
||||
return id.toString();
|
||||
}
|
||||
|
||||
/** The short JSON key a built-in module may set besides {@link #key()}. */
|
||||
public Optional<String> alias() {
|
||||
return attachment.alias();
|
||||
}
|
||||
|
||||
private static Optional<String> alias(Feature annotation) {
|
||||
return annotation.alias().isEmpty() ? Optional.empty() : Optional.of(annotation.alias());
|
||||
}
|
||||
|
||||
private static void requireConcreteFeature(Class<?> type) {
|
||||
if (!IrisFeature.class.isAssignableFrom(type)
|
||||
|| type.isInterface()
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package com.volmit.host;
|
||||
|
||||
import com.volmit.FeatureAttachment;
|
||||
import com.volmit.host.schema.PackSchema;
|
||||
import com.volmit.stage.Pipeline;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -25,7 +23,6 @@ public record LoadedModules(
|
||||
|
||||
/** Pass the built-in modules together with {@link PackModules#modules()} of the pack.
|
||||
*
|
||||
* @param reservedHostFields JSON fields the host itself uses, per attachment target
|
||||
* @param hostTypePackages packages whose classes the host describes itself, each with its
|
||||
* subpackages; only built-in modules' settings may use them (see {@link ModuleHost#describingHostTypesIn})
|
||||
* @param reservedFolders pack folders the host reads itself, which no resource kind may read (see
|
||||
@@ -33,10 +30,9 @@ public record LoadedModules(
|
||||
*/
|
||||
public static LoadedModules load(
|
||||
List<DiscoveredModule> modules,
|
||||
Map<FeatureAttachment.Target, Set<String>> reservedHostFields,
|
||||
Collection<String> hostTypePackages,
|
||||
Collection<String> reservedFolders) {
|
||||
var registry = new ModuleRegistry(reservedHostFields, Set.copyOf(reservedFolders));
|
||||
var registry = new ModuleRegistry(Set.copyOf(reservedFolders));
|
||||
var stages = new StageGraphBuilder();
|
||||
for (var discovered : modules) {
|
||||
installModule(discovered, stages, registry);
|
||||
|
||||
@@ -37,7 +37,7 @@ public final class LoadedPack implements AutoCloseable {
|
||||
var packModules = PackModules.load(packRoot, host.exposedHostPackages(), host.jarCopyRoot(), host.logger());
|
||||
try {
|
||||
var loaded = LoadedModules.load(host.withPackModules(packModules.modules()),
|
||||
host.reservedHostFields(), host.hostTypePackages(), host.reservedFolders());
|
||||
host.hostTypePackages(), host.reservedFolders());
|
||||
return new LoadedPack(packModules, loaded);
|
||||
} catch (RuntimeException | Error failure) {
|
||||
closeAfterFailure(packModules, failure);
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
package com.volmit.host;
|
||||
|
||||
import com.volmit.FeatureAttachment;
|
||||
import com.volmit.IrisModule;
|
||||
import com.volmit.resource.ResourceKind;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
@@ -22,18 +19,17 @@ import java.util.TreeSet;
|
||||
* <pre>{@code
|
||||
* var host = ModuleHost.of(builtInModules)
|
||||
* .exposing("art.arcane.iris.engine.modules")
|
||||
* .reservingFields(reservedHostFields);
|
||||
* .reservingFolders("biomes", "regions");
|
||||
* }</pre>
|
||||
*
|
||||
* Every method adds to what earlier calls configured, so a host can build the configuration in steps.
|
||||
* Built-in modules' {@code info()} is read here, once. Exposed package names, host type packages,
|
||||
* reserved folders and reserved field names are checked here, so a mistake fails when the host starts rather than at the
|
||||
* Built-in modules' {@code info()} is read here, once. Exposed package names, host type packages
|
||||
* and reserved folders are checked here, so a mistake fails when the host starts rather than at the
|
||||
* first pack load.
|
||||
*/
|
||||
public record ModuleHost(
|
||||
List<DiscoveredModule> builtIns,
|
||||
Set<String> exposedHostPackages,
|
||||
Map<FeatureAttachment.Target, Set<String>> reservedHostFields,
|
||||
Set<String> hostTypePackages,
|
||||
Set<String> reservedFolders,
|
||||
Path jarCopyRoot,
|
||||
@@ -43,14 +39,12 @@ public record ModuleHost(
|
||||
public ModuleHost {
|
||||
builtIns = List.copyOf(builtIns);
|
||||
exposedHostPackages = Set.copyOf(exposedHostPackages);
|
||||
reservedHostFields = copyOf(reservedHostFields);
|
||||
hostTypePackages = Set.copyOf(hostTypePackages);
|
||||
reservedFolders = Set.copyOf(reservedFolders);
|
||||
Objects.requireNonNull(jarCopyRoot, "jarCopyRoot");
|
||||
Objects.requireNonNull(logger, "logger");
|
||||
ExposedPackages.apiAnd(exposedHostPackages);
|
||||
HostTypes.of(hostTypePackages);
|
||||
requireFieldNames(reservedHostFields);
|
||||
requireFolderNames(reservedFolders);
|
||||
}
|
||||
|
||||
@@ -59,7 +53,7 @@ public record ModuleHost(
|
||||
*/
|
||||
public static ModuleHost of(List<? extends IrisModule> builtInModules) {
|
||||
var builtIns = builtInModules.stream().map(DiscoveredModule::builtIn).toList();
|
||||
return new ModuleHost(builtIns, Set.of(), Map.of(), Set.of(), Set.of(), systemTemporaryDirectory(),
|
||||
return new ModuleHost(builtIns, Set.of(), Set.of(), Set.of(), systemTemporaryDirectory(),
|
||||
System.getLogger(PackModules.class.getName()));
|
||||
}
|
||||
|
||||
@@ -67,16 +61,7 @@ public record ModuleHost(
|
||||
* modules, such as the packages that hold built-in modules' stage constants.
|
||||
*/
|
||||
public ModuleHost exposing(String... packages) {
|
||||
return new ModuleHost(builtIns, union(exposedHostPackages, packages), reservedHostFields,
|
||||
hostTypePackages, reservedFolders, jarCopyRoot, logger);
|
||||
}
|
||||
|
||||
/** This configuration with {@code fields} also reserved as JSON fields the host itself uses,
|
||||
* merged per attachment target with the fields reserved before.
|
||||
*/
|
||||
public ModuleHost reservingFields(Map<FeatureAttachment.Target, Set<String>> fields) {
|
||||
return new ModuleHost(builtIns, exposedHostPackages, merge(reservedHostFields, fields),
|
||||
hostTypePackages, reservedFolders, jarCopyRoot, logger);
|
||||
return new ModuleHost(builtIns, union(exposedHostPackages, packages), hostTypePackages, reservedFolders, jarCopyRoot, logger);
|
||||
}
|
||||
|
||||
/** This configuration with the classes in {@code packages}, each with its subpackages, described by
|
||||
@@ -85,7 +70,7 @@ public record ModuleHost(
|
||||
* instead of describing their fields. Pack modules' settings cannot use them.
|
||||
*/
|
||||
public ModuleHost describingHostTypesIn(String... packages) {
|
||||
return new ModuleHost(builtIns, exposedHostPackages, reservedHostFields,
|
||||
return new ModuleHost(builtIns, exposedHostPackages,
|
||||
union(hostTypePackages, packages), reservedFolders, jarCopyRoot, logger);
|
||||
}
|
||||
|
||||
@@ -93,7 +78,7 @@ public record ModuleHost(
|
||||
* itself, such as its biome and object folders. A module resource kind that reads one fails the pack load.
|
||||
*/
|
||||
public ModuleHost reservingFolders(String... folders) {
|
||||
return new ModuleHost(builtIns, exposedHostPackages, reservedHostFields, hostTypePackages,
|
||||
return new ModuleHost(builtIns, exposedHostPackages, hostTypePackages,
|
||||
union(reservedFolders, folders), jarCopyRoot, logger);
|
||||
}
|
||||
|
||||
@@ -101,7 +86,7 @@ public record ModuleHost(
|
||||
* cache directory of the host, which is created when missing. The last call wins.
|
||||
*/
|
||||
public ModuleHost copyingJarsTo(Path directory) {
|
||||
return new ModuleHost(builtIns, exposedHostPackages, reservedHostFields, hostTypePackages,
|
||||
return new ModuleHost(builtIns, exposedHostPackages, hostTypePackages,
|
||||
reservedFolders, directory, logger);
|
||||
}
|
||||
|
||||
@@ -109,7 +94,7 @@ public record ModuleHost(
|
||||
* {@code logger}, such as an adapter to the host's own log. The last call wins.
|
||||
*/
|
||||
public ModuleHost loggingTo(System.Logger logger) {
|
||||
return new ModuleHost(builtIns, exposedHostPackages, reservedHostFields, hostTypePackages,
|
||||
return new ModuleHost(builtIns, exposedHostPackages, hostTypePackages,
|
||||
reservedFolders, jarCopyRoot, logger);
|
||||
}
|
||||
|
||||
@@ -124,17 +109,6 @@ public record ModuleHost(
|
||||
return Path.of(System.getProperty(TEMPORARY_DIRECTORY_PROPERTY));
|
||||
}
|
||||
|
||||
private static Map<FeatureAttachment.Target, Set<String>> copyOf(Map<FeatureAttachment.Target, Set<String>> fields) {
|
||||
var copy = new EnumMap<FeatureAttachment.Target, Set<String>>(FeatureAttachment.Target.class);
|
||||
fields.forEach((target, names) -> copy.put(target, Set.copyOf(names)));
|
||||
return Map.copyOf(copy);
|
||||
}
|
||||
|
||||
/** A blank field name, or one with ':' like a feature id, fails here, as it would as an alias. */
|
||||
private static void requireFieldNames(Map<FeatureAttachment.Target, Set<String>> fields) {
|
||||
fields.values().forEach(names -> names.forEach(FeatureAttachment::requireFieldName));
|
||||
}
|
||||
|
||||
private static void requireFolderNames(Set<String> folders) {
|
||||
for (var folder : folders) {
|
||||
if (!ResourceKind.isFolderName(folder)) {
|
||||
@@ -144,15 +118,6 @@ public record ModuleHost(
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<FeatureAttachment.Target, Set<String>> merge(
|
||||
Map<FeatureAttachment.Target, Set<String>> existing,
|
||||
Map<FeatureAttachment.Target, Set<String>> added) {
|
||||
var merged = new EnumMap<FeatureAttachment.Target, Set<String>>(FeatureAttachment.Target.class);
|
||||
existing.forEach((target, names) -> merged.put(target, new TreeSet<>(names)));
|
||||
added.forEach((target, names) -> merged.computeIfAbsent(target, ignored -> new TreeSet<>()).addAll(names));
|
||||
return merged;
|
||||
}
|
||||
|
||||
private static Set<String> union(Set<String> existing, String... added) {
|
||||
var names = new TreeSet<>(existing);
|
||||
names.addAll(Arrays.asList(added));
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.volmit.host;
|
||||
|
||||
import com.volmit.FeatureAttachment;
|
||||
import com.volmit.FeatureRegistry;
|
||||
import com.volmit.IrisFeature;
|
||||
import com.volmit.IrisModule;
|
||||
@@ -23,9 +22,7 @@ import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
/** Reference host registry. Single-threaded registration ends with freeze(); the catalog is
|
||||
* immutable. IDs are unique across feature kinds, and every feature id is its JSON key. Aliases,
|
||||
* which only built-in modules may set, are unique per attachment target and may not equal the
|
||||
* host JSON fields passed in to reserve them. Modules register through
|
||||
* immutable. IDs are unique across feature kinds, and every feature id is its JSON key. Modules register through
|
||||
* {@link #register(DiscoveredModule)}; object feature ids, mantle keys, resource kind ids and explicitly registered
|
||||
* settings ids must be the registering module's id or start with it and '/' ({@link com.volmit.ModuleInfo#ownsId}).
|
||||
* Resource kinds have unique ids, types and folders, and no kind may read a folder the host reserves for its own
|
||||
@@ -41,28 +38,21 @@ public final class ModuleRegistry implements FeatureRegistry {
|
||||
private final Set<ResourceId> featureIds = new HashSet<>();
|
||||
private final Set<Class<?>> featureTypes = new HashSet<>();
|
||||
private final Set<Class<?>> registeredByOwner = new HashSet<>();
|
||||
private final Map<Field, String> fields = new HashMap<>();
|
||||
private final Map<ResourceId, ResourceKindRegistration> resourceKinds = new HashMap<>();
|
||||
private final List<ValidatorRegistration> validators = new ArrayList<>();
|
||||
private final List<LifecycleRegistration> lifecycles = new ArrayList<>();
|
||||
private final List<ServiceRegistration> services = new ArrayList<>();
|
||||
private final List<VanillaStructureHookRegistration> vanillaStructureHooks = new ArrayList<>();
|
||||
private final Set<String> reservedFolders;
|
||||
private final List<DiscoveredModule> registered = new ArrayList<>();
|
||||
private FeatureCatalog catalog;
|
||||
private DiscoveredModule registering;
|
||||
|
||||
public ModuleRegistry() {
|
||||
this(Map.of());
|
||||
}
|
||||
|
||||
public ModuleRegistry(Map<FeatureAttachment.Target, Set<String>> reservedFields) {
|
||||
this(reservedFields, Set.of());
|
||||
this(Set.of());
|
||||
}
|
||||
|
||||
/** @param reservedFolders folders below the pack root that the host reads itself, which no resource kind may read */
|
||||
public ModuleRegistry(Map<FeatureAttachment.Target, Set<String>> reservedFields, Set<String> reservedFolders) {
|
||||
reserveHostFields(reservedFields);
|
||||
public ModuleRegistry(Set<String> reservedFolders) {
|
||||
this.reservedFolders = Set.copyOf(reservedFolders);
|
||||
}
|
||||
|
||||
@@ -74,7 +64,6 @@ public final class ModuleRegistry implements FeatureRegistry {
|
||||
throw new IllegalStateException("Module " + discovered.info().id() + " registered during " + registering.info().id());
|
||||
}
|
||||
registering = discovered;
|
||||
registered.add(discovered);
|
||||
try {
|
||||
discovered.module().register(this);
|
||||
} finally {
|
||||
@@ -90,7 +79,7 @@ public final class ModuleRegistry implements FeatureRegistry {
|
||||
var descriptor = FeatureDescriptor.of(featureType);
|
||||
requireOwnedId("Object generator settings " + featureType.getName() + " with feature id", descriptor.id());
|
||||
var registration = new ObjectRegistration<>(descriptor, factory);
|
||||
claim(descriptor, registering);
|
||||
claim(descriptor);
|
||||
objects.put(featureType, registration);
|
||||
}
|
||||
|
||||
@@ -112,7 +101,7 @@ public final class ModuleRegistry implements FeatureRegistry {
|
||||
checkOpen();
|
||||
var descriptor = FeatureDescriptor.of(settingsType);
|
||||
requireOwnedId("Settings " + settingsType.getName() + " with feature id", descriptor.id());
|
||||
catalogSettings(descriptor, registering);
|
||||
catalogSettings(descriptor);
|
||||
registeredByOwner.add(settingsType);
|
||||
}
|
||||
|
||||
@@ -180,7 +169,7 @@ public final class ModuleRegistry implements FeatureRegistry {
|
||||
return;
|
||||
}
|
||||
var descriptor = FeatureDescriptor.of(settingsType);
|
||||
catalogSettings(descriptor, ownerOf(descriptor));
|
||||
catalogSettings(descriptor);
|
||||
}
|
||||
|
||||
/** Whether the module owning {@code settingsType} registered it through {@link #registerSettings}. */
|
||||
@@ -196,21 +185,14 @@ public final class ModuleRegistry implements FeatureRegistry {
|
||||
return catalog;
|
||||
}
|
||||
|
||||
private void catalogSettings(FeatureDescriptor<?> descriptor, DiscoveredModule owner) {
|
||||
private void catalogSettings(FeatureDescriptor<?> descriptor) {
|
||||
if (settings.containsKey(descriptor.type())) {
|
||||
return;
|
||||
}
|
||||
claim(descriptor, owner);
|
||||
claim(descriptor);
|
||||
settings.put(descriptor.type(), descriptor);
|
||||
}
|
||||
|
||||
private DiscoveredModule ownerOf(FeatureDescriptor<?> descriptor) {
|
||||
return registered.stream()
|
||||
.filter(module -> module.info().ownsId(descriptor.id()))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new IllegalStateException("No registered module owns feature id " + descriptor.id()));
|
||||
}
|
||||
|
||||
private void requireOwnedId(String registration, ResourceId id) {
|
||||
if (registering == null) {
|
||||
throw new IllegalStateException(registration + " " + id + " registered outside IrisModule.register");
|
||||
@@ -260,53 +242,12 @@ public final class ModuleRegistry implements FeatureRegistry {
|
||||
}
|
||||
}
|
||||
|
||||
private void reserveHostFields(Map<FeatureAttachment.Target, Set<String>> reservedFields) {
|
||||
for (var entry : reservedFields.entrySet()) {
|
||||
for (var name : entry.getValue()) {
|
||||
reserveHostField(entry.getKey(), name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void reserveHostField(FeatureAttachment.Target target, String name) {
|
||||
fields.put(new Field(target, FeatureAttachment.requireFieldName(name)), "host");
|
||||
}
|
||||
|
||||
private void claim(FeatureDescriptor<?> descriptor, DiscoveredModule owner) {
|
||||
validateClaim(descriptor, owner);
|
||||
recordClaim(descriptor);
|
||||
}
|
||||
|
||||
private void validateClaim(FeatureDescriptor<?> descriptor, DiscoveredModule owner) {
|
||||
private void claim(FeatureDescriptor<?> descriptor) {
|
||||
if (featureTypes.contains(descriptor.type()) || featureIds.contains(descriptor.id())) {
|
||||
throw new IllegalArgumentException("Duplicate feature: " + descriptor.id());
|
||||
}
|
||||
descriptor.alias().ifPresent(alias -> validateAlias(descriptor, alias, owner));
|
||||
}
|
||||
|
||||
private void validateAlias(FeatureDescriptor<?> descriptor, String alias, DiscoveredModule owner) {
|
||||
if (owner.source() == DiscoveredModule.Source.PACK) {
|
||||
throw new IllegalArgumentException("Settings " + descriptor.type().getName() + " of module " + owner
|
||||
+ " set alias '" + alias + "'; only modules that ship with the host may set one, so remove it:"
|
||||
+ " packs write these settings under their id \"" + descriptor.key() + "\"");
|
||||
}
|
||||
for (var target : descriptor.attachment().targets()) {
|
||||
var field = new Field(target, alias);
|
||||
if (fields.containsKey(field)) {
|
||||
throw new IllegalArgumentException("Alias collision at " + field + " of " + descriptor.id()
|
||||
+ ": " + fields.get(field));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void recordClaim(FeatureDescriptor<?> descriptor) {
|
||||
featureTypes.add(descriptor.type());
|
||||
featureIds.add(descriptor.id());
|
||||
descriptor.alias().ifPresent(alias -> {
|
||||
for (var target : descriptor.attachment().targets()) {
|
||||
fields.put(new Field(target, alias), descriptor.id().toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void checkOpen() {
|
||||
@@ -314,6 +255,4 @@ public final class ModuleRegistry implements FeatureRegistry {
|
||||
throw new IllegalStateException("Registration has ended");
|
||||
}
|
||||
}
|
||||
|
||||
private record Field(FeatureAttachment.Target target, String name) {}
|
||||
}
|
||||
@@ -84,7 +84,7 @@ final class PackSchemaBuilder {
|
||||
FeatureSchema complete(Map<String, ObjectType> types) {
|
||||
var descriptor = catalogued.descriptor();
|
||||
return new FeatureSchema(descriptor.id(), descriptor.name(), catalogued.role(), owner.info(), descriptor.key(),
|
||||
descriptor.alias(), descriptor.attachment().targets(), types.get(descriptor.type().getName()));
|
||||
descriptor.attachment().targets(), types.get(descriptor.type().getName()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import com.volmit.resource.ResourceId;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/** A module's settings type and the JSON keys it is written under at each of its targets.
|
||||
@@ -15,8 +14,6 @@ import java.util.Set;
|
||||
* @param name the feature's display name from {@code @Feature}
|
||||
* @param module the module that owns the feature id
|
||||
* @param key the JSON key the settings are written under, the feature id, the same at every target
|
||||
* @param alias the short JSON key a built-in module accepts instead of {@code key}; pack modules
|
||||
* have none. A JSON object may use one of the two, not both.
|
||||
* @param targets where the keys appear, in {@link FeatureAttachment.Target} order
|
||||
* @param settings the settings class; its description describes the value
|
||||
*/
|
||||
@@ -26,7 +23,6 @@ public record FeatureSchema(
|
||||
FeatureRole role,
|
||||
ModuleInfo module,
|
||||
String key,
|
||||
Optional<String> alias,
|
||||
Set<FeatureAttachment.Target> targets,
|
||||
ObjectType settings) {
|
||||
public FeatureSchema {
|
||||
@@ -35,16 +31,7 @@ public record FeatureSchema(
|
||||
Objects.requireNonNull(role, "role");
|
||||
Objects.requireNonNull(module, "module");
|
||||
Objects.requireNonNull(key, "key");
|
||||
Objects.requireNonNull(alias, "alias");
|
||||
Objects.requireNonNull(settings, "settings");
|
||||
targets = Collections.unmodifiableSet(EnumSet.copyOf(targets));
|
||||
}
|
||||
|
||||
/** The settings' only option, when they have exactly one. Packs may then write that option's value
|
||||
* directly instead of an object holding it, such as {@code "snow": 0.5} for {@code "snow": {"amount": 0.5}},
|
||||
* and the host decodes a value that is not a JSON object into it.
|
||||
*/
|
||||
public Optional<SchemaOption> shorthand() {
|
||||
return settings.options().size() == 1 ? Optional.of(settings.options().getFirst()) : Optional.empty();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user