package dev.isxander.yacl3.config.v2.api.serializer; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import dev.isxander.yacl3.config.ConfigEntry; import dev.isxander.yacl3.config.v2.api.ConfigClassHandler; import dev.isxander.yacl3.config.v2.api.ConfigSerializer; import dev.isxander.yacl3.config.v2.api.SerialEntry; import dev.isxander.yacl3.config.v2.impl.serializer.GsonConfigSerializer; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Style; import java.awt.*; import java.nio.file.Path; import java.util.function.UnaryOperator; /** * Uses GSON to serialize and deserialize config data from JSON to a file. *

* Only fields annotated with {@link dev.isxander.yacl3.config.v2.api.SerialEntry} are included in the JSON. * {@link Component}, {@link Style} and {@link Color} have default type adapters, so there is no need to provide them in your GSON instance. * GSON is automatically configured to format fields as {@code lower_camel_case}. *

* Optionally, this can also be written under JSON5 spec, allowing comments. * * @param config data type */ public interface GsonConfigSerializerBuilder { static GsonConfigSerializerBuilder create(ConfigClassHandler config) { return new GsonConfigSerializer.Builder<>(config); } /** * Sets the file path to save and load the config from. */ GsonConfigSerializerBuilder setPath(Path path); /** * Sets the GSON instance to use. Overrides all YACL defaults such as: *

* Still respects the exclusion strategy to only serialize {@link ConfigEntry} * but these can be added to with setExclusionStrategies. * * @param gsonBuilder gson builder to use */ GsonConfigSerializerBuilder overrideGsonBuilder(GsonBuilder gsonBuilder); /** * Sets the GSON instance to use. Overrides all YACL defaults such as: * * but these can be added to with setExclusionStrategies. * * @param gson gson instance to be converted to a builder */ GsonConfigSerializerBuilder overrideGsonBuilder(Gson gson); /** * Appends extra configuration to a GSON builder. * This is the intended way to add functionality to the GSON instance. *

* By default, YACL sets the GSON with the following options: *

* For example, if you wanted to revert YACL's lower_camel_case naming policy, * you could do the following: *
     * {@code
     * GsonConfigSerializerBuilder.create(config)
     *         .appendGsonBuilder(builder -> builder.setFieldNamingPolicy(FieldNamingPolicy.IDENTITY))
     * }
     * 
* * @param gsonBuilder the function to apply to the builder */ GsonConfigSerializerBuilder appendGsonBuilder(UnaryOperator gsonBuilder); /** * Writes the json under JSON5 spec, allowing the use of {@link SerialEntry#comment()}. * If enabling this option it's recommended to use the file extension {@code .json5}. * * @param json5 whether to write under JSON5 spec * @return this builder */ GsonConfigSerializerBuilder setJson5(boolean json5); ConfigSerializer build(); }