mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-17 01:15:52 +01:00
Revert "Fix dropType de-serialization"
This commit is contained in:
@@ -5,7 +5,6 @@ import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gson.stream.*;
|
||||
import emu.grasscutter.data.common.DynamicFloat;
|
||||
import emu.grasscutter.game.world.*;
|
||||
import emu.grasscutter.utils.objects.DropType;
|
||||
import it.unimi.dsi.fastutil.floats.FloatArrayList;
|
||||
import it.unimi.dsi.fastutil.ints.*;
|
||||
import lombok.val;
|
||||
@@ -53,24 +52,6 @@ public interface JsonAdapters {
|
||||
public void write(JsonWriter writer, DynamicFloat f) {}
|
||||
}
|
||||
|
||||
class DropTypeAdapter extends TypeAdapter<DropType> {
|
||||
@Override
|
||||
public void write(JsonWriter out, DropType value) throws IOException {
|
||||
if (value.isString())
|
||||
out.value(value.getAsString());
|
||||
else out.value(value.getAsInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DropType read(JsonReader in) throws IOException {
|
||||
return switch (in.peek()) {
|
||||
default -> new DropType(0);
|
||||
case STRING -> new DropType(in.nextString());
|
||||
case NUMBER -> new DropType(in.nextInt());
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class IntListAdapter extends TypeAdapter<IntList> {
|
||||
@Override
|
||||
public IntList read(JsonReader reader) throws IOException {
|
||||
|
||||
@@ -3,23 +3,27 @@ package emu.grasscutter.utils;
|
||||
import com.google.gson.*;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import emu.grasscutter.data.common.DynamicFloat;
|
||||
import emu.grasscutter.game.world.*;
|
||||
import emu.grasscutter.game.world.GridPosition;
|
||||
import emu.grasscutter.game.world.Position;
|
||||
import emu.grasscutter.utils.JsonAdapters.*;
|
||||
import emu.grasscutter.utils.objects.*;
|
||||
import emu.grasscutter.utils.objects.JObject;
|
||||
import it.unimi.dsi.fastutil.ints.IntList;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.*;
|
||||
import java.util.*;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public final class JsonUtils {
|
||||
static final Gson gson =
|
||||
new GsonBuilder()
|
||||
.setPrettyPrinting()
|
||||
.registerTypeAdapter(DynamicFloat.class, new DynamicFloatAdapter())
|
||||
.registerTypeAdapter(DropType.class, new DropTypeAdapter())
|
||||
.registerTypeAdapter(IntList.class, new IntListAdapter())
|
||||
.registerTypeAdapter(Position.class, new PositionAdapter())
|
||||
.registerTypeAdapter(GridPosition.class, new GridPositionAdapter())
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
package emu.grasscutter.utils.objects;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public final class DropType {
|
||||
private final Object raw;
|
||||
private final int value;
|
||||
|
||||
public DropType(int value) {
|
||||
this.raw = value;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public DropType(String value) {
|
||||
this.raw = value;
|
||||
this.value = switch (value) {
|
||||
default -> Integer.parseInt(value);
|
||||
case "ForceDrop" -> 2;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Whether the drop type value is a string.
|
||||
*/
|
||||
public boolean isString() {
|
||||
return this.raw instanceof String;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The drop type value as a string.
|
||||
*/
|
||||
public String getAsString() {
|
||||
if (this.raw instanceof String)
|
||||
return (String) this.raw;
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The drop type value as an integer.
|
||||
*/
|
||||
public int getAsInt() {
|
||||
if (this.raw instanceof Integer)
|
||||
return (int) this.raw;
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user