Skip to content

Commit

Permalink
Overhaul annotations, fix a ton of bad code, attempt fixing root scre…
Browse files Browse the repository at this point in the history
…en order, fail spectacularly
  • Loading branch information
calmilamsy committed Jun 25, 2024
1 parent 5830d44 commit 20bb974
Show file tree
Hide file tree
Showing 57 changed files with 606 additions and 538 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package net.modificationstation.stationapi.api.config;

import com.google.common.base.CharMatcher;
import net.modificationstation.stationapi.impl.config.DrawContextAccessor;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.screen.Screen;
import net.modificationstation.stationapi.impl.config.DrawContextAccessor;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,30 @@

/**
* The name you want to have on the button to access your category and at the top while it's open.
* @return a string, supports colour codes.
*/
String value();
String name();

/**
* The description shown to users in the scroll menu. ~30 chars max is recommended.
* @return a string, supports colour codes.
*/
String description() default "";

/**
* The comment shown inside config files. Can be as long as you want, and supports newlines. Does NOT support colour codes.
* If blank, description is shown instead.
*/
String comment() default "";

/**
* Unimplemented. Will be attached to a "?" button for users to show a fullscreen and scrollable description.
*/
String longDescription() default "";

/**
* Syncs the config entry with the server upon join, and server config change.
* Will also be able to be edited by ops in-game at a later date.
*/
boolean multiplayerSynced() default false;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package net.modificationstation.stationapi.api.config;

import java.lang.annotation.*;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@Documented
public @interface ConfigEntry {

/**
* This should be the visible name that you want users to see in the config GUI.
* @return a string, supports colour codes.
*/
String name();

/**
* The description shown to users in the scroll menu. ~30 chars max is recommended.
* @return a string, supports colour codes.
*/
String description() default "";

/**
* The comment shown inside config files. Can be as long as you want, and supports newlines. Does NOT support colour codes.
* If blank, description is shown instead.
*/
String comment() default "";

/**
* Unimplemented. Will be attached to a "?" button for users to show a fullscreen and scrollable description.
*/
String longDescription() default "";

/**
* Syncs the config entry with the server upon join, and server config change.
* Will also be able to be edited by ops in-game.
*/
boolean multiplayerSynced() default false;

/**
* The maximum length of this value.
* Default 32.
* Numeric values: the actual number value.
* Strings: how many characters.
* Applies to the contents of arrays, not the arrays themselves. See max and minArrayLength.
*/
long maxLength() default 32;

/**
* The minimum length of this value.
* Default 0.
* Numeric values: the actual number value.
* Strings: how many characters.
* Applies to the contents of arrays, not the arrays themselves. See max and minArrayLength.
*/
long minLength() default 0;

long maxArrayLength() default Short.MAX_VALUE;
long minArrayLength() default 0;


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.google.common.collect.ImmutableMap;
import net.modificationstation.stationapi.impl.config.NonFunction;
import net.modificationstation.stationapi.impl.config.object.ConfigEntry;
import net.modificationstation.stationapi.impl.config.object.ConfigEntryHandler;
import uk.co.benjiweber.expressions.function.SeptFunction;
import uk.co.benjiweber.expressions.function.SexFunction;

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

/**
* Return custom factories for certain config class types.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@Documented
public @interface GConfig {
public @interface ConfigRoot {

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

/**
* Make the config screen attached to the annotation the one that shows by default.
* The index this page uses. Those without a specified index will be added last.
*/
boolean primary() default false;
int index() default Integer.MAX_VALUE;


boolean multiplayerSynced() default false;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package net.modificationstation.stationapi.api.config;

import net.modificationstation.stationapi.impl.config.GlassYamlWrapper;

import java.lang.reflect.*;

/**
* Implement in custom types. This listener does not support java builtins because I value what little remains of my sanity.
*/
public interface FieldModifiedListener {

/**
* @param field The field. Use the field name as the yaml key if setting values in there.
* @param glassYamlWrapper The config file at the level the field is at.
* @param eventSource {@link net.modificationstation.stationapi.impl.config.EventStorage.EventSource}
*/
void fieldModified(Field field, GlassYamlWrapper glassYamlWrapper, int eventSource);
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package net.modificationstation.stationapi.api.config;

import net.fabricmc.loader.api.ModContainer;
import net.fabricmc.loader.api.entrypoint.EntrypointContainer;
import net.modificationstation.stationapi.api.util.Identifier;
import net.modificationstation.stationapi.impl.config.ConfigRootEntry;
import net.modificationstation.stationapi.impl.config.EventStorage;
import net.modificationstation.stationapi.impl.config.GCCore;
import net.modificationstation.stationapi.api.util.Identifier;
import net.modificationstation.stationapi.impl.config.GlassYamlFile;
import net.modificationstation.stationapi.impl.config.object.ConfigCategory;
import net.modificationstation.stationapi.impl.config.object.ConfigCategoryHandler;
import org.jetbrains.annotations.Nullable;
import uk.co.benjiweber.expressions.tuple.BiTuple;
import uk.co.benjiweber.expressions.tuple.QuadTuple;
import uk.co.benjiweber.expressions.tuple.TriTuple;

import java.io.*;
import java.util.concurrent.atomic.*;
Expand Down Expand Up @@ -35,15 +39,12 @@ public static void reloadConfig(Identifier configID, @Nullable String overrideCo
public static void reloadConfig(Identifier configID, @Nullable GlassYamlFile overrideConfigJson) {
AtomicReference<Identifier> mod = new AtomicReference<>();
GCCore.MOD_CONFIGS.keySet().forEach(modContainer -> {
if (modContainer.toString().equals(configID.toString())) {
mod.set(modContainer);
if (modContainer.equals(configID)) {
ConfigRootEntry category = GCCore.MOD_CONFIGS.get(mod.get());
GCCore.loadModConfig(category.configRoot(), category.modContainer(), category.configCategoryHandler().parentField, mod.get(), overrideConfigJson);
GCCore.saveConfig(category.modContainer(), category.configCategoryHandler(), EventStorage.EventSource.MOD_SAVE);
}
});
if (mod.get() != null) {
BiTuple<EntrypointContainer<Object>, ConfigCategory> category = GCCore.MOD_CONFIGS.get(mod.get());
GCCore.loadModConfig(category.one().getEntrypoint(), category.one().getProvider(), category.two().parentField, mod.get(), overrideConfigJson);
GCCore.saveConfig(category.one(), category.two(), EventStorage.EventSource.MOD_SAVE);
}
}

/**
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package net.modificationstation.stationapi.impl.config;

import com.google.common.collect.ImmutableMap;
import net.modificationstation.stationapi.api.config.MaxLength;
import net.modificationstation.stationapi.impl.config.object.ConfigEntry;
import net.modificationstation.stationapi.api.config.ConfigEntry;
import net.modificationstation.stationapi.impl.config.object.ConfigEntryHandler;
import uk.co.benjiweber.expressions.function.SeptFunction;

import java.lang.reflect.*;
import java.util.function.*;

public class ConfigFactories {

public static ImmutableMap<Type, NonFunction<String, String, String, Field, Object, Boolean, Object, Object, MaxLength, ConfigEntry<?>>> loadFactories = null;
public static ImmutableMap<Type, SeptFunction<String, ConfigEntry, Field, Object, Boolean, Object, Object, ConfigEntryHandler<?>>> loadFactories = null;
public static ImmutableMap<Type, Function<Object, Object>> saveFactories = null;

@SuppressWarnings("rawtypes")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package net.modificationstation.stationapi.impl.config;

import net.fabricmc.loader.api.ModContainer;
import net.modificationstation.stationapi.api.config.ConfigRoot;
import net.modificationstation.stationapi.impl.config.object.ConfigCategoryHandler;

public record ConfigRootEntry(
ModContainer modContainer,
ConfigRoot configRoot,
Object configObject,
ConfigCategoryHandler configCategoryHandler
) {}
Loading

0 comments on commit 20bb974

Please sign in to comment.