重新配置

重新配置

我的模组配置库

基础库

reconfigure

为我的模组打造的配置库

Documentation Available for fabric Requires fabric api Available on Modrinth See me on GitHub Chat on Discord

设计目标

  • 采用构建器模式,因此所有选项都支持自动补全。只需从 Config.builder() 开始,自动补全将引导你完成创建配置的整个过程
  • 设计用于在配置类的字段初始化器中使用
  • 不使用注解,以便在运行时保持灵活性

预览

基础控件 高级控件

定义示例

class DemoConfig {
    public final Config CONFIG = Config.builder("reconfigure-test")
            .serializer(Serializers.JSON)
            .build();
    public final ConfigTab DEMO_TAB = CONFIG.createTab("demo").build();
    Void HEADLINE = DEMO_TAB.createHeadline("headline");
    public final Property<String> STRING = DEMO_TAB.createStringProperty("string").defaultValue("Hello world")
            .asTextField().placeholder("Enter something").build();
    public final Property<Boolean> CHECKBOX = DEMO_TAB.createBooleanProperty("checkbox").defaultValue(true)
            .asCheckbox().build();
    public final Property<Boolean> TOGGLE_BUTTON = DEMO_TAB.createBooleanProperty("toggle_button")
            .asToggleButton().build();
    public final Property<Integer> SLIDER = DEMO_TAB.createIntegerProperty("slider").defaultValue(4).range(1,10)
            .asSlider().build();

    public final Property<DayOfWeek> CYCLE_BUTTON = DEMO_TAB
            .createEnumProperty("cycle_button", DayOfWeek.class)
            .defaultValue(DayOfWeek.MONDAY)
            .asCyclingButton()
            .build();

    public final Property<Integer> COLOR = DEMO_TAB.createIntegerProperty("color").asColorPicker().build();
    public final Property<String> EDIT_BOX = DEMO_TAB.createStringProperty("box").asEditBox().build();
    public final Property<List<String>> CHIP_LIST = DEMO_TAB.createListProperty("chiplist")
            .asChipList()
            .build();
}