Support respackopts.json5 instead of assets/respackopts/conf.json

This commit is contained in:
Johannes Frohnmeyer 2022-08-28 20:43:13 +02:00
parent 7c368fab76
commit a7379d1405
Signed by: Johannes
GPG Key ID: E76429612C2929F4
11 changed files with 69 additions and 54 deletions

View File

@ -18,7 +18,7 @@ Any number input that provides a minimum and maximum value will be displayed as
```json
{
id: "examplePack",
version: 6,
version: 9,
capabilities: ["FileFilter", "DirFilter"],
conf: {
someOption: {
@ -43,7 +43,7 @@ Their type is `enum`
```json
{
id: "examplePack",
version: 6,
version: 9,
capabilities: ["FileFilter", "DirFilter"],
conf: {
someOption: {

View File

@ -10,7 +10,7 @@ This file contains all applied config options as saved by respackopts.
## Dump the internal representation
Running `/rpoc dump config` will dump all data available about the enabled packs, including their config options (but not individual configurations like .rpo files)
You can use this if a conf.json isn't working as expected
You can use this if a respackopts.json5 isn't working as expected
## Dump GLSL code
You can run the command `/rpoc dump glsl` to dump the shader code generated by respackopts to a file.

View File

@ -5,17 +5,14 @@ Any pack id or config entry name MUST only contain alphabetical characters (no n
If that is not the case, you may face unexpected issues.
You can add [translations](./Translations.md) to work around this in the UI shown to users though.
### Location (ResourcePacks).
> `/assets/respackopts/conf.json`
### Creating a config
In order to start using Respackopts, you must first add a config file to your pack.
To do so, add a customized version of the following to your pack as `/respackopts.json5`:
### Location (DataPacks).
> `/data/respackopts/conf.json`
### What needs to be here.
```json
{
id: "<PackID>",
version: 8,
version: 9,
capabilities: ["FileFilter", "DirFilter"],
conf: {
// Your config options here
@ -37,7 +34,7 @@ To add a boolean entry, add code like this: `"entryName": <Default Option (true/
```json
{
id: "examplePack",
version: 8,
version: 9,
capabilities: ["FileFilter", "DirFilter"],
conf: {
someTexture: true,
@ -58,7 +55,7 @@ A number box follows the same principle as a boolean: `"entryName": Default Numb
```json
{
id: "examplePack",
version: 8,
version: 9,
capabilities: ["FileFilter", "DirFilter"],
conf: {
someOption: 10
@ -79,7 +76,7 @@ To allow users to select one entry from a list, you can use a json array with st
```json
{
id: "examplePack",
version: 8,
version: 9,
capabilities: ["FileFilter", "DirFilter"],
conf: {
someOption: [
@ -99,7 +96,7 @@ To allow users to select one entry from a list, you can use a json array with st
```json
{
id: "examplePack",
version: 8,
version: 9,
capabilities: ["FileFilter", "DirFilter"],
conf: {
someCategory: {

View File

@ -71,4 +71,5 @@ Corresponds to version 4.0.0
- New config screen backend powered by LibJF (needed to support serverside)
- New translation key syntax
- Removal of manual configuration for sliders vs input boxes
- Removal of manual configuration for sliders vs input boxes
- Support for respackopts configs in the pack root (`/respackopts.json5` instead of `/assets/respackopts/conf.json`)

View File

@ -1,7 +1,7 @@
# Select one of multiple files
This Allows you to pick between multiple files (3 or more files) using similar logic to [Toggle Files](./ToggleFiles.md)
But this requires multiple `.rpo` files to achieve the desired goal.
You will need the `PackID` and `EntryName` from your `/assets/respackopts/conf.json` that you created earlier
You will need the `PackID` and `EntryName` from your `respackopts.json5` that you created earlier
if you have not, see [Main Config](./MainConfig.md) on how to do so.
<br>

View File

@ -3,7 +3,7 @@ Sometimes, you may wish to use respackopts values inside your text files (for ex
without switching between a bunch of similar files. For this purpose, respackopts allows replacing text in files via resource expansion.
You can use the `expansions` block in your .rpo to replace content with a value computed through executing a custom [μScript](https://gitlab.com/JFronny/java-commons/-/tree/master/muscript) block.
Values can be accessed in the script in a the same exact way as in condition objects,
Values can be accessed in the script in the same exact way as in condition objects,
as the same language and object representation is used, though the result of a script is a string and not a boolean here.
I should probably point out here that, since the result here is always a string,
@ -11,11 +11,11 @@ string concatenation via the `||` operator is possible and recommended.
For example, the following is a valid script: `'Text ' || (someNumber * 15) || someBoolean`
### Example:
conf.json:
respackopts.json5:
```json
{
id: "examplePack",
version: 6,
version: 9,
capabilities: ["FileFilter", "DirFilter"],
conf: {
oakFence: {

View File

@ -1,7 +1,7 @@
# Toggle Files
A condition can be looked at like an `IF` statement simply returning true/false to configure whether the texture/file should be loaded into the pack.
(Turns the texture "on" or "off").
You will need the `Pack ID` and `Entry Name` from your `/assets/respackopts/conf.json` that you created earlier
You will need the `Pack ID` and `Entry Name` from your `respackopts.json5` that you created earlier
if you have not, see [Main Config](./MainConfig.md) on how to do so.
<br>
@ -33,7 +33,7 @@ Directories ("Folders") can also be toggled without toggling individual files.
To do this, create a file in the directory you want to toggle titled `.rpo` (no file name).
Both conditions and fallbacks work like they do on files, however, specifying multiple fallbacks
for a directory will not work. In some cases, you may need to add `"DirFilterAdditive"`
to your `capabilities` inside your conf.json for fallbacks to work as expected.
to your `capabilities` inside your respackopts.json5 for fallbacks to work as expected.
Please be aware that you should NOT specify it unless you are SURE you need it, as it will worsen performance.
See [Switch between two files](./ToggleFilesWithFallback.md) to see how to swap textures out with each other (alternate Options)

View File

@ -1,7 +1,7 @@
# Switch between two files
This is a simple `IF` statement simply returning true/false to if the texture/file should be loaded into the pack.
(Pick one file over another).
You will need the `Pack ID` and `Entry Name` from your `/assets/respackopts/conf.json` that you created earlier
You will need the `Pack ID` and `Entry Name` from your `respackopts.json5` that you created earlier
if you have not, see [Main Config](./MainConfig.md) on how to do so.
<br>

View File

@ -14,8 +14,7 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.*;
import java.nio.file.Path;
import java.util.HashSet;
import java.util.Map;
@ -31,37 +30,34 @@ public class ResourcePackManagerMixin {
Set<Path> toRemove = new HashSet<>(dataLocations);
dataLocations.clear();
profiles.forEach((s, v) -> {
ResourcePack rpi = v.createResourcePack();
ResourceType packConfType = null;
for (ResourceType type : ResourceType.values()) {
if (rpi.contains(type, Respackopts.CONF_ID)) {
packConfType = type;
try (ResourcePack rpi = v.createResourcePack()) {
Path dataLocation = null;
if (rpi instanceof AbstractFileResourcePack arr) {
Path pack = arr.getBase().toPath();
dataLocation = pack.getParent().resolve(pack.getFileName().toString() + Respackopts.FILE_EXTENSION);
}
}
if (packConfType != null) {
try (InputStream is = rpi.open(packConfType, Respackopts.CONF_ID); InputStreamReader isr = new InputStreamReader(is)) {
String displayName = v.getDisplayName().getString();
String packName = rpi.getName();
PackMeta conf = Respackopts.GSON.fromJson(isr, PackMeta.class);
if (RespackoptsConfig.debugLogs)
Respackopts.LOGGER.info("Discovered pack: " + conf.id);
if (Respackopts.META_VERSION < conf.version) {
Respackopts.LOGGER.error(displayName + " was not loaded as it specifies a newer respackopts version than is installed");
return;
try (InputStream is = rpi.openRoot(Respackopts.ID + ".json5")) {
readConfiguration(is, dataLocation, rpi.getName(), v.getDisplayName().getString(), toRemove);
return;
} catch (ResourceNotFoundException ignored) {
} catch (IOException e) {
Respackopts.LOGGER.error("Could not read respackopts config in root");
}
ResourceType packConfType = null;
for (ResourceType type : ResourceType.values()) {
if (rpi.contains(type, Respackopts.CONF_ID)) {
packConfType = type;
}
Path dataLocation;
if (rpi instanceof AbstractFileResourcePack arr) {
Path pack = ((AbstractFileResourcePackAccessor)arr).getBase().toPath();
dataLocation = pack.getParent().resolve(pack.getFileName().toString() + Respackopts.FILE_EXTENSION);
}
if (packConfType != null) {
try (InputStream is = rpi.open(packConfType, Respackopts.CONF_ID)) {
readConfiguration(is, dataLocation, rpi.getName(), v.getDisplayName().getString(), toRemove);
} catch (Throwable e) {
Respackopts.LOGGER.error("Could not initialize pack meta for " + s, e);
}
else {
dataLocation = Respackopts.FALLBACK_CONF_DIR.resolve(conf.id + ".json");
}
MetaCache.addFromScan(displayName, packName, conf, dataLocation);
dataLocations.add(dataLocation);
toRemove.remove(dataLocation);
} catch (Throwable e) {
Respackopts.LOGGER.error("Could not initialize pack meta for " + s, e);
}
}
});
@ -71,4 +67,20 @@ public class ResourcePackManagerMixin {
}
MetaCache.save(SaveHook.Arguments.DO_NOTHING);
}
private void readConfiguration(InputStream is, Path dataLocation, String packName, String displayName, Set<Path> toRemove) throws IOException {
try (InputStreamReader isr = new InputStreamReader(is)) {
PackMeta conf = Respackopts.GSON.fromJson(isr, PackMeta.class);
if (RespackoptsConfig.debugLogs)
Respackopts.LOGGER.info("Discovered pack: " + conf.id);
if (Respackopts.META_VERSION < conf.version) {
Respackopts.LOGGER.error(displayName + " was not loaded as it specifies a newer respackopts version than is installed");
return;
}
if (dataLocation == null) dataLocation = Respackopts.FALLBACK_CONF_DIR.resolve(conf.id + ".json");
MetaCache.addFromScan(displayName, packName, conf, dataLocation);
dataLocations.add(dataLocation);
toRemove.remove(dataLocation);
}
}
}

View File

@ -42,11 +42,16 @@
"fabricloader": ">=0.12.0",
"fabric": "*",
"minecraft": "*",
"libjf-data-manipulation-v0": ">=3.0.0",
"libjf-base": ">=3.0.0",
"libjf-data-manipulation-v0": ">=3.0.0",
"libjf-config-core-v1": ">=3.0.0"
},
"conflicts": {
"libjf": "<2.0"
"libjf": "<3.0.0"
},
"custom": {
"loom:injected_interfaces": {
"net/minecraft/class_3255": ["io/gitlab/jfronny/respackopts/mixin/AbstractFileResourcePackAccessor"]
}
}
}