Skip to content

Commit 20bb974

Browse files
committed
Overhaul annotations, fix a ton of bad code, attempt fixing root screen order, fail spectacularly
1 parent 5830d44 commit 20bb974

57 files changed

Lines changed: 606 additions & 538 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/CharacterUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package net.modificationstation.stationapi.api.config;
22

33
import com.google.common.base.CharMatcher;
4-
import net.modificationstation.stationapi.impl.config.DrawContextAccessor;
54
import net.minecraft.client.font.TextRenderer;
65
import net.minecraft.client.gui.screen.Screen;
6+
import net.modificationstation.stationapi.impl.config.DrawContextAccessor;
77
import org.lwjgl.opengl.GL11;
88
import org.lwjgl.opengl.GL12;
99

glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/Comment.java

Lines changed: 0 additions & 8 deletions
This file was deleted.

glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/ConfigCategory.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,30 @@
99

1010
/**
1111
* The name you want to have on the button to access your category and at the top while it's open.
12+
* @return a string, supports colour codes.
1213
*/
13-
String value();
14+
String name();
15+
16+
/**
17+
* The description shown to users in the scroll menu. ~30 chars max is recommended.
18+
* @return a string, supports colour codes.
19+
*/
20+
String description() default "";
21+
22+
/**
23+
* The comment shown inside config files. Can be as long as you want, and supports newlines. Does NOT support colour codes.
24+
* If blank, description is shown instead.
25+
*/
26+
String comment() default "";
27+
28+
/**
29+
* Unimplemented. Will be attached to a "?" button for users to show a fullscreen and scrollable description.
30+
*/
31+
String longDescription() default "";
32+
33+
/**
34+
* Syncs the config entry with the server upon join, and server config change.
35+
* Will also be able to be edited by ops in-game at a later date.
36+
*/
37+
boolean multiplayerSynced() default false;
1438
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package net.modificationstation.stationapi.api.config;
2+
3+
import java.lang.annotation.*;
4+
5+
@Retention(RetentionPolicy.RUNTIME)
6+
@Target(ElementType.FIELD)
7+
@Documented
8+
public @interface ConfigEntry {
9+
10+
/**
11+
* This should be the visible name that you want users to see in the config GUI.
12+
* @return a string, supports colour codes.
13+
*/
14+
String name();
15+
16+
/**
17+
* The description shown to users in the scroll menu. ~30 chars max is recommended.
18+
* @return a string, supports colour codes.
19+
*/
20+
String description() default "";
21+
22+
/**
23+
* The comment shown inside config files. Can be as long as you want, and supports newlines. Does NOT support colour codes.
24+
* If blank, description is shown instead.
25+
*/
26+
String comment() default "";
27+
28+
/**
29+
* Unimplemented. Will be attached to a "?" button for users to show a fullscreen and scrollable description.
30+
*/
31+
String longDescription() default "";
32+
33+
/**
34+
* Syncs the config entry with the server upon join, and server config change.
35+
* Will also be able to be edited by ops in-game.
36+
*/
37+
boolean multiplayerSynced() default false;
38+
39+
/**
40+
* The maximum length of this value.
41+
* Default 32.
42+
* Numeric values: the actual number value.
43+
* Strings: how many characters.
44+
* Applies to the contents of arrays, not the arrays themselves. See max and minArrayLength.
45+
*/
46+
long maxLength() default 32;
47+
48+
/**
49+
* The minimum length of this value.
50+
* Default 0.
51+
* Numeric values: the actual number value.
52+
* Strings: how many characters.
53+
* Applies to the contents of arrays, not the arrays themselves. See max and minArrayLength.
54+
*/
55+
long minLength() default 0;
56+
57+
long maxArrayLength() default Short.MAX_VALUE;
58+
long minArrayLength() default 0;
59+
60+
61+
}

glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/ConfigFactoryProvider.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import com.google.common.collect.ImmutableMap;
44
import net.modificationstation.stationapi.impl.config.NonFunction;
5-
import net.modificationstation.stationapi.impl.config.object.ConfigEntry;
5+
import net.modificationstation.stationapi.impl.config.object.ConfigEntryHandler;
6+
import uk.co.benjiweber.expressions.function.SeptFunction;
7+
import uk.co.benjiweber.expressions.function.SexFunction;
68

79
import java.lang.reflect.*;
810
import java.util.function.*;
@@ -14,7 +16,7 @@ public interface ConfigFactoryProvider {
1416
* @param immutableBuilder Arguments for the OctFunction are: id, name, description, field, parentObject, value, multiplayerSynced, maxLength.
1517
* Should return a class returning a config entry for your custom config type.
1618
*/
17-
void provideLoadFactories(ImmutableMap.Builder<Type, NonFunction<String, String, String, Field, Object, Boolean, Object, Object, MaxLength, ConfigEntry<?>>> immutableBuilder);
19+
void provideLoadFactories(ImmutableMap.Builder<Type, SeptFunction<String, ConfigEntry, Field, Object, Boolean, Object, Object, ConfigEntryHandler<?>>> immutableBuilder);
1820

1921
/**
2022
* Return custom factories for certain config class types.

glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/ConfigName.java

Lines changed: 0 additions & 15 deletions
This file was deleted.

glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/GConfig.java renamed to glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/ConfigRoot.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
@Retention(RetentionPolicy.RUNTIME)
66
@Target(ElementType.FIELD)
77
@Documented
8-
public @interface GConfig {
8+
public @interface ConfigRoot {
99

1010
/**
1111
* The identifier of this config entrypoint. !!!MUST BE UNIQUE FROM OTHER CONFIGS IN YOUR MOD!!!
@@ -18,7 +18,10 @@
1818
String visibleName();
1919

2020
/**
21-
* Make the config screen attached to the annotation the one that shows by default.
21+
* The index this page uses. Those without a specified index will be added last.
2222
*/
23-
boolean primary() default false;
23+
int index() default Integer.MAX_VALUE;
24+
25+
26+
boolean multiplayerSynced() default false;
2427
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package net.modificationstation.stationapi.api.config;
2+
3+
import net.modificationstation.stationapi.impl.config.GlassYamlWrapper;
4+
5+
import java.lang.reflect.*;
6+
7+
/**
8+
* Implement in custom types. This listener does not support java builtins because I value what little remains of my sanity.
9+
*/
10+
public interface FieldModifiedListener {
11+
12+
/**
13+
* @param field The field. Use the field name as the yaml key if setting values in there.
14+
* @param glassYamlWrapper The config file at the level the field is at.
15+
* @param eventSource {@link net.modificationstation.stationapi.impl.config.EventStorage.EventSource}
16+
*/
17+
void fieldModified(Field field, GlassYamlWrapper glassYamlWrapper, int eventSource);
18+
}

glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/GCAPI.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
package net.modificationstation.stationapi.api.config;
22

3+
import net.fabricmc.loader.api.ModContainer;
34
import net.fabricmc.loader.api.entrypoint.EntrypointContainer;
5+
import net.modificationstation.stationapi.api.util.Identifier;
6+
import net.modificationstation.stationapi.impl.config.ConfigRootEntry;
47
import net.modificationstation.stationapi.impl.config.EventStorage;
58
import net.modificationstation.stationapi.impl.config.GCCore;
6-
import net.modificationstation.stationapi.api.util.Identifier;
79
import net.modificationstation.stationapi.impl.config.GlassYamlFile;
8-
import net.modificationstation.stationapi.impl.config.object.ConfigCategory;
10+
import net.modificationstation.stationapi.impl.config.object.ConfigCategoryHandler;
911
import org.jetbrains.annotations.Nullable;
1012
import uk.co.benjiweber.expressions.tuple.BiTuple;
13+
import uk.co.benjiweber.expressions.tuple.QuadTuple;
14+
import uk.co.benjiweber.expressions.tuple.TriTuple;
1115

1216
import java.io.*;
1317
import java.util.concurrent.atomic.*;
@@ -35,15 +39,12 @@ public static void reloadConfig(Identifier configID, @Nullable String overrideCo
3539
public static void reloadConfig(Identifier configID, @Nullable GlassYamlFile overrideConfigJson) {
3640
AtomicReference<Identifier> mod = new AtomicReference<>();
3741
GCCore.MOD_CONFIGS.keySet().forEach(modContainer -> {
38-
if (modContainer.toString().equals(configID.toString())) {
39-
mod.set(modContainer);
42+
if (modContainer.equals(configID)) {
43+
ConfigRootEntry category = GCCore.MOD_CONFIGS.get(mod.get());
44+
GCCore.loadModConfig(category.configRoot(), category.modContainer(), category.configCategoryHandler().parentField, mod.get(), overrideConfigJson);
45+
GCCore.saveConfig(category.modContainer(), category.configCategoryHandler(), EventStorage.EventSource.MOD_SAVE);
4046
}
4147
});
42-
if (mod.get() != null) {
43-
BiTuple<EntrypointContainer<Object>, ConfigCategory> category = GCCore.MOD_CONFIGS.get(mod.get());
44-
GCCore.loadModConfig(category.one().getEntrypoint(), category.one().getProvider(), category.two().parentField, mod.get(), overrideConfigJson);
45-
GCCore.saveConfig(category.one(), category.two(), EventStorage.EventSource.MOD_SAVE);
46-
}
4748
}
4849

4950
/**

glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/LongDescription.java

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)