Search in sources :

Example 1 with GuiElementStatement

use of buildcraft.lib.gui.statement.GuiElementStatement in project BuildCraft by BuildCraft.

the class ElementTypeStatementSlot method deserialize0.

@Override
public IGuiElement deserialize0(BuildCraftJsonGui gui, IGuiPosition parent, JsonGuiInfo info, JsonGuiElement json) {
    FunctionContext ctx = createContext(json);
    if (!json.properties.containsKey("size[0]")) {
        json.properties.put("size[0]", "18");
    }
    if (!json.properties.containsKey("size[1]")) {
        json.properties.put("size[1]", "18");
    }
    inheritProperty(json, "pos[0]", "area[0]");
    inheritProperty(json, "pos[1]", "area[1]");
    inheritProperty(json, "size[0]", "area[2]");
    inheritProperty(json, "size[1]", "area[3]");
    IGuiArea area = resolveArea(json, "area", parent, ctx);
    String source;
    if (json.properties.containsKey("source")) {
        source = json.properties.get("source");
    } else {
        source = resolveEquation(json, "source_expression", ctx);
        if (source == null) {
            throw new JsonSyntaxException("Expected either 'source' or 'source_expression' for " + NAME);
        }
    }
    boolean draw = !"false".equals(json.properties.get("draw"));
    FullStatement<?> fullStatement = gui.properties.get(source, FullStatement.class);
    if (fullStatement == null) {
        throw new JsonSyntaxException("Can't find a statement called '" + source + "'");
    }
    StatementContext<?> context = gui.properties.get(source, StatementContext.class);
    return new GuiElementStatement<>(gui, area, fullStatement, context, draw);
}
Also used : IGuiArea(buildcraft.lib.gui.pos.IGuiArea) JsonSyntaxException(com.google.gson.JsonSyntaxException) FunctionContext(buildcraft.lib.expression.FunctionContext) GuiElementStatement(buildcraft.lib.gui.statement.GuiElementStatement)

Aggregations

FunctionContext (buildcraft.lib.expression.FunctionContext)1 IGuiArea (buildcraft.lib.gui.pos.IGuiArea)1 GuiElementStatement (buildcraft.lib.gui.statement.GuiElementStatement)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1