- add shader code generation
- initialize data on resource load
This commit is contained in:
parent
64f2373877
commit
2c8ede637d
|
@ -13,7 +13,6 @@ import net.minecraft.util.Language;
|
|||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class GuiFactory {
|
||||
public void buildCategory(JsonObject source, String screenId, ConfigCategory config, ConfigEntryBuilder entryBuilder) {
|
||||
|
@ -42,7 +41,10 @@ public class GuiFactory {
|
|||
Respackopts.boolVals.get(screenId).put(n, defaultValue);
|
||||
config.addEntry(entryBuilder.startBooleanToggle(getText(n, b), currentValue)
|
||||
.setDefaultValue(defaultValue)
|
||||
.setSaveConsumer(v -> Respackopts.boolVals.get(screenId).put(n, v))
|
||||
.setSaveConsumer(v -> {
|
||||
Respackopts.updateShaders();
|
||||
Respackopts.boolVals.get(screenId).put(n, v);
|
||||
})
|
||||
.build());
|
||||
}
|
||||
else if (p.isNumber()) {
|
||||
|
@ -54,7 +56,10 @@ public class GuiFactory {
|
|||
Respackopts.numVals.get(screenId).put(n, defaultValue);
|
||||
config.addEntry(entryBuilder.startDoubleField(getText(n, b), currentValue)
|
||||
.setDefaultValue(defaultValue)
|
||||
.setSaveConsumer(v -> Respackopts.numVals.get(screenId).put(n, v))
|
||||
.setSaveConsumer(v -> {
|
||||
Respackopts.updateShaders();
|
||||
Respackopts.numVals.get(screenId).put(n, v);
|
||||
})
|
||||
.build());
|
||||
}
|
||||
else if (p.isString()) {
|
||||
|
@ -66,7 +71,10 @@ public class GuiFactory {
|
|||
Respackopts.strVals.get(screenId).put(n, defaultValue);
|
||||
config.addEntry(entryBuilder.startStrField(getText(n, b), currentValue)
|
||||
.setDefaultValue(defaultValue)
|
||||
.setSaveConsumer(v -> Respackopts.strVals.get(screenId).put(n, v))
|
||||
.setSaveConsumer(v -> {
|
||||
Respackopts.updateShaders();
|
||||
Respackopts.strVals.get(screenId).put(n, v);
|
||||
})
|
||||
.build());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ public class Respackopts implements ClientModInitializer {
|
|||
@Override
|
||||
public void onInitializeClient() {
|
||||
load();
|
||||
Respackopts.updateShaders();
|
||||
}
|
||||
|
||||
public static void save() {
|
||||
|
@ -92,4 +93,27 @@ public class Respackopts implements ClientModInitializer {
|
|||
if (strVals == null)
|
||||
strVals = new HashMap<>();
|
||||
}
|
||||
|
||||
public static void updateShaders() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
numVals.forEach((s, v) -> v.forEach((s1, v1) -> {
|
||||
sb.append("\n");
|
||||
sb.append("#define ");
|
||||
sb.append(s);
|
||||
sb.append("_");
|
||||
sb.append(s1);
|
||||
sb.append(" ");
|
||||
sb.append(v1);
|
||||
}));
|
||||
boolVals.forEach((s, v) -> v.forEach((s1, v1) -> {
|
||||
if (v1) {
|
||||
sb.append("\n");
|
||||
sb.append("#define ");
|
||||
sb.append(s);
|
||||
sb.append("_");
|
||||
sb.append(s1);
|
||||
}
|
||||
}));
|
||||
System.out.println(sb.toString());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package io.gitlab.jfronny.respackopts.mixin;
|
|||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import io.gitlab.jfronny.respackopts.Respackopts;
|
||||
import io.gitlab.jfronny.respackopts.data.Respackmeta;
|
||||
import net.minecraft.resource.ResourcePackManager;
|
||||
|
@ -18,6 +19,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Mixin(ResourcePackManager.class)
|
||||
|
@ -30,18 +32,51 @@ public class ResourcePackManagerMixin {
|
|||
if (hasMetadata(v, "conf.json")) {
|
||||
try {
|
||||
Respackmeta conf = Respackopts.g.fromJson(readMetadata(v, "conf.json", Respackopts.g), Respackmeta.class);
|
||||
if (!Respackopts.boolVals.containsKey(conf.id))
|
||||
Respackopts.boolVals.put(conf.id, new HashMap<>());
|
||||
if (!Respackopts.numVals.containsKey(conf.id))
|
||||
Respackopts.numVals.put(conf.id, new HashMap<>());
|
||||
if (!Respackopts.strVals.containsKey(conf.id))
|
||||
Respackopts.strVals.put(conf.id, new HashMap<>());
|
||||
for (Map.Entry<String, JsonElement> entry : conf.conf.entrySet()) {
|
||||
String n = entry.getKey();
|
||||
if (n.contains(":") || n.contains(".")) {
|
||||
System.err.println(n + " contains invalid characters");
|
||||
continue;
|
||||
}
|
||||
JsonElement e = entry.getValue();
|
||||
if (e.isJsonPrimitive()) {
|
||||
JsonPrimitive p = e.getAsJsonPrimitive();
|
||||
if (p.isBoolean()) {
|
||||
if (!Respackopts.boolVals.get(conf.id).containsKey(n))
|
||||
Respackopts.boolVals.get(conf.id).put(n, p.getAsBoolean());
|
||||
}
|
||||
else if (p.isNumber()) {
|
||||
if (!Respackopts.numVals.get(conf.id).containsKey(n))
|
||||
Respackopts.numVals.get(conf.id).put(n, p.getAsDouble());
|
||||
}
|
||||
else if (p.isString()) {
|
||||
if (!Respackopts.strVals.get(conf.id).containsKey(n))
|
||||
Respackopts.strVals.get(conf.id).put(n, p.getAsString());
|
||||
}
|
||||
}
|
||||
else {
|
||||
System.err.println("[respackopts] Unsupported non-primitive datatype");
|
||||
}
|
||||
}
|
||||
if (Respackopts.metaVersion.equals(conf.version)) {
|
||||
Respackopts.resPackMetas.put(v.getDisplayName().asString(), conf);
|
||||
}
|
||||
else {
|
||||
System.err.println(s + " was not loaded as it specifies a different respackopts version than is installed");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
Respackopts.load();
|
||||
Respackopts.updateShaders();
|
||||
Respackopts.save();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user