Skip to content

Commit

Permalink
Code fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
calmilamsy committed Jun 29, 2024
1 parent 70fb0fd commit 0d2389b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.google.common.collect.ImmutableMap;
import net.modificationstation.stationapi.api.config.ConfigFactoryProvider;
import net.modificationstation.stationapi.api.config.ConfigEntry;
import net.modificationstation.stationapi.impl.config.NonFunction;
import net.modificationstation.stationapi.impl.config.object.ConfigEntryHandler;
import net.modificationstation.stationapi.impl.config.object.entry.BooleanConfigEntryHandler;
import net.modificationstation.stationapi.impl.config.object.entry.FloatConfigEntryHandler;
Expand All @@ -12,7 +11,6 @@
import net.modificationstation.stationapi.impl.config.object.entry.IntegerListConfigEntryHandler;
import net.modificationstation.stationapi.impl.config.object.entry.StringConfigEntryHandler;
import net.modificationstation.stationapi.impl.config.object.entry.StringListConfigEntryHandler;
import uk.co.benjiweber.expressions.function.OctFunction;
import uk.co.benjiweber.expressions.function.SeptFunction;

import java.lang.reflect.*;
Expand All @@ -28,9 +26,9 @@ public void provideLoadFactories(ImmutableMap.Builder<Type, SeptFunction<String,
immutableBuilder.put(Integer.class, ((id, configEntry, parentField, parentObject, isMultiplayerSynced, value, defaultValue) -> new IntegerConfigEntryHandler(id, configEntry, parentField, parentObject, isMultiplayerSynced, Integer.valueOf(String.valueOf(value)), Integer.valueOf(String.valueOf(defaultValue)))));
immutableBuilder.put(Float.class, ((id, configEntry, parentField, parentObject, isMultiplayerSynced, value, defaultValue) -> new FloatConfigEntryHandler(id, configEntry, parentField, parentObject, isMultiplayerSynced, Float.valueOf(String.valueOf(value)), Float.valueOf(String.valueOf(defaultValue)))));
immutableBuilder.put(Boolean.class, ((id, configEntry, parentField, parentObject, isMultiplayerSynced, value, defaultValue) -> new BooleanConfigEntryHandler(id, configEntry, parentField, parentObject, isMultiplayerSynced, (boolean) value, (boolean) defaultValue)));
immutableBuilder.put(String[].class, ((id, configEntry, parentField, parentObject, isMultiplayerSynced, value, defaultValue) -> new StringListConfigEntryHandler(id, configEntry, parentField, parentObject, isMultiplayerSynced, ((ArrayList<String>) value).toArray(new String[0]), (String[]) defaultValue))); // the new ArrayList is required or it returns java.util.Arrays.ArrayList, which is fucking dumb.
immutableBuilder.put(Integer[].class, ((id, configEntry, parentField, parentObject, isMultiplayerSynced, value, defaultValue) -> new IntegerListConfigEntryHandler(id, configEntry, parentField, parentObject, isMultiplayerSynced, ((ArrayList<Integer>) value).toArray(new Integer[0]), (Integer[]) defaultValue)));
immutableBuilder.put(Float[].class, ((id, configEntry, parentField, parentObject, isMultiplayerSynced, value, defaultValue) -> new FloatListConfigEntryHandler(id, configEntry, parentField, parentObject, isMultiplayerSynced, ((ArrayList<Float>) value).toArray(new Float[0]), (Float[]) defaultValue)));
immutableBuilder.put(String[].class, ((id, configEntry, parentField, parentObject, isMultiplayerSynced, value, defaultValue) -> new StringListConfigEntryHandler(id, configEntry, parentField, parentObject, isMultiplayerSynced, listOrArrayToArray(value, new String[0]), (String[]) defaultValue)));
immutableBuilder.put(Integer[].class, ((id, configEntry, parentField, parentObject, isMultiplayerSynced, value, defaultValue) -> new IntegerListConfigEntryHandler(id, configEntry, parentField, parentObject, isMultiplayerSynced, listOrArrayToArray(value, new Integer[0]), (Integer[]) defaultValue)));
immutableBuilder.put(Float[].class, ((id, configEntry, parentField, parentObject, isMultiplayerSynced, value, defaultValue) -> new FloatListConfigEntryHandler(id, configEntry, parentField, parentObject, isMultiplayerSynced, listOrArrayToArray(value, new Float[0]), (Float[]) defaultValue)));
}

@Override
Expand All @@ -44,7 +42,15 @@ public void provideSaveFactories(ImmutableMap.Builder<Type, Function<Object, Obj
immutableBuilder.put(Float[].class, DefaultFactoryProvider::justPass);
}

private static <T> T justPass(T object) {
public static <T> T justPass(T object) {
return object;
}

public static <T> T[] listOrArrayToArray(Object object, T[] type) {
if (object instanceof List<?> list) {
return list.toArray(type);
}
//noinspection unchecked // If this isn't right, we're fucked anyways
return (T[]) object;
}
}
1 change: 0 additions & 1 deletion src/test/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
"net.modificationstation.sltest.gcapi.ExampleConfig"
],
"gcapi:factory_provider": [
"net.modificationstation.stationapi.impl.config.factory.DefaultFactoryProvider",
"net.modificationstation.sltest.gcapi.ExampleConfigEnumFactories"
],
"gcapi:postload": [
Expand Down

0 comments on commit 0d2389b

Please sign in to comment.