mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
Let modules declare pack resource kinds and validators: ResourceKind, PackResources.ids, @ResourceRef, the validation API and folders the host reserves
This commit is contained in:
1 parent
09afee8ae3
commit
ef4b640867
37 files changed
+990
-128
No files matched your search
@@ -13,9 +13,11 @@ public record OptionsMetadata(String description, String snippet, List<Option> o
|
||||
options = List.copyOf(options);
|
||||
}
|
||||
|
||||
/** One field of a settings type. {@code minimum}, {@code maximum} and {@code reference} are null when not declared. */
|
||||
/** One field of a settings type. {@code minimum}, {@code maximum}, {@code reference} and {@code resource} are null
|
||||
* when not declared; {@code resource} is the class of {@link ResourceRef}.
|
||||
*/
|
||||
public record Option(Field field, String description, boolean required,
|
||||
Double minimum, Double maximum, Reference reference) {
|
||||
Double minimum, Double maximum, Reference reference, Class<?> resource) {
|
||||
public String name() {
|
||||
return field.getName();
|
||||
}
|
||||
@@ -45,6 +47,7 @@ public record OptionsMetadata(String description, String snippet, List<Option> o
|
||||
var min = field.getAnnotation(MinNumber.class);
|
||||
var max = field.getAnnotation(MaxNumber.class);
|
||||
var ref = field.getAnnotation(Ref.class);
|
||||
var resourceRef = field.getAnnotation(ResourceRef.class);
|
||||
if ((min != null || max != null) && !isNumeric(field.getType())) {
|
||||
throw new IllegalArgumentException("Numeric bounds on nonnumeric option: " + field.getName());
|
||||
}
|
||||
@@ -55,7 +58,7 @@ public record OptionsMetadata(String description, String snippet, List<Option> o
|
||||
}
|
||||
options.add(new Option(field, desc == null ? "" : desc.value(), field.isAnnotationPresent(Required.class),
|
||||
min == null ? null : min.value(), max == null ? null : max.value(),
|
||||
ref == null ? null : ref.value()));
|
||||
ref == null ? null : ref.value(), resourceRef == null ? null : resourceRef.value()));
|
||||
}
|
||||
}
|
||||
var desc = type.getAnnotation(Desc.class);
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.volmit.config;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/** Says that an option names a resource of the module resource kind read into {@code value}, by its key in the
|
||||
* pack, such as {@code @ResourceRef(Pool.class) String startPool = "castle/start"}. Studio then offers the keys
|
||||
* of that kind's files. Allowed on {@code String} options and lists, sets and arrays of them; the class must be
|
||||
* the type of a resource kind some module of the pack registers. Anywhere else it fails the pack load.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface ResourceRef {
|
||||
Class<?> value();
|
||||
}
|
||||
Reference in new issue
Block a user