Search in sources :

Example 31 with JsonValue

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();
}
Also used : PropertyLocation(com.gempukku.libgdx.graph.shader.property.PropertyLocation) JsonValue(com.badlogic.gdx.utils.JsonValue) ObjectSet(com.badlogic.gdx.utils.ObjectSet)

Example 32 with JsonValue

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());
    }
}
Also used : JsonValue(com.badlogic.gdx.utils.JsonValue) JsonIterator(com.badlogic.gdx.utils.JsonValue.JsonIterator)

Example 33 with JsonValue

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();
        }
    });
}
Also used : JsonValue(com.badlogic.gdx.utils.JsonValue) Net(com.badlogic.gdx.Net) HttpResponseListener(com.badlogic.gdx.Net.HttpResponseListener)

Example 34 with JsonValue

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;
}
Also used : Array(com.badlogic.gdx.utils.Array) FileHandle(com.badlogic.gdx.files.FileHandle) JsonValue(com.badlogic.gdx.utils.JsonValue) JsonReader(com.badlogic.gdx.utils.JsonReader) ReflectionException(com.badlogic.gdx.utils.reflect.ReflectionException)

Example 35 with JsonValue

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;
}
Also used : JsonValue(com.badlogic.gdx.utils.JsonValue)

Aggregations

JsonValue (com.badlogic.gdx.utils.JsonValue)148 JsonReader (com.badlogic.gdx.utils.JsonReader)27 IOException (java.io.IOException)21 Array (com.badlogic.gdx.utils.Array)20 Json (com.badlogic.gdx.utils.Json)15 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)14 FileHandle (com.badlogic.gdx.files.FileHandle)11 ReflectionException (com.badlogic.gdx.utils.reflect.ReflectionException)10 BladeJson (com.bladecoder.engine.serialization.BladeJson)9 HashMap (java.util.HashMap)8 Color (com.badlogic.gdx.graphics.Color)7 GraphBoxImpl (com.gempukku.libgdx.graph.ui.graph.GraphBoxImpl)7 ArrayList (java.util.ArrayList)7 Vector2 (com.badlogic.gdx.math.Vector2)6 Actor (com.badlogic.gdx.scenes.scene2d.Actor)6 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)6 Action (com.bladecoder.engine.actions.Action)6 File (java.io.File)6 ObjectMap (com.badlogic.gdx.utils.ObjectMap)5 SerializationException (com.badlogic.gdx.utils.SerializationException)5