use of buildcraft.lib.client.model.ResourceLoaderContext in project BuildCraft by BuildCraft.
the class JsonGuiTypeRegistry method main.
// Simple test
public static void main(String[] args) throws IOException {
String loc = "/assets/buildcraftbuilders/gui/filler.json";
InputStream is = JsonGuiTypeRegistry.class.getResourceAsStream(loc);
JsonObject obj;
try (InputStreamReader isr = new InputStreamReader(is)) {
obj = new Gson().fromJson(isr, JsonObject.class);
}
JsonGuiInfo info = new JsonGuiInfo(obj, DefaultContexts.createWithAll(), new ResourceLoaderContext());
info.printOut(System.out::println);
}
use of buildcraft.lib.client.model.ResourceLoaderContext in project BuildCraft by BuildCraft.
the class BuildCraftJsonGui method load.
public final void load() {
ResourceLoaderContext loadHistory = new ResourceLoaderContext();
try (InputStreamReader reader = loadHistory.startLoading(jsonGuiDefinition)) {
JsonObject obj = new Gson().fromJson(reader, JsonObject.class);
JsonGuiInfo info = new JsonGuiInfo(obj, context, loadHistory);
sizeX = (int) GenericExpressionCompiler.compileExpressionLong(info.sizeX, context).evaluate();
sizeY = (int) GenericExpressionCompiler.compileExpressionLong(info.sizeY, context).evaluate();
varData.setNodes(info.createTickableNodes());
for (JsonGuiElement elem : info.elements) {
String typeName = elem.properties.get("type");
ElementType type = JsonGuiTypeRegistry.TYPES.get(typeName);
if (type == null) {
BCLog.logger.warn("Unknown type " + typeName);
} else {
IGuiElement e = type.deserialize(this, rootElement, info, elem);
String parent = elem.properties.get("parent");
IContainingElement p = properties.get("custom." + parent, IContainingElement.class);
properties.put("custom." + elem.name, e);
if (p == null) {
shownElements.add(e);
} else {
p.getChildElements().add(e);
p.calculateSizes();
}
}
}
} catch (InvalidExpressionException iee) {
throw new JsonSyntaxException("Failed to resolve the size of " + jsonGuiDefinition, iee);
} catch (IOException e) {
throw new Error(e);
}
loadHistory.finishLoading();
}
Aggregations