use of com.google.gson.JsonSyntaxException in project BuildCraft by BuildCraft.
the class JsonVariableModel method deserializePartArray.
static JsonVariableModelPart[] deserializePartArray(JsonObject json, String member, FunctionContext fnCtx, ResourceLoaderContext ctx, boolean require) {
if (!json.has(member)) {
if (require) {
throw new JsonSyntaxException("Did not have '" + member + "' in '" + json + "'");
} else {
return new JsonVariableModelPart[0];
}
}
JsonElement elem = json.get(member);
if (!elem.isJsonArray()) {
throw new JsonSyntaxException("Expected an array, got '" + elem + "'");
}
JsonArray array = elem.getAsJsonArray();
JsonVariableModelPart[] to = new JsonVariableModelPart[array.size()];
for (int i = 0; i < to.length; i++) {
to[i] = JsonVariableModelPart.deserializeModelPart(array.get(i), fnCtx, ctx);
}
return to;
}
use of com.google.gson.JsonSyntaxException in project BuildCraft by BuildCraft.
the class JsonVariableModel method deserializeTextures.
private void deserializeTextures(JsonElement elem) {
if (elem == null)
return;
if (!elem.isJsonObject()) {
throw new JsonSyntaxException("Expected to find an object for 'textures', but found " + elem);
}
JsonObject obj = elem.getAsJsonObject();
for (Entry<String, JsonElement> entry : obj.entrySet()) {
String name = entry.getKey();
JsonElement tex = entry.getValue();
JsonTexture texture;
if (tex.isJsonPrimitive() && tex.getAsJsonPrimitive().isString()) {
String location = tex.getAsString();
texture = new JsonTexture(location);
} else if (tex.isJsonObject()) {
texture = new JsonTexture(tex.getAsJsonObject());
} else {
throw new JsonSyntaxException("Expected a string or an object, but got " + tex);
}
textures.put(name, texture);
}
}
use of com.google.gson.JsonSyntaxException in project BuildCraft by BuildCraft.
the class ElementType method resolvePosition.
public static IGuiPosition resolvePosition(JsonGuiElement json, String name, IGuiPosition parent, FunctionContext ctx) {
String eqn = json.properties.get(name);
if (eqn == null) {
INodeDouble x = getEquationDouble(json, name + "[0]", ctx);
INodeDouble y = getEquationDouble(json, name + "[1]", ctx);
return IGuiPosition.create(x, y).offset(parent);
}
try {
return GenericExpressionCompiler.compileExpressionObject(IGuiPosition.class, eqn, ctx).evaluate();
} catch (InvalidExpressionException e) {
throw new JsonSyntaxException("Failed to resolve a position for " + json.fullName, e);
}
}
use of com.google.gson.JsonSyntaxException in project BuildCraft by BuildCraft.
the class ElementType method resolveArea.
public static IGuiArea resolveArea(JsonGuiElement json, String name, IGuiPosition parent, FunctionContext ctx) {
String eqn = json.properties.get(name);
if (eqn == null) {
INodeDouble x = getEquationDouble(json, name + "[0]", ctx);
INodeDouble y = getEquationDouble(json, name + "[1]", ctx);
INodeDouble w = getEquationDouble(json, name + "[2]", ctx);
INodeDouble h = getEquationDouble(json, name + "[3]", ctx);
return IGuiArea.create(x, y, w, h).offset(parent);
}
try {
return GenericExpressionCompiler.compileExpressionObject(IGuiArea.class, eqn, ctx).evaluate();
} catch (InvalidExpressionException e) {
throw new JsonSyntaxException("Failed to resolve an area for " + json.fullName, e);
}
}
use of com.google.gson.JsonSyntaxException in project BuildCraft by BuildCraft.
the class GuiConfigManager method loadFromConfigFile.
public static void loadFromConfigFile() {
if (BCLibConfig.guiConfigFile != null) {
Gson gson = new Gson();
List<String> lines;
try {
lines = Files.readAllLines(BCLibConfig.guiConfigFile.toPath());
} catch (IOException io) {
BCLog.logger.warn("[lib.gui.cfg] Failed to read the config file! " + io.getMessage());
return;
}
StringBuilder allLines = new StringBuilder();
for (String line : lines) {
allLines.append(line);
allLines.append('\n');
}
try {
readFromJson(gson.fromJson(allLines.toString(), JsonObject.class));
return;
} catch (JsonSyntaxException jse) {
BCLog.logger.warn("[lib.gui.cfg] There's a problem with the config file: try fixing it manually, " + "or deleting it to let buildcraft overwrite it on save." + jse.getMessage());
} catch (ClassCastException cce) {
// This happens occasionally, and its a bit wierd
BCLog.logger.warn("[lib.gui.cfg] There's a major problem with the config file: try fixing it manually, " + "or deleting it to let buildcraft overwrite it on save." + cce.getMessage());
}
BCLog.logger.info("File contents:");
for (String line : lines) {
BCLog.logger.info(line.replace("\0", "\\0"));
}
}
}
Aggregations