Search in sources :

Example 66 with JsonValue

use of com.badlogic.gdx.utils.JsonValue in project bladecoder-adventure-engine by bladecoder.

the class Verb method read.

@Override
public void read(Json json, JsonValue jsonData) {
    BladeJson bjson = (BladeJson) json;
    if (bjson.getMode() == Mode.MODEL) {
        id = json.readValue("id", String.class, jsonData);
        target = json.readValue("target", String.class, (String) null, jsonData);
        state = json.readValue("state", String.class, (String) null, jsonData);
        icon = json.readValue("icon", String.class, (String) null, jsonData);
        actions.clear();
        JsonValue actionsValue = jsonData.get("actions");
        for (int i = 0; i < actionsValue.size; i++) {
            JsonValue aValue = actionsValue.get(i);
            String clazz = aValue.getString("class");
            try {
                Action a = ActionUtils.readJson(bjson.getWorld(), json, aValue);
                actions.add(a);
            } catch (SerializationException e) {
                EngineLogger.error("Error loading action: " + clazz + " " + aValue.toString());
                throw e;
            }
        }
    } else {
        // MUTABLE
        currentTarget = json.readValue("currentTarget", String.class, (String) null, jsonData);
        ip = json.readValue("ip", Integer.class, jsonData);
        cb = ActionCallbackSerializer.find(bjson.getWorld(), bjson.getScene(), json.readValue("cb", String.class, jsonData));
        JsonValue actionsValue = jsonData.get("actions");
        int i = 0;
        for (Action a : actions) {
            if (a instanceof Serializable && i < actionsValue.size) {
                if (actionsValue.get(i) == null)
                    break;
                ((Serializable) a).read(json, actionsValue.get(i));
                i++;
            }
        }
    }
}
Also used : Action(com.bladecoder.engine.actions.Action) Serializable(com.badlogic.gdx.utils.Json.Serializable) SerializationException(com.badlogic.gdx.utils.SerializationException) BladeJson(com.bladecoder.engine.serialization.BladeJson) JsonValue(com.badlogic.gdx.utils.JsonValue)

Example 67 with JsonValue

use of com.badlogic.gdx.utils.JsonValue in project bladecoder-adventure-engine by bladecoder.

the class VerbManager method read.

@SuppressWarnings("unchecked")
@Override
public void read(Json json, JsonValue jsonData) {
    BladeJson bjson = (BladeJson) json;
    if (bjson.getMode() == Mode.MODEL) {
        this.w = bjson.getWorld();
        verbs = json.readValue("verbs", HashMap.class, Verb.class, jsonData);
    } else {
        for (String v : verbs.keySet()) {
            Verb verb = verbs.get(v);
            JsonValue jsonValue = jsonData.get("verbs").get(v);
            if (jsonValue != null)
                verb.read(json, jsonValue);
            else
                EngineLogger.debug("LOAD WARNING: Verb not found in saved game: " + jsonData.name + "." + v);
        }
    }
}
Also used : HashMap(java.util.HashMap) BladeJson(com.bladecoder.engine.serialization.BladeJson) JsonValue(com.badlogic.gdx.utils.JsonValue)

Example 68 with JsonValue

use of com.badlogic.gdx.utils.JsonValue in project bladecoder-adventure-engine by bladecoder.

the class ActionUtils method readJson.

public static Action readJson(World w, Json json, JsonValue jsonData) {
    String className = jsonData.getString("class", null);
    Action action = null;
    if (className != null) {
        jsonData.remove("class");
        try {
            action = ActionFactory.create(className, null);
        } catch (ClassNotFoundException | ReflectionException e1) {
            throw new SerializationException(e1);
        }
        for (int j = 0; j < jsonData.size; j++) {
            JsonValue v = jsonData.get(j);
            try {
                if (v.isNull())
                    ActionUtils.setParam(action, v.name, null);
                else
                    ActionUtils.setParam(action, v.name, v.asString());
            } catch (NoSuchFieldException e) {
                EngineLogger.error("Action field not found - class: " + className + " field: " + v.name);
            } catch (IllegalArgumentException | IllegalAccessException e) {
                EngineLogger.error("Action field error - class: " + className + " field: " + v.name + " value: " + (v == null ? "null" : v.asString()));
            }
        }
        action.init(w);
    }
    return action;
}
Also used : ReflectionException(com.badlogic.gdx.utils.reflect.ReflectionException) Action(com.bladecoder.engine.actions.Action) SerializationException(com.badlogic.gdx.utils.SerializationException) JsonValue(com.badlogic.gdx.utils.JsonValue)

Example 69 with JsonValue

use of com.badlogic.gdx.utils.JsonValue in project talos by rockbite.

the class GradientColorModule method read.

@Override
public void read(Json json, JsonValue jsonData) {
    super.read(json, jsonData);
    points.clear();
    final JsonValue jsonPpoints = jsonData.get("points");
    for (JsonValue point : jsonPpoints) {
        createPoint(new Color(point.getFloat("r"), point.getFloat("g"), point.getFloat("b"), 1f), point.getFloat("pos"));
    }
}
Also used : Color(com.badlogic.gdx.graphics.Color) JsonValue(com.badlogic.gdx.utils.JsonValue)

Example 70 with JsonValue

use of com.badlogic.gdx.utils.JsonValue in project talos by rockbite.

the class CurveModule method read.

@Override
public void read(Json json, JsonValue jsonData) {
    super.read(json, jsonData);
    points.clear();
    final JsonValue points = jsonData.get("points");
    for (JsonValue point : points) {
        createPoint(point.get(0).asFloat(), point.get(1).asFloat());
    }
}
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