Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Commit

Permalink
version 3.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
KrLite committed Dec 21, 2022
1 parent 52819cf commit 1b68653
Show file tree
Hide file tree
Showing 13 changed files with 256 additions and 110 deletions.
49 changes: 40 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ repositories {
dependencies {
// Please use modApi instead of something else
// Versions lower than v3.0.0 are outdated, and versions that are not latest are not recommended
modApi include("maven.modrinth:plumeconfig:v3.0.0")
modApi include("maven.modrinth:plumeconfig:v3.1.0")
// Plume Config is using TOMLJ, so you need to implement it as well
implementation "org.tomlj:tomlj:1.1.0"
Expand All @@ -48,12 +48,17 @@ Then, rebuild the gradle and you are ready to go.
```toml
# 1
# comment2
s = "string" # String | A String Comment
# commented line
integer = 1 # Int
bool = false

[abc]
s = "string" # String | A String Comment
# comment3
d = 1.0

[def]
color = 0xff000000
bool = false
```

## Usage
Expand Down Expand Up @@ -156,6 +161,28 @@ line\
String!"""
```

One of the main features of TOML is categories(work as dotted keys), and Plume Config also supports it by using the `@Category` annotation:

```java
@Category("abc")
public @Comment String catComment="Categorized Comment";

public String uncat="Uncategorized";

@Category("abc")
public @Option String cat="Categorized";
```

```toml
uncat = "Uncategorized"

[abc]
# Categorized Comment
cat = "Categorized"
```

> The order of the fields is not important, Plume Config will sort them automatically by categories.
That's how it works. Now write some configs into your class:

```java
Expand All @@ -168,12 +195,14 @@ public class MyConfig {
@Option(comment = "Change this number smaller to make your mouse faster")
public double d = 1.0;

@Comment public String comment = "=-= Be careful changing the options below =-=";
@Category("misc")
@Comment public String comment = "=-Misc-=";

@Option(comment = "The only identity in the map")
public int color = Color.BLACK;

@Option(name = "Streaming switch", comment = "Toggle the streaming mode")

@Category("misc")
@Option(name = "Streaming switch", comment = "Toggle streaming mode")
public boolean bool = false;
}
```
Expand All @@ -198,9 +227,11 @@ Your config file(`run/config/my_modid/my_config.toml`) will look like this:
```toml
player_name = "Lambda Sigma" # Player Name | Your name in the game
d = 1.0 # Change this number smaller to make your mouse faster
# =-= Be careful changing the options below =-=
color = 0xff000000 # The only identity in the map
bool = false # Streaming switch | Toggle the streaming mode

[misc]
# =-Misc-=
bool = false # Streaming switch | Toggle streaming mode
```

In your code, make sure everytime you load your mod, you read your config first.
Expand Down Expand Up @@ -231,7 +262,7 @@ public class MyModInitializer implements ModInitializer {
}
```

Pretty cool, right? Plume Config doesn't support all toml features now, like dotted keys and categories. But we are always working to make everything better, and just watch our project if you are interested in the progress!
Pretty cool, right? Plume Config doesn't support all toml features now, but we are always making everything better. Just watch our project if you are interested in the progress!

## License

Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version = 1.19.2
minecraft_version = 1.19
yarn_mappings = 1.19.2+build.28
loader_version = 0.14.10

# Mod Properties
mod_version = 3.0.0
mod_version = 3.1.0
maven_group = net.krlite
archives_base_name = plume-config

Expand Down
36 changes: 16 additions & 20 deletions src/main/java/example/Example.java
Original file line number Diff line number Diff line change
@@ -1,39 +1,35 @@
package example;

import net.krlite.plumeconfig.annotation.Category;
import net.krlite.plumeconfig.annotation.Comment;
import net.krlite.plumeconfig.annotation.Option;

import java.awt.*;

public class Example {
// This is an integer comment
public @Comment int comment = 1;
public @Comment int comment = 1; // Integer comment

// This is a string comment
public @Comment String comment2 = "comment2";
public @Comment String comment2 = "comment2\ncommented line"; // Multi-line comment

// This is a string option
@Option(name = "String", comment = "A String Comment")
public String s = "string";
@Option(name = "String", comment = "A String\n Comment")
@Category("abc")
public String s = "string"; // A String option named "String" with a comment(line breaks will be ignored)

// This is an integer option
@Option(key = "integer", name = "Int")
@Option(key = "integer", name = "Int") // An Integer option named "Int" with a specified key "integer"
public int i = 1;

// This is a string comment
private final @Comment String comment3 = "comment3";
@Category("abc")
private final @Comment String comment3 = "comment3"; // A comment in the category "abc"

// This is a double option, but final, so cannot be changed
private static final @Option double d = 1.0;
@Category("abc")
private static final @Option double d = 1.0; // A double option in the category "abc"

// This is a regular field to not being read and written
public static int silent = 1;
public static int silent = 1; // No annotations, will be ignored

public static int silent2 = 1;
private static final int silent2 = 1;

// This is a color option
public static @Option Color color = Color.BLACK;
@Category("def")
public static @Option Color color = Color.BLACK; // A Color option in the category "def"

// This is a boolean option
public static @Option boolean bool;
public static @Option boolean bool; // A boolean option
}
5 changes: 2 additions & 3 deletions src/main/java/example/ExampleModInitializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
public class ExampleModInitializer implements ModInitializer {
@Override
public void onInitialize() {
ConfigFile config = new ConfigFile("example", new File("/config/example.toml"));
Example example = config.load(Example.class);
config.save(example);
ConfigFile config = new ConfigFile("example");
Example example = config.loadAndSave(Example.class);
}
}
11 changes: 8 additions & 3 deletions src/main/java/example/config/example.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# 1
# comment2
s = "string" # String | A String Comment
# commented line
integer = 1 # Int
bool = false

[abc]
s = "string" # String | A String Comment
# comment3
d = 1.0
color = 0xff000000
bool = false

[def]
color = 0xff000000
13 changes: 13 additions & 0 deletions src/main/java/example/config/example_unformatted.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 1
# comment2
# commented line
integer = 1 # Int
bool = false
[abc]
s = "string" # String | A String Comment
[abc]
# comment3
[abc]
d = 1.0
[def]
color = 0xff000000
39 changes: 0 additions & 39 deletions src/main/java/net/krlite/plumeconfig/Example.java

This file was deleted.

4 changes: 0 additions & 4 deletions src/main/java/net/krlite/plumeconfig/PlumeConfigMod.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.krlite.plumeconfig;

import net.fabricmc.api.ModInitializer;
import net.krlite.plumeconfig.base.ConfigFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -13,8 +12,5 @@ public class PlumeConfigMod implements ModInitializer {

@Override
public void onInitialize() {
ConfigFile config = new ConfigFile("plumeconfig");
Example example = config.load(Example.class);
config.save(example);
}
}
12 changes: 12 additions & 0 deletions src/main/java/net/krlite/plumeconfig/annotation/Category.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package net.krlite.plumeconfig.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Category {
String value();
}
Loading

0 comments on commit 1b68653

Please sign in to comment.