Skip to content

Commit

Permalink
Add enums to supported values
Browse files Browse the repository at this point in the history
  • Loading branch information
OroArmor committed Feb 4, 2021
1 parent 9d9ca87 commit e540d78
Show file tree
Hide file tree
Showing 18 changed files with 881 additions and 827 deletions.
50 changes: 26 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies {
The best way to use my config is to extend `com.oroarmor.config.Config` with your own class. Inside this class, you should include other classes that extend `com.oroarmor.config.ConfigItemGroup` for your config groups. See the [example](#example) for a way to use the library.

### Config Item
`ConfigItem`s are the main storage of the different values that make up your config. Currently the only supported types are `String`, `Double`, `Integer`, and `Boolean` (Technically `ConfigItemGroup`s, but those are extremely different). There are two constructors for `ConfigItem`:
`ConfigItem`s are the main storage of the different values that make up your config. Currently the only supported types are `String`, `Double`, `Integer`, `Boolean`, and all enums (Technically `ConfigItemGroup`s, but those are extremely different). There are two constructors for `ConfigItem`:
```java
ConfigItem(String name, T defaultValue, String details)
```
Expand Down Expand Up @@ -77,37 +77,38 @@ These are pulled from the testmod, and are part of this repositiory. [Test Mod](
Config Class:
```java
public class TestConfig extends Config {
public static final ConfigItemGroup mainGroup = new ConfigGroupLevel1();
public static final ConfigItemGroup mainGroup = new ConfigGroupLevel1();

public static final List<ConfigItemGroup> configs = of(mainGroup);
public static final List<ConfigItemGroup> configs = of(mainGroup);

public TestConfig() {
super(configs, new File(FabricLoader.getInstance().getConfigDir().toFile(), "oroarmor_config_testmod.json"), "oroarmor_config_testmod");
}
public TestConfig() {
super(configs, new File(FabricLoader.getInstance().getConfigDir().toFile(), "oroarmor_config_testmod.json"), "oroarmor_config_testmod");
}

public static class ConfigGroupLevel1 extends ConfigItemGroup {
public static class NestedGroup extends ConfigItemGroup {
public static class TripleNested extends ConfigItemGroup {
public static final ConfigItem<String> testString = new ConfigItem<String>("test_string", "Default", "test_string");
public static class ConfigGroupLevel1 extends ConfigItemGroup {
public static final ConfigItem<EnumTest> testEnum = new ConfigItem<>("test_enum", EnumTest.A, "test_enum");
public static final ConfigItem<Boolean> testItem = new ConfigItem<Boolean>("test_boolean", true, "test_boolean");

public TripleNested() {
super(of(testString), "triple");
public ConfigGroupLevel1() {
super(of(new NestedGroup(), testItem, testEnum), "group");
}
}

public static final ConfigItem<Integer> nestedItem = new ConfigItem<Integer>("test_int", 0, "test_integer");
public static class NestedGroup extends ConfigItemGroup {
public static final ConfigItem<Integer> nestedItem = new ConfigItem<Integer>("test_int", 0, "test_integer");

public NestedGroup() {
super(of(nestedItem, new TripleNested()), "nested");
}
}
public NestedGroup() {
super(of(nestedItem, new TripleNested()), "nested");
}

public static final ConfigItem<Boolean> testItem = new ConfigItem<Boolean>("test_boolean", true, "test_boolean");
public static class TripleNested extends ConfigItemGroup {
public static final ConfigItem<String> testString = new ConfigItem<String>("test_string", "Default", "test_string");

public ConfigGroupLevel1() {
super(of(new NestedGroup(), testItem), "group");
public TripleNested() {
super(of(testString), "triple");
}
}
}
}
}
}
```
This then creates a config file called `oroarmor_config_testmod.json` in the `/config/` directory wherever Minecraft is run:
Expand All @@ -120,14 +121,15 @@ This then creates a config file called `oroarmor_config_testmod.json` in the `/c
"test_string": "Default"
}
},
"test_boolean": true
"test_boolean": true,
"test_enum": "A"
}
}
```

Command Registration:
```java
CommandRegistrationCallback.EVENT.register(new ConfigCommand(YOUR_CONFIG));
CommandRegistrationCallback.EVENT.register(new ConfigCommand(YOUR_CONFIG)::register);
```

Mod Menu Integration:
Expand Down
8 changes: 5 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '0.5-SNAPSHOT'
id 'fabric-loom' version '0.6-SNAPSHOT'
id 'maven-publish'
id 'com.jfrog.bintray' version "1.8.4"
}
Expand All @@ -11,6 +11,8 @@ repositories {
}
}

project.version = project.mod_version

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

Expand All @@ -33,7 +35,7 @@ dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
// Fabric API. This is technically optional, but you probably want it anyway.
testmodCompile "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
include(modImplementation(fabricApi.module("fabric-command-api-v1", project.fabric_version)))

modCompile("io.github.prospector:modmenu:1.14.6+build.31") {
exclude(module: "fabric-api")
Expand All @@ -53,7 +55,7 @@ processResources {

from(sourceSets.main.resources.srcDirs) {
include "fabric.mod.json"
expand "version": project.version
expand "version": project.mod_version
}

from(sourceSets.main.resources.srcDirs) {
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ org.gradle.jvmargs=-Xmx2G
loader_version=0.10.0+build.208

# Mod Properties
mod_version = 1.1.0
mod_version = 1.2.0
maven_group = com.oroarmor
archives_base_name = oro-config

# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
fabric_version= 0.29.4+1.16
fabric_version= 0.30.0+1.16
Loading

0 comments on commit e540d78

Please sign in to comment.