Respect enum insertion order, add respackopts_loaded to allow canvas shaders to check whether rpo is loaded

This commit is contained in:
JFronny 2020-12-28 09:41:02 +01:00
parent c02aa65dd2
commit 3821953a23
7 changed files with 22 additions and 19 deletions

View File

@ -30,6 +30,7 @@ To use the information from the config you will need to use and integration modu
For the ones included by default:
### Canvas
Respackopts defines a config supplier, you can include it with `#include respackopts:config_supplier`\
You can always check whether it was properly loaded by checking if `respackopts_loaded` is defined.\
Values can be accessed with `{packId}_{entryId}` for basic elements.\
Enum values can be accessed with `{packId}_{entryId}_{enumKey}`.\
Examples of using these are available [here](https://gitlab.com/JFronny/respackopts/-/tree/master/run/resourcepacks/lumi)

View File

@ -6,7 +6,7 @@ minecraft_version=1.16.4
yarn_mappings=1.16.4+build.7
loader_version=0.10.8
# Mod Properties
mod_version=1.2.0
mod_version=1.3.0
maven_group=io.gitlab.jfronny
archives_base_name=respackopts
# Dependencies

View File

@ -20,9 +20,11 @@
"thisIsCool": true,
"numberInSub": 15,
"enumInSub": [
"zthis is default",
"yay1",
"yay2",
"yay3"
"yay3",
"athis is last"
],
"enableLang": true
}

View File

@ -19,6 +19,7 @@ import net.minecraft.util.Language;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
public class GuiFactory {
@ -75,19 +76,19 @@ public class GuiFactory {
}
}
else if (e.isJsonArray()) {
TreeSet<String> ev = Respackopts.enumKeys.get(screenId).get(n);
Set<String> ev = Respackopts.enumKeys.get(screenId).get(n);
Double c = Respackopts.numVals.get(screenId).get(n);
String sel = ev.first();
String sel = "";
String def = "";
int i = 0;
for (String s1 : ev) {
if (c.intValue() == i) {
sel = s1;
}
if (i == 0) def = s1;
if (c.intValue() == i) sel = s1;
i++;
}
config.addEntry(entryBuilder.startDropdownMenu(getText(n, b), (DropdownBoxEntry.SelectionTopCellElement) DropdownMenuBuilder.TopCellElementBuilder.of(sel, (s) -> s, (s) -> new LiteralText(s)), new DropdownBoxEntry.DefaultSelectionCellCreator())
.setSuggestionMode(false)
.setDefaultValue(ev.first())
.setDefaultValue(def)
.setSelections(() -> ev.iterator())
.setSaveConsumer(v -> {
int j = 0;

View File

@ -12,25 +12,22 @@ import net.fabricmc.loader.api.FabricLoader;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Objects;
import java.util.TreeSet;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
@Environment(EnvType.CLIENT)
public class Respackopts implements ClientModInitializer {
public static HashMap<String, HashMap<String, Boolean>> boolVals;
public static HashMap<String, HashMap<String, Double>> numVals;
public static HashMap<String, HashMap<String, String>> strVals;
public static HashMap<String, HashMap<String, TreeSet<String>>> enumKeys;
public static Map<String, HashMap<String, Boolean>> boolVals;
public static Map<String, HashMap<String, Double>> numVals;
public static Map<String, HashMap<String, String>> strVals;
public static Map<String, Map<String, Set<String>>> enumKeys;
public static Gson g = new Gson();
public static GuiFactory factory = new GuiFactory();
public static final Integer metaVersion = 1;
public static HashMap<String, Respackmeta> resPackMetas = new HashMap<>();
public static Map<String, Respackmeta> resPackMetas = new HashMap<>();
public static final String ID = "respackopts";
static final Path p = FabricLoader.getInstance().getConfigDir().resolve("respackopts");
public static final HashSet<Runnable> saveActions = new HashSet<>();
public static final Set<Runnable> saveActions = new HashSet<>();
public static final String fileExtension = ".rpo";
public static boolean forceRespackReload = false;
@Override

View File

@ -48,6 +48,7 @@ public class FrexCompat implements FrexInitializer {
sb.append(i.getAndIncrement());
});
}));
sb.append("\n#define respackopts_loaded");
return sb.toString();
});
System.out.println("[respackopts] enabled frex/canvas support");

View File

@ -17,6 +17,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.TreeSet;
@ -85,7 +86,7 @@ public class ResourcePackManagerMixin {
continue;
}
if (!Respackopts.enumKeys.get(id).containsKey(n)) {
Respackopts.enumKeys.get(id).put(n, new TreeSet<>());
Respackopts.enumKeys.get(id).put(n, new LinkedHashSet<>());
}
JsonPrimitive p = element.getAsJsonPrimitive();
if (!p.isString()) {