Skip to content

Commit

Permalink
Revert "wip new config stuff, commented the variant blacklist out"
Browse files Browse the repository at this point in the history
This reverts commit 317af31.

Had to be done because the build script would have an aneurysm with this for some reason
  • Loading branch information
UnlikePaladin committed Feb 19, 2024
1 parent bae54a5 commit 9d468fd
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 1,039 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
MinecraftClient.getInstance().setScreen(parent);
}, new TranslatableText("gui.pfm.changesMightNotBeSaved").setStyle(Style.EMPTY.withColor(0xf77f34).withBold(true)), new TranslatableText("gui.pfm.saveChanges")));
return true;
} else if (optionListWidget.keyPressed(keyCode, scanCode, modifiers))
return true;
}
return super.keyPressed(keyCode, scanCode, modifiers);
}

Expand Down Expand Up @@ -81,24 +80,14 @@ protected void init() {
if (option.getDefaultValue() != this.optionListWidget.newConfigValues.get(option)) {
this.optionListWidget.hasChanges.set(this.optionListWidget.configOptionToIndexForHasChanges.get(option), true);
}
this.optionListWidget.newConfigValues.put(option, option.getDefaultValue());
} else if (option.getType() == String.class) {
if (option.getDefaultValue() != this.optionListWidget.newConfigValues.get(option)) {
this.optionListWidget.hasChanges.set(this.optionListWidget.configOptionToIndexForHasChanges.get(option), true);
}
this.optionListWidget.newConfigValues.put(option, option.getDefaultValue());
this.optionListWidget.newConfigValues.put(option, (Boolean) option.getDefaultValue());
}
} else if (!isOnServer && option.getSide() == Side.SERVER) {
if (option.getType() == Boolean.class) {
if (option.getDefaultValue() != this.optionListWidget.newConfigValues.get(option)) {
this.optionListWidget.hasChanges.set(this.optionListWidget.configOptionToIndexForHasChanges.get(option), true);
}
this.optionListWidget.newConfigValues.put(option, option.getDefaultValue());
} else if (option.getType() == String.class) {
if (option.getDefaultValue() != this.optionListWidget.newConfigValues.get(option)) {
this.optionListWidget.hasChanges.set(this.optionListWidget.configOptionToIndexForHasChanges.get(option), true);
}
this.optionListWidget.newConfigValues.put(option, option.getDefaultValue());
this.optionListWidget.newConfigValues.put(option, (Boolean) option.getDefaultValue());
}
}
});
Expand All @@ -122,7 +111,7 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {

drawCenteredText(matrices, this.textRenderer, TITLE.setStyle(Style.EMPTY.withColor(0xf77f34).withBold(true)), this.width / 2, 8, 0xFFFFFF);
boolean bl = false;
for (Map.Entry<AbstractConfigOption, Object> optionEntry : optionListWidget.newConfigValues.entrySet()) {
for (Map.Entry<AbstractConfigOption, Boolean> optionEntry : optionListWidget.newConfigValues.entrySet()) {
if (optionEntry.getValue() == optionEntry.getKey().getDefaultValue()) continue;
bl = true;
break;
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import com.google.gson.*;
import com.google.gson.reflect.TypeToken;
import com.unlikepaladin.pfm.PaladinFurnitureMod;
import com.unlikepaladin.pfm.config.option.*;
import com.unlikepaladin.pfm.config.option.AbstractConfigOption;
import com.unlikepaladin.pfm.config.option.BooleanConfigOption;
import com.unlikepaladin.pfm.config.option.Side;
import net.minecraft.text.TranslatableText;

import java.io.*;
Expand Down Expand Up @@ -40,7 +42,6 @@ public PaladinFurnitureModConfig(Path propertiesPath) {
mobsSitOnChairs = new BooleanConfigOption(new TranslatableText("pfm.option.mobsSitOnChairs"), new TranslatableText("pfm.option.mobsSitOnChairs.tooltip"), GAMEPLAY_OPTIONS, true, Side.SERVER),
renderImmersivePortalsMirrors = new BooleanConfigOption(new TranslatableText("pfm.option.renderImmersivePortalsMirrors"), new TranslatableText("pfm.option.renderImmersivePortalsMirrors.tooltip"), GAMEPLAY_OPTIONS, true, Side.CLIENT),
spawnImmersivePortalsMirror = new BooleanConfigOption(new TranslatableText("pfm.option.spawnImmersivePortalsMirror"), new TranslatableText("pfm.option.spawnImmersivePortalsMirror.tooltip"), GAMEPLAY_OPTIONS, true, Side.SERVER)
// variantBlacklist = new StringArrayConfigOption(new TranslatableText("pfm.option.variantBlacklist"), new TranslatableText("pfm.option.variantBlacklist.tooltip"), GAMEPLAY_OPTIONS, new ArrayList<>(), Side.SERVER) alas it is not ready yet
);
this.propertiesPath = propertiesPath.resolve("pfm.json");
this.directoryPath = propertiesPath;
Expand Down Expand Up @@ -126,7 +127,6 @@ public boolean doImmersivePortalsMirrorsSpawn() {
private BooleanConfigOption mobsSitOnChairs;
private BooleanConfigOption renderImmersivePortalsMirrors;
private BooleanConfigOption spawnImmersivePortalsMirror;
// private StringArrayConfigOption variantBlacklist;


public Path getPath() {
Expand Down Expand Up @@ -165,17 +165,7 @@ public void load() throws IOException {
mobsSitOnChairs.setValue(getFromJsonElement(config.get("mobsSitOnChairs"), false));
renderImmersivePortalsMirrors.setValue(getFromJsonElement(config.get("renderImmersivePortalsMirrors"), true));
spawnImmersivePortalsMirror.setValue(getFromJsonElement(config.get("spawnImmersivePortalsMirror"), true));
/* JsonObject object = getFromJsonElement(config.get("variantBlacklist"), new JsonObject());
if (object != null && object.isJsonArray()) {
JsonArray variantBlackListArray = object.getAsJsonArray();
// Extract strings from the array
List<String> stringList = new ArrayList<>();
for (JsonElement arrayElement : variantBlackListArray) {
stringList.add(arrayElement.getAsString());
}
variantBlacklist.addAll(stringList);
}*/

for (String key : options.keySet()) {
if (!config.has(key.replace("pfm.option.", ""))){
PaladinFurnitureMod.GENERAL_LOGGER.warn("Missing Config Option: " + key.replace("pfm.option.", "") + ", resetting to default value.");
Expand Down Expand Up @@ -249,17 +239,9 @@ public void save() throws IOException {
object.addProperty("mobsSitOnChairs", mobsSitOnChairs.getValue());
object.addProperty("renderImmersivePortalsMirrors", renderImmersivePortalsMirrors.getValue());
object.addProperty("spawnImmersivePortalsMirror", spawnImmersivePortalsMirror.getValue());
// object.add("variantBlacklist", toJsonElement(variantBlacklist.getValue()));

try (FileWriter writer = new FileWriter(propertiesPath.toString())) {
GSON.toJson(object, writer);
}
}

public JsonElement toJsonElement(String[] stringArray) {
JsonArray jsonArray = new JsonArray();
for (String value : stringArray) {
jsonArray.add(new JsonPrimitive(value));
}
return jsonArray;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@
import java.io.IOException;
import java.util.Objects;

public interface AbstractConfigOption<T extends Object> extends Comparable<String> {
public abstract class AbstractConfigOption<T> implements Comparable<String> {
public static final byte NULL_TYPE = 0;
public static final byte BOOL_TYPE = 1;
public static final byte STRING_TYPE = 2;
public static final byte STRING_ARRAY_TYPE = 3;
public static final byte LIST_TYPE = 4;

public abstract Text getTitle();

Expand Down Expand Up @@ -50,6 +47,10 @@ public static Side getSide(String string) {
}
return null;
}
@Override
public String toString() {
return "{Type: " + getType() + ", Title: " + ((TranslatableText)getTitle()).getKey() + ", Category: " + getCategory() + ", Value: " + getValue() + ", Side:" + getSide() + "}";
}

public abstract void write(DataOutput output) throws IOException;

Expand Down Expand Up @@ -86,12 +87,8 @@ public static AbstractConfigOption readConfigOption(PacketByteBuf packetByteBuf,
}
}

public default String asString() {
return "{Type: " + getType() + ", Title: " + ((TranslatableText)getTitle()).getKey() + ", Category: " + getCategory() + ", Value: " + getValue() + ", Side:" + getSide() + "}";
}

@Override
public default int compareTo(@NotNull String o) {
public int compareTo(@NotNull String o) {
return this.getCategory().compareTo(o);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@
import java.io.DataOutput;
import java.io.IOException;

public class BooleanConfigOption implements AbstractConfigOption<Boolean>{
public class BooleanConfigOption extends AbstractConfigOption<Boolean>{
public static final ConfigOptionType<BooleanConfigOption> TYPE = new ConfigOptionType<>() {
public BooleanConfigOption read(DataInput dataInput, int i, ConfigSizeTracker sizeTracker) throws IOException {
sizeTracker.add(2400L);
public BooleanConfigOption read(DataInput dataInput, int i, ConfigSizeTracker nbtTagSizeTracker) throws IOException {
nbtTagSizeTracker.add(2400L);
String title = dataInput.readUTF();
String tooltip = dataInput.readUTF();
String category = dataInput.readUTF();
boolean value = dataInput.readBoolean();
Side side = AbstractConfigOption.getSide(dataInput.readUTF());
sizeTracker.add(224L + 16L * title.length());
sizeTracker.add(224L + 16L * tooltip.length());
sizeTracker.add(224L + 16L * category.length());
sizeTracker.add(64L);
Side side = getSide(dataInput.readUTF());
nbtTagSizeTracker.add(224L + 16L * title.length());
nbtTagSizeTracker.add(224L + 16L * tooltip.length());
nbtTagSizeTracker.add(224L + 16L * category.length());
nbtTagSizeTracker.add(64L);
BooleanConfigOption booleanConfigOption = new BooleanConfigOption(new TranslatableText(title), new TranslatableText(tooltip), category, value, side);
return booleanConfigOption;
}

public String getCrashReportName() {
return "BOOL-OPTION";
return "END";
}

public boolean isImmutable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.jetbrains.annotations.Nullable;

import java.io.*;
import java.util.ArrayList;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;

Expand Down Expand Up @@ -74,7 +73,7 @@ public static AbstractConfigOption read(DataInput input, ConfigSizeTracker track

protected static void write(AbstractConfigOption element, DataOutput output) throws IOException {
output.writeByte(element.getConfigType());
if (element.getType() != Boolean.class && element.getType() != ArrayList.class && element.getType() != String.class && element.getType() != String[].class) {
if (element.getType() != Boolean.class) {
PaladinFurnitureMod.GENERAL_LOGGER.warn("Unsupported Type: " + element.getType());
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public String getCrashReportName() {
}

@Override
public NullConfigOption read(DataInput input, int depth, ConfigSizeTracker tracker) throws IOException {
public /* synthetic */ NullConfigOption read(DataInput input, int depth, ConfigSizeTracker tracker) throws IOException {
throw new IllegalArgumentException("Invalid Config id: " + type);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public class ConfigOptionTypes {
//
private static final ConfigOptionType<?>[] VALUES = new ConfigOptionType[]{NullConfigOption.TYPE, BooleanConfigOption.TYPE, StringConfigOption.TYPE, StringArrayConfigOption.TYPE, ListConfigOption.TYPE};
private static final ConfigOptionType<?>[] VALUES = new ConfigOptionType[]{NullConfigOption.TYPE, BooleanConfigOption.TYPE};

public static ConfigOptionType<?> byId(int id) {
if (id < 0 || id >= VALUES.length) {
Expand Down
Loading

0 comments on commit 9d468fd

Please sign in to comment.