| 1 | package net.minecraft.client.resources.data;
|
| 2 |
|
| 3 | import com.google.gson.JsonDeserializationContext;
|
| 4 | import com.google.gson.JsonElement;
|
| 5 | import com.google.gson.JsonObject;
|
| 6 | import com.google.gson.JsonParseException;
|
| 7 | import java.lang.reflect.Type;
|
| 8 | import net.minecraft.util.JsonUtils;
|
| 9 | import org.apache.commons.lang3.Validate;
|
| 10 |
|
| 11 | public class FontMetadataSectionSerializer extends BaseMetadataSectionSerializer<FontMetadataSection>
|
| 12 | {
|
| 13 | public FontMetadataSection deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
|
| 14 | {
|
| 15 | JsonObject jsonobject = p_deserialize_1_.getAsJsonObject();
|
| 16 | float[] afloat = new float[256];
|
| 17 | float[] afloat1 = new float[256];
|
| 18 | float[] afloat2 = new float[256];
|
| 19 | float f = 1.0F;
|
| 20 | float f1 = 0.0F;
|
| 21 | float f2 = 0.0F;
|
| 22 |
|
| 23 | if (jsonobject.has("characters"))
|
| 24 | {
|
| 25 | if (!jsonobject.get("characters").isJsonObject())
|
| 26 | {
|
| 27 | throw new JsonParseException("Invalid font->characters: expected object, was " + jsonobject.get("characters"));
|
| 28 | }
|
| 29 |
|
| 30 | JsonObject jsonobject1 = jsonobject.getAsJsonObject("characters");
|
| 31 |
|
| 32 | if (jsonobject1.has("default"))
|
| 33 | {
|
| 34 | if (!jsonobject1.get("default").isJsonObject())
|
| 35 | {
|
| 36 | throw new JsonParseException("Invalid font->characters->default: expected object, was " + jsonobject1.get("default"));
|
| 37 | }
|
| 38 |
|
| 39 | JsonObject jsonobject2 = jsonobject1.getAsJsonObject("default");
|
| 40 | f = JsonUtils.getFloat(jsonobject2, "width", f);
|
| 41 | Validate.inclusiveBetween(0.0D, 3.4028234663852886E38D, (double)f, "Invalid default width");
|
| 42 | f1 = JsonUtils.getFloat(jsonobject2, "spacing", f1);
|
| 43 | Validate.inclusiveBetween(0.0D, 3.4028234663852886E38D, (double)f1, "Invalid default spacing");
|
| 44 | f2 = JsonUtils.getFloat(jsonobject2, "left", f1);
|
| 45 | Validate.inclusiveBetween(0.0D, 3.4028234663852886E38D, (double)f2, "Invalid default left");
|
| 46 | }
|
| 47 |
|
| 48 | for (int i = 0; i < 256; ++i)
|
| 49 | {
|
| 50 | JsonElement jsonelement = jsonobject1.get(Integer.toString(i));
|
| 51 | float f3 = f;
|
| 52 | float f4 = f1;
|
| 53 | float f5 = f2;
|
| 54 |
|
| 55 | if (jsonelement != null)
|
| 56 | {
|
| 57 | JsonObject jsonobject3 = JsonUtils.getJsonObject(jsonelement, "characters[" + i + "]");
|
| 58 | f3 = JsonUtils.getFloat(jsonobject3, "width", f);
|
| 59 | Validate.inclusiveBetween(0.0D, 3.4028234663852886E38D, (double)f3, "Invalid width");
|
| 60 | f4 = JsonUtils.getFloat(jsonobject3, "spacing", f1);
|
| 61 | Validate.inclusiveBetween(0.0D, 3.4028234663852886E38D, (double)f4, "Invalid spacing");
|
| 62 | f5 = JsonUtils.getFloat(jsonobject3, "left", f2);
|
| 63 | Validate.inclusiveBetween(0.0D, 3.4028234663852886E38D, (double)f5, "Invalid left");
|
| 64 | }
|
| 65 |
|
| 66 | afloat[i] = f3;
|
| 67 | afloat1[i] = f4;
|
| 68 | afloat2[i] = f5;
|
| 69 | }
|
| 70 | }
|
| 71 |
|
| 72 | return new FontMetadataSection(afloat, afloat2, afloat1);
|
| 73 | }
|
| 74 |
|
| 75 | /**
|
| 76 | * The name of this section type as it appears in JSON.
|
| 77 | */
|
| 78 | public String getSectionName()
|
| 79 | {
|
| 80 | return "font";
|
| 81 | }
|
| 82 | }
|
| 83 |
|