This repository has been archived by the owner on Apr 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
207 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,74 @@ | ||
# `< Plume 🪶 Config >` | ||
|
||
## License | ||
### `Fabric` `Minecraft 1.18.2` `...` `0.0.1 α` | ||
|
||
This mod is under the MIT license. | ||
## `📖 Introduction` | ||
|
||
**Plume Config is a lightweight Configuration Library for Minecraft Mods.** | ||
|
||
If you are looking for an easy way to create, write and read configuration files for your mod, this is the library for you. Just a few simple steps will get you up and running in no time. | ||
|
||
Plume Config is using `.properties` files to store the configuration. **This is a simple and easy to read format from Java.** This means that you can easily edit the configuration files with any text editor. | ||
|
||
## `📦 Installation` | ||
|
||
**Plume Config is currently in `alpha.`** | ||
You can download alpha releases from GitHub for now. | ||
|
||
If you meet the requirements, feel free to build the library yourself. | ||
|
||
## `📝 Configuration` | ||
|
||
### `🧑💻 Example Config Content` | ||
|
||
```properties | ||
# | Category Booleans | | ||
|
||
option.test.boolean=false | ||
# Default: false | ||
|
||
|
||
# | Category Numbers | | ||
|
||
option.test.color=FF123456 | ||
# Default: FFFFFFFF | ||
|
||
option.test.int=0 | ||
# Default: 0 | ||
|
||
|
||
# | Category String Values | | ||
|
||
option.test.string=abc | ||
# Default: abc | ||
|
||
option.test.double=0.0 | ||
# Default: 0.0 | ||
``` | ||
|
||
> **Note:** | ||
> | ||
> The `#` character is used to comment out lines. This means that the line will be ignored by the library. You can define the comments in your codes to add descriptions to your configuration. | ||
> | ||
> The `=` character is used to separate the key from the value. The key must be unique to identify the value. The value can be a boolean, a number, a string or a hex-string stored integer color (custom value types will be allowed in future). | ||
> **Please refer to our wiki page for example codes.** | ||
### `📁 Structure` | ||
|
||
The configuration files are stored in the `config` folder of your Minecraft instance. The folder structure is as follows: | ||
|
||
config | ||
├── <modid> | ||
│ ├── <config1>.properties | ||
│ └── <config2>.properties | ||
└── <another_modid> | ||
└── <another_config>.properties | ||
|
||
Folder names and file names are defined by the mod developer, and there could be multiple configuration files under one folder. Plume Config will create the folders and files if they do not exist. | ||
|
||
**Please use your modid as the folder name in case of repetition with another mod.** | ||
|
||
## `📜 License` | ||
|
||
This mod is available under the `MIT license.` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/net/krlite/plumeconfig/config/api/PlumeConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package net.krlite.plumeconfig.config.api; | ||
|
||
import net.fabricmc.loader.api.FabricLoader; | ||
import net.krlite.plumeconfig.config.Config; | ||
import net.krlite.plumeconfig.config.Request; | ||
|
||
import java.nio.file.Path; | ||
|
||
public abstract class PlumeConfig extends PlumeConfigApi{ | ||
public PlumeConfig(String fileName) { | ||
request = new Request(FabricLoader.getInstance().getConfigDir(), fileName); | ||
config = new Config(request); | ||
} | ||
|
||
public PlumeConfig(String path, String fileName) { | ||
request = new Request(Path.of(FabricLoader.getInstance().getConfigDir().toString(), "/", path), fileName); | ||
config = new Config(request); | ||
} | ||
|
||
private final Config config; | ||
private final Request request; | ||
|
||
Config config() { | ||
return this.config; | ||
} | ||
} |
32 changes: 12 additions & 20 deletions
32
src/main/java/net/krlite/plumeconfig/config/api/PlumeConfigApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,31 @@ | ||
package net.krlite.plumeconfig.config.api; | ||
|
||
import net.fabricmc.loader.api.FabricLoader; | ||
import net.krlite.plumeconfig.config.Config; | ||
import net.krlite.plumeconfig.config.ConfigBuilder; | ||
import net.krlite.plumeconfig.config.PlumeConfig; | ||
import net.krlite.plumeconfig.config.Request; | ||
|
||
import java.nio.file.Path; | ||
import java.util.HashMap; | ||
|
||
public abstract class PlumeConfigApi { | ||
private final PlumeConfig plumeConfig; | ||
private final Request request; | ||
|
||
public PlumeConfigApi(String fileName) { | ||
request = new Request(FabricLoader.getInstance().getConfigDir(), fileName); | ||
plumeConfig = new PlumeConfig(request); | ||
} | ||
|
||
public PlumeConfigApi(String path, String fileName) { | ||
request = new Request(Path.of(FabricLoader.getInstance().getConfigDir().toString(), "/", path), fileName); | ||
plumeConfig = new PlumeConfig(request); | ||
} | ||
abstract class PlumeConfigApi { | ||
abstract Config config(); | ||
|
||
public abstract void read(HashMap<String, String> config); | ||
|
||
public abstract void save(ConfigBuilder configBuilder); | ||
|
||
public void load() { | ||
this.read(this.plumeConfig.read()); | ||
prepare(); | ||
this.read(this.config().read()); | ||
write(); | ||
} | ||
|
||
public void write() { | ||
prepare(); | ||
this.config().write(); | ||
} | ||
|
||
private void prepare() { | ||
ConfigBuilder configBuilder = new ConfigBuilder(); | ||
this.save(configBuilder); | ||
this.plumeConfig.prepare(configBuilder); | ||
this.plumeConfig.write(); | ||
this.config().prepare(configBuilder); | ||
} | ||
} |
5 changes: 2 additions & 3 deletions
5
src/main/java/net/krlite/plumeconfig/config/json/ConfigSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
package net.krlite.plumeconfig.config.json; | ||
|
||
import com.google.gson.JsonObject; | ||
import com.google.gson.stream.JsonReader; | ||
import net.krlite.plumeconfig.config.PlumeConfig; | ||
import net.krlite.plumeconfig.config.Config; | ||
|
||
public interface ConfigSerializer<T extends PlumeConfig> { | ||
public interface ConfigSerializer<T extends Config> { | ||
T serialize(JsonObject json); | ||
JsonObject deSerialize(T config); | ||
} |
58 changes: 58 additions & 0 deletions
58
src/main/java/net/krlite/plumeconfig/example/ExampleConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package net.krlite.plumeconfig.example; | ||
|
||
import net.krlite.plumeconfig.config.ConfigBuilder; | ||
import net.krlite.plumeconfig.config.api.PlumeConfig; | ||
import net.krlite.plumeconfig.option.*; | ||
|
||
import java.awt.*; | ||
import java.util.HashMap; | ||
|
||
public class ExampleConfig extends PlumeConfig { | ||
// The constructor, you can modify the path and file name here or leave them as parameters | ||
public ExampleConfig(String path, String fileName) { | ||
super(path, fileName); | ||
} | ||
|
||
// Define your options here using the Option* classes | ||
public OptionBoolean exampleBoolean = new OptionBoolean("The name of the example boolean", "option.example.boolean", false); | ||
public OptionDouble exampleDouble = new OptionDouble(/* The name can be null */ "option.example.double", 0.0 /* The comment can also be null */); | ||
public OptionLong exampleInt = new OptionLong("option.example.int", 0 /* The key and the default value cannot be null */); | ||
public OptionString exampleString = new OptionString("My example string", "option.example.string", "abc", "Hey, this is an example comment!"); | ||
public OptionColor exampleColor = new OptionColor("option.example.color", Color.WHITE, "Expected color value: AARRGGBB"); | ||
|
||
/** | ||
* Use config.parse() method to read from the config file. | ||
* | ||
* @param config A HashMap represents the config file, can be read by the config keys. | ||
*/ | ||
public void read(HashMap<String, String> config) { | ||
exampleBoolean.parse(config.get(exampleBoolean.getKey())); | ||
exampleDouble.parse(config.get(exampleDouble.getKey())); | ||
exampleInt.parse(config.get(exampleInt.getKey())); | ||
exampleString.parse(config.get(exampleString.getKey())); | ||
exampleColor.parse(config.get(exampleColor.getKey())); | ||
} | ||
|
||
/** | ||
* Put the values you want to append to the config file here. | ||
* | ||
* @param configBuilder A ConfigBuilder object, use configBuilder.accept() to append to the config file. | ||
*/ | ||
public void save(ConfigBuilder configBuilder) { | ||
// We can append categories | ||
configBuilder.accept("Category Booleans"); | ||
// Append an option (do not do it twice to the same option) | ||
configBuilder.accept(exampleBoolean); | ||
|
||
// Another category | ||
configBuilder.accept("Category Numbers"); | ||
configBuilder.accept(exampleDouble); | ||
configBuilder.accept(exampleInt); | ||
|
||
configBuilder.accept("Category String Values"); | ||
configBuilder.accept(exampleString); | ||
configBuilder.accept(exampleColor); | ||
|
||
// ...More options and categories | ||
} | ||
} |
Oops, something went wrong.