Skip to content

Commit 8a1521a

Browse files
committed
fix accordion issue with field types and fix field-type buttons
1 parent 21b9bcd commit 8a1521a

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ dgt.java.version=8
1212
# Project Configuration
1313
project.group=org.polyfrost.oneconfig
1414
project.name=OneConfig
15-
project.version=1.0.0-alpha.69+dgt
15+
project.version=1.0.0-alpha.70

modules/config-impl/src/main/java/org/polyfrost/oneconfig/api/config/v1/collect/impl/OneConfigCollector.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ protected void handleField(@NotNull Field f, @NotNull Object src, @NotNull Tree
8484
Tree t = Tree.tree(f.getName());
8585
t.addMetadata(MHUtils.getAnnotationValues(a).getOrThrow());
8686
try {
87-
handle(t, f.get(src), 1);
87+
handle(t, MHUtils.instantiate(f.getType(), true).getOrThrow(), 1);
8888
} catch (Throwable e) {
8989
throw new RuntimeException("Failed to collect accordion-type field " + f.getName(), e);
9090
}
@@ -94,7 +94,14 @@ protected void handleField(@NotNull Field f, @NotNull Object src, @NotNull Tree
9494
if (opt == null) continue;
9595
try {
9696
Property<?> p;
97-
if (type == Button.class) p = Properties.dummy();
97+
if (type == Button.class) {
98+
p = Properties.dummy();
99+
try {
100+
p.addMetadata("runnable", (Runnable) MHUtils.setAccessible(f).get(src));
101+
} catch (Throwable e) {
102+
throw new RuntimeException("Couldn't extract button method from field " + f.getName() + ", is it of type Runnable?", e);
103+
}
104+
}
98105
else p = Properties.field(null, null, f, src);
99106
handleMetadata(tree, p, a, opt, f);
100107
tree.put(p);

modules/config-impl/src/main/java/org/polyfrost/oneconfig/api/config/v1/collect/impl/ReflectiveCollector.java

+8
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ public ReflectiveCollector(int maxDepth) {
6060

6161

6262
public void handle(@NotNull Tree tree, @NotNull Object src, int depth) {
63+
if (src == null) {
64+
LOGGER.error("Failed to collect properties for {} from object {} as the object was null", tree.getID(), src);
65+
return;
66+
}
67+
if (tree == null) {
68+
LOGGER.error("Failed to collect properties for {} from object {} as the tree was null", tree.getID(), src);
69+
return;
70+
}
6371
Class<?> cls = src.getClass();
6472
for (Field f : cls.getDeclaredFields()) {
6573
handleField(f, src, tree);

modules/config-impl/src/main/kotlin/org/polyfrost/oneconfig/api/config/v1/Visualizer.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ fun interface Visualizer {
4949
class ButtonVisualizer : Visualizer {
5050
override fun visualize(prop: Property<*>): Drawable {
5151
val text = prop.getMetadata<String>("text")?.strv()
52-
val action = prop.getMetadata<Runnable>("runnable") ?: prop.getAs()
52+
val action: Runnable? = prop.getMetadata<Runnable>("runnable") ?: prop.getAs<Runnable?>()
53+
require(action != null) { "Button property $prop is missing a runnable, set it with either the metadata key 'runnable' or the property value" }
5354
return Button(
5455
size = Vec2(300f, 32f),
5556
text = text ?: "oneconfig.button.default",

0 commit comments

Comments
 (0)