use of com.badlogic.gdx.utils.JsonValue in project gdx-graph by MarcinSc.
the class GraphLoader method loadGraph.
public static <T> T loadGraph(JsonValue graph, GraphLoaderCallback<T> graphLoaderCallback, PropertyLocation defaultPropertyLocation) {
// Assuming default
String version = graph.has("version") ? graph.getString("version") : "0.1.0";
if (!canReadVersion(version)) {
throw new IllegalArgumentException("Unable to read a graph of version " + version);
}
if (!VERSION.equals(version))
Gdx.app.debug("GraphLoader", "Reading a graph from different version " + VERSION + " != " + version);
graphLoaderCallback.start();
for (JsonValue object : graph.get("nodes")) {
String type = object.getString("type");
String id = object.getString("id");
float x = object.getFloat("x");
float y = object.getFloat("y");
JsonValue data = object.get("data");
if (data == null)
data = emptyData;
graphLoaderCallback.addPipelineNode(id, type, x, y, data);
}
for (JsonValue connection : graph.get("connections")) {
String fromNode = connection.getString("fromNode");
String fromField = connection.getString("fromField");
String toNode = connection.getString("toNode");
String toField = connection.getString("toField");
graphLoaderCallback.addPipelineVertex(fromNode, fromField, toNode, toField);
}
for (JsonValue property : graph.get("properties")) {
String type = property.getString("type");
String name = property.getString("name");
JsonValue data = property.get("data");
if (data == null)
data = emptyData;
String location = property.getString("location", null);
PropertyLocation propertyLocation = (location != null) ? PropertyLocation.valueOf(location) : defaultPropertyLocation;
graphLoaderCallback.addPipelineProperty(type, name, propertyLocation, data);
}
JsonValue groups = graph.get("groups");
if (groups != null) {
for (JsonValue group : groups) {
String name = group.getString("name");
JsonValue nodes = group.get("nodes");
ObjectSet<String> nodeIds = new ObjectSet<>();
for (JsonValue node : nodes) {
nodeIds.add(node.asString());
}
graphLoaderCallback.addNodeGroup(name, nodeIds);
}
}
return graphLoaderCallback.end();
}
use of com.badlogic.gdx.utils.JsonValue in project gdx-gltf by mgsx-dev.
the class GLTFMorphTarget method read.
@Override
public void read(Json json, JsonValue jsonData) {
for (JsonIterator i = jsonData.iterator(); i.hasNext(); ) {
JsonValue e = i.next();
put(e.name, e.asInt());
}
}
use of com.badlogic.gdx.utils.JsonValue in project gaiasky by langurmonkey.
the class WikiInfoWindow method getJSONData.
private void getJSONData(String url, final WikiDataListener listener) {
Net.HttpRequest request = new Net.HttpRequest(HttpMethods.GET);
request.setUrl(url);
request.setTimeOut(5000);
Gdx.net.sendHttpRequest(request, new HttpResponseListener() {
@Override
public void handleHttpResponse(Net.HttpResponse httpResponse) {
if (httpResponse.getStatus().getStatusCode() == HttpStatus.SC_OK) {
// Ok
JsonValue root = reader.parse(httpResponse.getResultAsString());
listener.ok(root);
} else {
// Ko with code
listener.ko(httpResponse.getStatus().toString());
}
}
@Override
public void failed(Throwable t) {
// Failed
listener.ko();
}
@Override
public void cancelled() {
// Cancelled
listener.ko();
}
});
}
use of com.badlogic.gdx.utils.JsonValue in project gaiasky by langurmonkey.
the class GeoJsonLoader method loadData.
@Override
public Array<? extends SceneGraphNode> loadData() {
Array<T> bodies = new Array<T>();
try {
JsonReader json = new JsonReader();
for (String filePath : filePaths) {
FileHandle file = Settings.settings.data.dataFileHandle(filePath);
JsonValue model = json.parse(file.read());
JsonValue child = model.get("features").child;
int size = 0;
while (child != null) {
size++;
// Convert to object and add to list
@SuppressWarnings("unchecked") T object = (T) convertJsonToArea(child);
bodies.add(object);
child = child.next;
}
Logger.getLogger(this.getClass()).info(I18n.txt("notif.nodeloader", size, filePath));
}
} catch (Exception e) {
Logger.getLogger(this.getClass()).error(e);
}
return bodies;
}
use of com.badlogic.gdx.utils.JsonValue in project gaiasky by langurmonkey.
the class GeoJsonLoader method convertToDoubleArray.
public double[][][] convertToDoubleArray(JsonValue json, int size, int d) {
double[][][] result = new double[size][][];
int i = 0;
JsonValue current = json;
if (d > 1)
current = json.child;
do {
double[][] l1 = new double[current.size][];
// Fill in last level
JsonValue child = current.child;
int j = 0;
do {
double[] l2 = child.asDoubleArray();
l1[j] = l2;
child = child.next();
j++;
} while (child != null);
result[i] = l1;
if (d == 1) {
current = current.next();
} else {
current = json.next() != null ? json.next().child : null;
json = json.next();
}
i++;
} while (current != null);
return result;
}
Aggregations